The problem is the same as last time (XBee+Arduino communication problem XBee+Arduino communication problem)
You are sending the data via:
Serial.println(val1);
which outputs an ASCII
representation of the number.
But in your reading, you are reading in a byte
value. Actually, I just realised you are reading in a char
which is a signed (-128 to 127) value:
char inByte = portOne.read();
first, change that to:
byte inByte = portOne.read();
Now, you have three options:
If (as you say) the numbers you expect are around
200
and will always be below256
(and positive) then you could send a byte value instead. That way, when you read the byte in, you get the same value. You would do this usingSerial.write(val1);
instead ofprint
.If you need to send larger than a byte value, eg
int
, then send as two bytes, HIGH and LOW. Then on the receiving end, take in two bytes when reading that data.Send as plain text but read in as plain text. Since you have delimiters, keep reading in the serial until you have all the data you need and then break it down. (You could adapt the code I posted in the answer above to do that).
edit: a couple of other points with your code:
You're doing an
analogWrite
to digital pins0, 1,
and2
. Was that your intention?analogWrite
is reserved for sending out PWM signals on only those pins that are capable (see: http://arduino.cc/en/Reference/analogWrite )analogRead
will read a value of0-1023
and if your intention is to just use PWM at the other end, then step it down to a value of0-255
. In that case you can get away with writing byte values toSerial.write
.You're never setting the
pinMode
of the outputs in the receiver.You're sending
val1
,val2
, andval3
out viaSerial.println
which will send your value out (asASCII
), followed by a newline, so the bytes sent from that one line will be32 30 30 0D 0A
. You have to interpret that at the other end.You're also using software serial on the hardware serial port (you're assigning digital pins 0 and 1. These are the hardware serial pins). BUT you're also initialising it via hardware serial. I'm guessing that it really wouldn't matter (if the pins are aligned), but you can't expect to receive data via software serial and send data via hardware serial if they're all using the same pins.
The problem is the same as last time (XBee+Arduino communication problem)
You are sending the data via:
Serial.println(val1);
which outputs an ASCII
representation of the number.
But in your reading, you are reading in a byte
value. Actually, I just realised you are reading in a char
which is a signed (-128 to 127) value:
char inByte = portOne.read();
first, change that to:
byte inByte = portOne.read();
Now, you have three options:
If (as you say) the numbers you expect are around
200
and will always be below256
(and positive) then you could send a byte value instead. That way, when you read the byte in, you get the same value. You would do this usingSerial.write(val1);
instead ofprint
.If you need to send larger than a byte value, eg
int
, then send as two bytes, HIGH and LOW. Then on the receiving end, take in two bytes when reading that data.Send as plain text but read in as plain text. Since you have delimiters, keep reading in the serial until you have all the data you need and then break it down. (You could adapt the code I posted in the answer above to do that).
edit: a couple of other points with your code:
You're doing an
analogWrite
to digital pins0, 1,
and2
. Was that your intention?analogWrite
is reserved for sending out PWM signals on only those pins that are capable (see: http://arduino.cc/en/Reference/analogWrite )analogRead
will read a value of0-1023
and if your intention is to just use PWM at the other end, then step it down to a value of0-255
. In that case you can get away with writing byte values toSerial.write
.You're never setting the
pinMode
of the outputs in the receiver.You're sending
val1
,val2
, andval3
out viaSerial.println
which will send your value out (asASCII
), followed by a newline, so the bytes sent from that one line will be32 30 30 0D 0A
. You have to interpret that at the other end.You're also using software serial on the hardware serial port (you're assigning digital pins 0 and 1. These are the hardware serial pins). BUT you're also initialising it via hardware serial. I'm guessing that it really wouldn't matter (if the pins are aligned), but you can't expect to receive data via software serial and send data via hardware serial if they're all using the same pins.
The problem is the same as last time (XBee+Arduino communication problem)
You are sending the data via:
Serial.println(val1);
which outputs an ASCII
representation of the number.
But in your reading, you are reading in a byte
value. Actually, I just realised you are reading in a char
which is a signed (-128 to 127) value:
char inByte = portOne.read();
first, change that to:
byte inByte = portOne.read();
Now, you have three options:
If (as you say) the numbers you expect are around
200
and will always be below256
(and positive) then you could send a byte value instead. That way, when you read the byte in, you get the same value. You would do this usingSerial.write(val1);
instead ofprint
.If you need to send larger than a byte value, eg
int
, then send as two bytes, HIGH and LOW. Then on the receiving end, take in two bytes when reading that data.Send as plain text but read in as plain text. Since you have delimiters, keep reading in the serial until you have all the data you need and then break it down. (You could adapt the code I posted in the answer above to do that).
edit: a couple of other points with your code:
You're doing an
analogWrite
to digital pins0, 1,
and2
. Was that your intention?analogWrite
is reserved for sending out PWM signals on only those pins that are capable (see: http://arduino.cc/en/Reference/analogWrite )analogRead
will read a value of0-1023
and if your intention is to just use PWM at the other end, then step it down to a value of0-255
. In that case you can get away with writing byte values toSerial.write
.You're never setting the
pinMode
of the outputs in the receiver.You're sending
val1
,val2
, andval3
out viaSerial.println
which will send your value out (asASCII
), followed by a newline, so the bytes sent from that one line will be32 30 30 0D 0A
. You have to interpret that at the other end.You're also using software serial on the hardware serial port (you're assigning digital pins 0 and 1. These are the hardware serial pins). BUT you're also initialising it via hardware serial. I'm guessing that it really wouldn't matter (if the pins are aligned), but you can't expect to receive data via software serial and send data via hardware serial if they're all using the same pins.
You're doing an analogWrite
to digital pins 0, 1,
and 2
. Was that your intention? analogWrite
is reserved for sending out PWM signals on only those pins that are capable (see: http://arduino.cc/en/Reference/analogWrite )
analogRead
will read a value of 0-1023
and if your intention is to just use PWM at the other end, then step it down to a value of 0-255
. In that case you can get away with writing byte values to Serial.write
.
You're never setting the pinMode
of the outputs in the receiver.
You're doing an
analogWrite
to digital pins0, 1,
and2
. Was that your intention?analogWrite
is reserved for sending out PWM signals on only those pins that are capable (see: http://arduino.cc/en/Reference/analogWrite )analogRead
will read a value of0-1023
and if your intention is to just use PWM at the other end, then step it down to a value of0-255
. In that case you can get away with writing byte values toSerial.write
.You're never setting the
pinMode
of the outputs in the receiver.You're sending
val1
,val2
, andval3
out viaSerial.println
which will send your value out (asASCII
), followed by a newline, so the bytes sent from that one line will be32 30 30 0D 0A
. You have to interpret that at the other end.You're also using software serial on the hardware serial port (you're assigning digital pins 0 and 1. These are the hardware serial pins). BUT you're also initialising it via hardware serial. I'm guessing that it really wouldn't matter (if the pins are aligned), but you can't expect to receive data via software serial and send data via hardware serial if they're all using the same pins.
You're doing an analogWrite
to digital pins 0, 1,
and 2
. Was that your intention? analogWrite
is reserved for sending out PWM signals on only those pins that are capable (see: http://arduino.cc/en/Reference/analogWrite )
analogRead
will read a value of 0-1023
and if your intention is to just use PWM at the other end, then step it down to a value of 0-255
. In that case you can get away with writing byte values to Serial.write
.
You're never setting the pinMode
of the outputs in the receiver.
You're doing an
analogWrite
to digital pins0, 1,
and2
. Was that your intention?analogWrite
is reserved for sending out PWM signals on only those pins that are capable (see: http://arduino.cc/en/Reference/analogWrite )analogRead
will read a value of0-1023
and if your intention is to just use PWM at the other end, then step it down to a value of0-255
. In that case you can get away with writing byte values toSerial.write
.You're never setting the
pinMode
of the outputs in the receiver.You're sending
val1
,val2
, andval3
out viaSerial.println
which will send your value out (asASCII
), followed by a newline, so the bytes sent from that one line will be32 30 30 0D 0A
. You have to interpret that at the other end.You're also using software serial on the hardware serial port (you're assigning digital pins 0 and 1. These are the hardware serial pins). BUT you're also initialising it via hardware serial. I'm guessing that it really wouldn't matter (if the pins are aligned), but you can't expect to receive data via software serial and send data via hardware serial if they're all using the same pins.
The problem is the same as last time (XBee+Arduino communication problem)
You are sending the data via:
Serial.println(val1);
which outputs an ASCII
representation of the number.
But in your reading, you are reading in a byte
value. Actually, I just realised you are reading in a char
which is a signed (-128 to 127) value:
char inByte = portOne.read();
first, change that to:
byte inByte = portOne.read();
Now, you have three options:
If (as you say) the numbers you expect are around
200
and will always be below256
(and positive) then you could send a byte value instead. That way, when you read the byte in, you get the same value. You would do this usingSerial.write(val1);
instead ofprint
.If you need to send larger than a byte value, eg
int
, then send as two bytes, HIGH and LOW. Then on the receiving end, take in two bytes when reading that data.Send as plain text but read in as plain text. Since you have delimiters, keep reading in the serial until you have all the data you need and then break it down. (You could adapt the code I posted in the answer above to do that).
edit: a couple of other points with your code:
You're doing an analogWrite
to digital pins 0, 1,
and 2
. Was that your intention? analogWrite
is reserved for sending out PWM signals on only those pins that are capable (see: http://arduino.cc/en/Reference/analogWrite )
analogRead
will read a value of 0-1023
and if your intention is to just use PWM at the other end, then step it down to a value of 0-255
. In that case you can get away with writing byte values to Serial.write
.
You're never setting the pinMode
of the outputs in the receiver.
The problem is the same as last time (XBee+Arduino communication problem)
You are sending the data via:
Serial.println(val1);
which outputs an ASCII
representation of the number.
But in your reading, you are reading in a byte
value. Actually, I just realised you are reading in a char
which is a signed (-128 to 127) value:
char inByte = portOne.read();
first, change that to:
byte inByte = portOne.read();
Now, you have three options:
If (as you say) the numbers you expect are around
200
and will always be below256
(and positive) then you could send a byte value instead. That way, when you read the byte in, you get the same value. You would do this usingSerial.write(val1);
instead ofprint
.If you need to send larger than a byte value, eg
int
, then send as two bytes, HIGH and LOW. Then on the receiving end, take in two bytes when reading that data.Send as plain text but read in as plain text. Since you have delimiters, keep reading in the serial until you have all the data you need and then break it down. (You could adapt the code I posted in the answer above to do that).
The problem is the same as last time (XBee+Arduino communication problem)
You are sending the data via:
Serial.println(val1);
which outputs an ASCII
representation of the number.
But in your reading, you are reading in a byte
value. Actually, I just realised you are reading in a char
which is a signed (-128 to 127) value:
char inByte = portOne.read();
first, change that to:
byte inByte = portOne.read();
Now, you have three options:
If (as you say) the numbers you expect are around
200
and will always be below256
(and positive) then you could send a byte value instead. That way, when you read the byte in, you get the same value. You would do this usingSerial.write(val1);
instead ofprint
.If you need to send larger than a byte value, eg
int
, then send as two bytes, HIGH and LOW. Then on the receiving end, take in two bytes when reading that data.Send as plain text but read in as plain text. Since you have delimiters, keep reading in the serial until you have all the data you need and then break it down. (You could adapt the code I posted in the answer above to do that).
edit: a couple of other points with your code:
You're doing an analogWrite
to digital pins 0, 1,
and 2
. Was that your intention? analogWrite
is reserved for sending out PWM signals on only those pins that are capable (see: http://arduino.cc/en/Reference/analogWrite )
analogRead
will read a value of 0-1023
and if your intention is to just use PWM at the other end, then step it down to a value of 0-255
. In that case you can get away with writing byte values to Serial.write
.
You're never setting the pinMode
of the outputs in the receiver.