how to pass data from a code on Arduino IDE to matlab
31 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ibrahim alami merroui
el 31 de En. de 2023
Comentada: Walter Roberson
el 5 de Feb. de 2023
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 comentarios
Respuesta aceptada
Walter Roberson
el 31 de En. de 2023
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 comentarios
Walter Roberson
el 5 de Feb. de 2023
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Instrument Control Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!