필터 지우기
필터 지우기

get data and plot graph from multiples termocouples in Arduino

조회 수: 6 (최근 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 CenterFile Exchange에서 I2C Devices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by