I need to send serially an array of bytes (array size 16) from Arduino to another receiving slave device and should receive array of bytes from the slave as well. I am using NewSoftSerial to send and receive data.
Could anyone show me how array of bytes can be sent and received serially using NewSoftSerial ???really need help thnks*
Have you tried using a for loop, and sending one value at a time? Are you sending the data as bytes or as strings?
Have you considered how you will recognize the end of one value and the start of another? Have you considered how to handle dropped bytes?
I tried sending as string first
mySerial.print("^021002A") .Those inside the parenthesis are to be sent to the slave device.It didn't work so now i am trying to send byte by byte.Each character will be send as a byte.I wanted to use mySerial.print but there was no such command in NewSoftSerial.
"Have you considered how you will recognize the end of one value and the start of another? Have you considered how to handle dropped bytes?"
I dont know how to take care of these.This is how I read bytes from slave device:
if(mySerial.available()>0) {
int i=0;
val = mySerial.read();
values*=val *
- i++; *
- }*
I tried sending as string first
mySerial.print("^021002A") .Those inside the parenthesis are to be sent to the slave device.It didn't work
What didn't work? Weren't the characters sent?
I wanted to use mySerial.print but there was no such command in NewSoftSerial.
The NewSoftSerial class most certainly does have a print method.
This is how I read bytes from slave device:
if(mySerial.available()>0) {
int i=0;
val = mySerial.read();
values*=val *
- i++; *
- } [/quote]*
That is how to receive ONE byte. If you want to receive more than one byte, you need some kind of loop.