get data and plot graph from multiples termocouples in Arduino
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Angel Lira
le 27 Juil 2018
Réponse apportée : Gayatri Menon
le 31 Juil 2018
Hi guys, I am having a problem trying to figure out how to plot a graph into Matlab of multiple termocouples using OneWire library from Arduino. I am a beginner in this programming stuff so, right now I am stuck on. The arduino reads the data fine, but I don't know how to get this data into Matlab.
// Data wire is plugged into port 2 on the Arduino #define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); DeviceAddress addr;
void setup(void) { // start serial port Serial.begin(9600); Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
void loop(void) { // call sensors.requestTemperatures() to issue a global temperature // request to all devices on the bus Serial.print("Requesting temperatures..."); sensors.requestTemperatures(); // Send the command to get temperatures Serial.println("DONE");
for (uint8_t s=0; s < sensors.getDeviceCount(); s++) {
// get the unique address
sensors.getAddress(addr, s);
// just look at bottom two bytes, which is pretty likely to be unique
int smalladdr = (addr[6] << 8) | addr[7];
Serial.print("Temperature for the device #"); Serial.print(s);
Serial.print(" with ID #"); Serial.print(smalladdr);
Serial.print(" is: ");
Serial.println(sensors.getTempCByIndex(s));
}
}
Here is the shame of my Matlab code, where I got it so far: clear global clear a %call library OneWire in Matlab a = arduino('COM3', 'Uno', 'libraries','PaulStoffregen/OneWire'); a.InputBufferSize = 1;%read one byte every time try fopen(arduino); x = linspace(1,100); %100 samples numcols = 1;
catch err fclose(instrfind); error('Make sure you selected the right port'); end
%define pin for sensor addon
sensor = addon(a,'PaulStoffregen/OneWire','D2');
%getting addresses
addr = sensor.AvailableAddresses();
fscanf(a)
%define variables for sensors
%sensorOne = sensor.AvailableAddresses{1};
%sensorTwo = sensor.AvailableAddresses{2};
reset(sensor);
If anyone could shy a light for me, any guidance is welcome. Thanks a lot!
0 commentaires
Réponse acceptée
Gayatri Menon
le 31 Juil 2018
Hi Angel,
Since you are printing the data to Serial monitor using Arduino IDE, you could create a serial object in MATLAB to read the data transmitted by the Arduino. To read the data transmitted serially from arduino, using a serial object in MATLAB could be a good approach. Please refer to the below link to know more about creating Serial object:
Hope this helps.
Thanks
Gayatri
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur I2C Devices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!