필터 지우기
필터 지우기

Measurements with a DHT11. How to use the arduino board "normally", while connected to it via the "serialport" function.

조회 수: 6 (최근 30일)
Hi everybody,
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:
arduinoObj=arduino("COM15", "UNO")
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!
Sebastien

답변 (1개)

Dhruv
Dhruv 2023년 3월 23일
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:
  • 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.
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.
  댓글 수: 1
Sébastien Josset
Sébastien Josset 2023년 3월 23일
Hi Dhruv,
Thanks a lot for having taken the time to answer!
However, I'm a bit confused:
If you use the configurePin and writeDigitalPin functions, then the Arduino functions are running, meaning you cannot use the serial function meanwhile. Or do you mean opening/closing alternatively the arduino funtion and the serialport function?
Kind Regards
Seb

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Serial and USB Communication에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by