Issue moving data into arduino

christop:
So you’re opening the serial monitor to receive data from the Arduino after sending data to it from Matlab? That’s not going to work for two reasons:

  1. opening the serial monitor auto-resets the Arduino, so your program won’t even remember what it received previously (unless you either disable the auto-reset in hardware or store the data in non-volatile memory to send it after the Arduino resets).
  2. your program already sent its data to Matlab (even if Matlab doesn’t read the data) before the serial monitor started.

Hi christop,
With number 1, are you implying that the data is indeed being sent through, but I’m simply unable to see it? I suppose I could come up with some various tests to see if this is true, but how would I go about disabling the auto-reset, or using non-volatile memory to send later (are you referring to EEPROM?)
What exactly do you mean with number 2? What data is being sent to MATLAB?
Thanks for your help.

jalperto34: I think you've gotten to the root of the problem here. When I ran this code, here is what I saw appear on the serial monitor: I'm guessing this suggests that the data isn't even being sent in the first place? This is very bizarre, seeing as how simple my MATLAB code is, and also that the LED code I used earlier worked fine (showing me what I'm trying to do is possible?). I could be way off here, but do you think that the data could somehow be disappearing after I close serial communication in MATLAB (last line of my code)? I'm just not sure of how to make sense of all this.

I can confirm that this indeed shows nothing. There must be something very fundamental I'm missing. Either way, I think that it's something wrong in MATLAB, rather than arduino. Or, there's something about serial communication/the serial monitor that I'm missing. Do you have any suggestions?

jalperto34, 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.

christop: So you're opening the serial monitor to receive data from the Arduino after sending data to it from Matlab? That's not going to work for two reasons: 1. opening the serial monitor auto-resets the Arduino, so your program won't even remember what it received previously (unless you either disable the auto-reset in hardware or store the data in non-volatile memory to send it after the Arduino resets). 2. your program already sent its data to Matlab (even if Matlab doesn't read the data) before the serial monitor started.

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: 1. Connect Arduino. 2. Open serial monitor. 3. Reset Arduino. 4. Launch MATHLAB execution.

[]s

jalperto34:
one dimensional vector filled with random positive and/or negative integers (ranging from a length of 6 as a minimum, and a maximum of 120)-that’s what I want to transfer to Arduino. For example, a vector v =[1,0,-10,185,-99].

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
<4,1.0,-10,185,-99>
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.

…R

Robin2:
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
<4,1.0,-10,185,-99>
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.

…R

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.

fabianoantunes:
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:

  1. Connect Arduino.
  2. Open serial monitor.
  3. Reset Arduino.
  4. Launch MATHLAB execution.

s

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.

fabianoantunes:
jalperto34,
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.

jalperto34: The most important thing for me is to find a way to generate a vector in MATLAB, and then transfer it to Arduino,

I don't know anything about Matlab but that is such a basic thing that it is inconceivable that it cannot be done.

Rather than write rambling posts here why don't you do some Googling for a Matlab solution. What you need to find is how to convert a vector into a string. It may be as simple as print(vector).

...R