get data and plot graph from multiples termocouples in Arduino
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Angel Lira
am 27 Jul. 2018
Beantwortet: Gayatri Menon
am 31 Jul. 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 Kommentare
Akzeptierte Antwort
Gayatri Menon
am 31 Jul. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu I2C Devices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!