how to pass data from a code on Arduino IDE to matlab
43 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ibrahim alami merroui
il 31 Gen 2023
Commentato: Walter Roberson
il 5 Feb 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 Commenti
Risposta accettata
Walter Roberson
il 31 Gen 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 Commenti
Walter Roberson
il 5 Feb 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su MATLAB Support Package for Arduino Hardware in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!