how to pass data from a code on Arduino IDE to matlab
조회 수: 50 (최근 30일)
이전 댓글 표시
Hello,
i'm using arduino Nano 33 IoT to get data from a sensor. So i had to write a code on Arduino IDE because there are no libraries in Matlab, wich help for the calculating. That means i can only get the data using the interface I2C on Arduino Nano 33 IoT. When i use I2C directly on Matlab it doesn't work (problem of sensor libraries ). Now after i have the data on Arduino IDE i want to pass it directly to Matlab. In this Case there is two codes, one in C++ (for Arduino to run the sensor and getting the data) and the other code on matlab for image processing. The problem i'm facing is that i can't combine the two codes.
Can someone help me to figure out how i can run the C++ on Arduino and after that send the Data to Matlab ? The data is a Matrix with 768 pixels. Every 2 seconds i get new Matrix from Arduino in a loop.
Thanks in advance
댓글 수: 0
채택된 답변
Walter Roberson
2023년 1월 31일
Use https://arduinogetstarted.com/reference/serial-println to convert to text to send. Or https://arduinogetstarted.com/reference/serial-write to send as binary (more efficient)
On the MATLAB side, serialport rather than using arduino . To read as text readline and sscanf or str2double . To read as binary read
댓글 수: 8
Walter Roberson
2023년 2월 5일
The way you build the echo server works for me when I change the IP address to "localhost". That is, that code for echoudp is for testing "loopback" -- testing that when you write data on the MATLAB end that it is properly going out and being received back as input on port 2390.
You would not use echoudp for the case where you expected the arduino to answer.
Note that the 2390 port that you writeline() to must match the local port number on the arduino end. You commented that out; you are assigning 55753 instead.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!