get data and plot graph from multiples termocouples in Arduino

1 回表示 (過去 30 日間)
Angel Lira
Angel Lira 2018 年 7 月 27 日
回答済み: Gayatri Menon 2018 年 7 月 31 日
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.
Here is the Arduino code: #include OneWire.h #include DallasTemperature.h
// 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!

採用された回答

Gayatri Menon
Gayatri Menon 2018 年 7 月 31 日
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 件)

カテゴリ

Help Center および File ExchangeI2C Devices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by