If you mean that the number of items can vary from one transmission to the next I would include, as the first value, the number of items and then I would use the system in the 3rd example in serial input basics. That way the actual data sent to the Arduino would be like this
Then a modification of the parse example in that Thread would be used to read all the items and save them wherever in the Arduino.
I have used <> as start and end markers but you could use any pair of characters that will never appear in the actual data.
Thanks for the suggestion Robin. Unfortunately the pressing matter I have is getting data of any length into Arduino in the first place-I can deal with the fact that the data length varies at another time. The most important thing for me is to find a way to generate a vector in MATLAB, and then transfer it to Arduino, either directly or indirectly.
If I bought an SD card for Arduino, is it possible to generate a vector in MATLAB, write it to a .txt file and save that file in the SD card, and then have Arduino read from that .txt file? The transmission will only happen once while my Arduino program is running so I can just have it happen in the beginning. I hope this isn’t a dumb question-I’ve never used an SD card shield (or whatever it’s called) before.
Cristop, I don’t know how the serial monitor for Arduino works in other platforms, but for Debian, I’m able to monitor the serial port in a non-blocking way, provided that I start the monitor first.
A possible solution for troubleshooting, in this case, would be:
- Connect Arduino.
- Open serial monitor.
- Reset Arduino.
- Launch MATHLAB execution.
Unfortunately this didn’t work. An error appeared on my MATLAB terminal indicating that the serial monitor is in use. I don’t think I can ever open the serial monitor on the Arduino side and then run my MATLAB script.
The fact that you are seeing data as
Data Received: 0
proves you are indeed receiving data from the serial port.
Try running that same program, but enter data manually on the serial console and see if that spits out exactly what you’ve typed in. That would discard communication problems with your hardware, at least. From there, I would check communication speed for the serial port and line ending characters.
Let us know should you make any progress and I can help troubleshooting the rest of the problem.
Yes, when I enter numbers manually in the serial monitor, it indeed returns exactly what I expect. I think I’ve ruled out any Arduino issues, so the remaining problem must lie with my MATLAB script. I’ll try and increase the speed, and check for line ending characters, and I’ll keep you updated. Let me know if you think of other ideas as well-I could really use the help on this one.