Arduino to Arduino Serial problems

Hello, I stumbled upon a issue where 2 arduinos with simple serial code that is supposed to send values in the range of 0-180 while they only recieved bytes are in the range 40-60 (the sender code works normally with Serial.print)

CONNECTIONS:
Arduino sender:
A0-A4 Potentiometers
GND->pots
5V->pots
RX->TX ard2
TX->RX ard2
GND->GND ard2

Arduino Receiver:
6-10 Servos
GND->Servos
RX->TX ard1
TX->RX ard1
GND->GND ard1

The servos are powered by a external power supply and the serial wires ale about a meter long. Any help would be greatly appreciated.

Lab_Gaming:
while they only recieved bytes are in the range 40-60 (the sender code works normally with Serial.print)

Without seeing your program how can we help?

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable.

You can send data in a compatible format with code like this

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

...R

Serial.print works fine, Serial.write is the problem. As for the code it’s a simple analogRead mapped to 0-180 and the mapped value is being sent via serial.

Lab_Gaming:
As for the code it’s a simple analogRead mapped to 0-180 and the mapped value is being sent via serial.

But still a secret, evidently.

Lab_Gaming:
Serial.print works fine, Serial.write is the problem.

Did you know? write() sends out binary raw data, while print() send out a textual representation of that value (although a single char still counts as raw data).

Here is the code:

int shoulder[3], arm[3], elbow[3], finger[3], wrist[3];

void readPots() {
for(int i=0; i<3; i++) {
shoulder*=map(analogRead(0), 0, 1023, 360, 0);*
_ arm*=map(analogRead(1), 0, 1023, 0, 360);_
_ elbow=map(analogRead(2), 0, 1023, 360, 0);
finger=map(analogRead(3), 0, 1023, 0, 360)-83;
wrist=map(analogRead(4), 0, 1023, 360, 0);
}
}
int avr(int val[3]) {
return ((float)val[0]+(float)val[1]+(float)val[2])/(float)3+0.67;
}
void setup() {
Serial.begin(9600);
}*

void loop() {_

readPots();
/
* if(Serial.availableForWrite()==63) {*
Serial.write(avr(shoulder));
* Serial.write(avr(arm));*
* Serial.write(avr(elbow));*
* Serial.write(avr(finger));*
* Serial.write(avr(wrist)); *
* }*
_ /
Serial.println(avr(shoulder));
Serial.println(avr(arm));
Serial.println(avr(elbow));
Serial.println(avr(finger));
Serial.println(avr(wrist));
Serial.print("\n");
delay(150);
/
}_

Lucario448:
Did you know? write() sends out binary raw data, while print() send out a textual representation of that value (although a single char still counts as raw data).

Yes I did know that.

Lab_Gaming:
Here is the code:

That is just the sending code. You need to post the receiving code as well - they must work as a pair. How will the receiving program determine which is the first value?

And please post your program using the code button </>

so it looks like this

. See How to use the Forum. It makes it much easier for people to help you.

...R