get data and plot graph from multiples termocouples in Arduino
Afficher commentaires plus anciens
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!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur I2C Devices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!