Hello, I am trying to run a neural network using Matlab and sending the outputs back to Arduino. Any ideas on suggestions on how to approach this? My current approach is not working.
Matlab code.
s = serialport('COM3', 115200);
while true
if s.NumBytesAvailable > 0
data = strtrim(string(readline(s)));
data = split(data,',');
data = str2double(data);
values = [data(1), data(2),...];
prediction = predict(network,values);
write(s, prediction,"double"); %send value to serial
end
end
%code to read in arduino.
double nnOutput = Serial.read();
Serial.println(nnOutput);
For informed help, please read and follow the instructions in the "How to get the best out of this forum" post, linked at the head of every forum category.
Hint: this line reads one ASCII character from the serial port, if one happens to available:
I'm very interested in this topic! If you don’t mind, I’ll leave a reply here and follow the updates on this discussion. Hopefully, more experts can contribute and help with the development of your project.
Lately, I’ve also been working on a project involving Arduino and MATLAB, specifically for real-time data acquisition. In the future, I might also explore signal processing to apply machine learning to the acquired signals.
Could you share more details on your current approach and what specific issues you’re facing? Are you using MATLAB’s Serial Communication (Serial.write/Serial.read) to send and receive data between MATLAB and Arduino? Also, what kind of neural network are you running—are you using MATLAB’s Deep Learning Toolbox or a custom model?
Looking forward to seeing how this project develops!
In that case you don't have double, only float (IEEE single precision). (On AVR architecture such as the Mega, you can declare a variable double, but actually is a float).