How to extract only specific data from whole bunch of string that is coming from Arduino ?

5 次查看(过去 30 天)
I am using 2 pairs of Arduino, Xbee, DHT11 sensor, and an MQ2 sensor that will transmit data to the third Arduino, Xbee connected to the computer with Matlab. Matlab GUI was created to display data from two Xbee's. The transmitted data consists of source address and data of Xbee1 and Xbee2 along with some other data like the checksum. Using Matlab I want to read incoming data(Data continuously coming from both 2 pairs of Arduino, Xbee) and extract the data I want(source address and values of DHT11,MQ2) from whole data. How to achieve this?

回答(2 个)

Robert Adam
Robert Adam 2018-4-3
Could you tell me please what is the code you used on the both transmitters? I mean the code on the Arduino board which are connected to the sensors?...I really need your answer..
  1 个评论
Karthik Muthineni
Hello Robert Adam, I have integrated dht11 and mq2 sensors with Arduino and plotted the live data from these sensors in Matlab. Here is my Arduino code that I have used
#include dht.h
SoftwareSerial sensor(2,3);
#define dataPin A1
#define mq2Pin A2
dht DHT;
void setup(){
Serial.begin(9600);
sensor.begin(9600);
}
void loop(){
int readData=DHT.read22(dataPin);
float t=DHT.temperature;
float h=DHT.humidity;
float s=analogRead(mq2Pin);
Serial.print(t);
Serial.print(h);
Serial.println(s);
delay(1000);
}

请先登录,再进行评论。


Srinidhi B R 16MMT0007
Hello karthik,
if you are sending the data in a specified format then its really easy to log it in MATLAB.
the follwing image shows how i am sending a array data in serial port . the variable SensorData is a 1x3 array which holds acceleration values from a ADXL345 sensor. after sending each value with a single space between them we need to send a new line feed ( Serial.println();) which will be defined as terminator in MATLAB.
now in MATLAB we need to program such that it detects the data in the specified sent format. here is the image of a part of the code in MATLAB
s is a Serial port object. sscanf command scans a length of data for the specified format and stores it in the store variable. if you use it in the loop correctly you will be able to log easily.
as you mentioned two arduino i believe you will have to create two serial object ports correspondingly and scan the particular port

类别

Help CenterFile Exchange 中查找有关 Sensors and Transducers 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by