How can I read the Grove Temperature & Humidity sensor via Arduino Mega 2560?

8 Ansichten (letzte 30 Tage)
I am trying to set up a Seeedstudio ADK Main Board (Arduino Mega 2560) with Grove Mega Shield and Grove Temperature & Humidity sensor so I can read the temperature and use it in further calculation. So far, I have been able to connect to the Arduino with the Arduino IO Support Package in MATLAB R2014a.
Now, I want to read the temperature. On the Wiki page of the sensor ( http://www.seeedstudio.com/wiki/Grove-_Temperature_and_Humidity_Sensor ) there is a reference to libraries which can be used to read the temperature and humidity. These are, of course, in C/C++ for use in the Arduino IDE. However, I am wondering what the best way is to convert one of the libraries for use in MATLAB?
The library that I would like to use can be found here: https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib.

Antworten (1)

Christiaan
Christiaan am 2 Apr. 2015
Dear Wilko,
Once you have accomplished to connect the Arduino to Simulink, the next step would be to first show the data you collect from the sensor in your ''built-in serial monitor''. (shift M in Arduino IDE). The library can be used directly in the Arduino code, to obtain the correct output.
If you see that the output in your Arduino monitor is 'correct', you can now connect the Arduino over either an analog input or digital input (depends at which port the data is received) and use Simulink blocks to obtain the data. You could display this at a scope or save it in your MATLAB workspace.
It is advised to first try an easy example ( here), that the connection between Arduino and Simulink is working and that you understand how you can transmit data from/to the Arduino.
Good luck! Christiaan
  1 Kommentar
Wilko ten Hove
Wilko ten Hove am 7 Apr. 2015
Dear Christiaan,
Thank you for your answer. I followed the steps, the first part is clear and it works in de serial monitor of the Arduino IDE.
I am not entirely sure if I understand the second part. Using analog input in Simulink reads the voltage of the signal, which contains the values of temperature and humidity, so that didn't work (I already tried that in the MATLAB workspace). The library for the sensor divides the signal into two functions for reading the two values (That's why I needed it).
It might be that I didn't understand your answer as you meant it, however, working with it brought me to a new idea. I am now running a script on the Arduino which gives an output to the serial port, containing the values for temperature and humidity. In the MATLAB workspace I connected to the COM port and used:
fscanf()
This gives the same result as the serial monitor in the Arduino IDE and I can use the values in MATLAB, which is what I want.
Thanks again! Wilko

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by