- Modify the existing Arduino sketch to continuously read the temperature and humidity values from the DHT11 sensor and send them over the serial port to MATLAB.
- Upload the modified sketch to the Arduino board.
- In MATLAB, open a serial connection to the Arduino board using the serialport function as done above.
- Use the configurePin function to set the pin mode of the Arduino pins you want to control.
- Use the writeDigitalPin function to write a digital value to the pins you configured.
- Use the read function of the serial port object to read the temperature and humidity values sent by the Arduino.
- Repeat the steps to continuously obtain the temperature and humidity values from the Arduino.
Measurements with a DHT11. How to use the arduino board "normally", while connected to it via the "serialport" function.
2 views (last 30 days)
I've been searching for hours and could not find a solution.
I have an arduino Uno, from which I get the temperature and humidity values from a DHT11 sensor to matlab. The board is connected to matlab with the serialport function and it works fine:
s = serialport("COM15",9600)
I would like to be able to use further functions of the board but cannot connect it using:
Since it's obviously already in use!
My question is:
how to run in the background the skrict on the arduino retrieving the DHT11 data, and still being able to modify the states of the pins in Matlab?
Thanks in advance for any help!
Dhruv on 23 Mar 2023
To run the script on the Arduino in the background while also being able to modify the pin states in MATLAB, try using the following approach:
Note that the arduino function cannot be used to connect to the Arduino while the serial port is already in use. Instead, you can use the serialport function to communicate with the Arduino and the configurePin and writeDigitalPin functions to control the pins.