Arduino to Arduino communication issue

Hello i am a newbie to arduino and i have an issue when communicating an arduino mega 2560 to an arduino uno using apc220

in this post how to send 2 analog inputs values over serial - Programming Questions - Arduino Forum i asked how to send 2 analog inputs over the air, i have tried what people answered and worked when communicating to the pc using the apc220, but when using arduino to arduino it does nothing like it doesnt receive any signal.

first i tested if first arduino sends the correct signal using the pc as receiver with one of the cards of apc220, and it does! (sends the analog values like Number,Number)

i also checked if the other arduino can receive the signal using the pc as Transmitter with one of the cards of apc220, and it does! (based on the example sketch named ReadASCIIString) checks serial for integers in this format Number,Number and end of line

when communicating arduino to arduino It doesnt work properlly, and i have no idea why, i checked if everything is connected well and it is
all the second arduino does is turn the motors on at full speed no matter if i turn the pots on the other arduino it just doesnt change speed, both arduinos and the mottors have independent power source, also checked that the config in both apc220 cards were the same

i use this code for reading 2 pots on an arduino mega and send the signal over the air using the apc220

const int analogInPin = A0; 
const int analogInPin2 = A1;
int sensorValue = 0; 
int sensorValue2 = 0;

void setup() {  
  Serial.begin(19200); 
}

void loop() {
  
  sensorValue = analogRead(analogInPin);
  sensorValue2 = analogRead(analogInPin2);   
                        
  Serial.print(sensorValue); 
  Serial.print("," );     
  Serial.println(sensorValue2);
  
  delay(100);                     
}

i use this other code for receiving the signal and make 2 small motors run, i have a 50 amp motor driver to control them that is well connected

const int Pin1 = 3;
const int Pin2 = 5;


void setup() {  
  Serial.begin(19200); 
  pinMode(Pin1, OUTPUT); 
  pinMode(Pin2, OUTPUT);
}

void loop() {  
  while (Serial.available() > 0) { 
    
    int M1 = Serial.parseInt();   
    int M2 = Serial.parseInt(); 
    
    if (Serial.read() == '\n') {  
      
      M1 = constrain(M1, 0, 255);
      M2 = constrain(M2, 0, 255);
      
      analogWrite(Pin1, M1);
      analogWrite(Pin2, M2);     
     }
  }
}

can you people tell me what im doing wrong?

voltrex32:
i checked if everything is connected well and it is

What's connected to what?

I can't tell you what you're doing wrong but I can offer a suggestion.

Have your receiving Arduino blink an LED or something when it receives something from the RF device. That way you'll all least know it's getting something.

You could also have your Mega as the receiver and hook the RF device to Serial1 or 2 or 3 and monitor serial 0 on your pc. That way when it receives something you can have it print what it received to the serial monitor. That should give you a clue at least.

Arrch:

voltrex32:
i checked if everything is connected well and it is

What's connected to what?

ummm, and arduino mega have 2 pots connected to it and one card of the apc220 to send the data

the second arduino, the arduino uno is connected to the 2 motors and the second card of the apc220 to receive the data

Snowman815901:
I can't tell you what you're doing wrong but I can offer a suggestion.

Have your receiving Arduino blink an LED or something when it receives something from the RF device. That way you'll all least know it's getting something.

You could also have your Mega as the receiver and hook the RF device to Serial1 or 2 or 3 and monitor serial 0 on your pc. That way when it receives something you can have it print what it received to the serial monitor. That should give you a clue at least.

...??? the arduino uno has a led that blinks only when programming, and also i tested the serial ports on both arduinos and they work, separately using the pc as receiver or transmitter, when trying arduino to arduino they dont work as they should

ok think about this, i have an arduino mega that has to send serial info over serial port 0, and an arduino uno that has to read that data, letting the apc220 module at a side, if i just wire the TX0 "Pin 1" on arduino mega to the RX on the arduino uno it should transmitt the data and do what the sketch says right?

well it does nothing, like its not connected

A somewhat similar discussion.

http://forum.arduino.cc/index.php?topic=247948.msg1771963#msg1771963

zoomkat:
A somewhat similar discussion.

Problem with Serial control of multiple servos - Programming Questions - Arduino Forum

this is assuming both arduinos communicate, but mines dont, my entire problem is that both arduinos dont communicate betweeen them for somewhat reason, but they communicate well will the pc

Did you connect the grounds together?

I don't know anything about the APC220 but I don't see anything about it in the code in your first post. Perhaps the APC modules are just connected to the Serial pins?

If you are using a Mega take advantage of its multiple Serial ports so that you can print stuff to the serial monitor as well as receiving or sending data on a different Serial port.

I can't figure from your post whether you have been able to send any data from one Arduino to the other using the APC220. If not, start with two very simple sketches that send the letter A from one and receive it at the other.

Also, you seem to be saying that you could use the APC220 to send data from an Arduino to a PC, How did you manage that?

...R

...??? the arduino uno has a led that blinks only when programming, and also i tested the serial ports on both arduinos and they work, separately using the pc as receiver or transmitter, when trying arduino to arduino they dont work as they should

Pin 13 is connected to an LED on the Arduino board. Try this for the receiver:

const int Pin1 = 3;
const int Pin2 = 5;
int LEDpin = 13;


void setup() {  
  Serial.begin(19200); 
  pinMode(Pin1, OUTPUT); 
  pinMode(Pin2, OUTPUT);
  pinMode(LEDpin, OUTPUT);
}

void loop() {
    
  while (Serial.available() > 0) {

  digitalWrite(LEDpin, HIGH);
  delay(100);
  digitalWrite(LEDpin, LOW);
  delay(100);
  digitalWrite(LEDpin, HIGH);
  delay(100);
  digitalWrite(LEDpin, LOW);
  delay(100);
 
    int M1 = Serial.parseInt();   
    int M2 = Serial.parseInt(); 
    
    if (Serial.read() == '\n') {  
      
      M1 = constrain(M1, 0, 255);
      M2 = constrain(M2, 0, 255);
      
      analogWrite(Pin1, M1);
      analogWrite(Pin2, M2);     
     }
  }
}

That way you'll know if they're communicating at all. Right now you only know that's it's not doing what you want.

Also,

If you are using a Mega take advantage of its multiple Serial ports so that you can print stuff to the serial monitor as well as receiving or sending data on a different Serial port.

Like I said.

all i have to say is thank you for the led thing, it helped me verify if arduinos communicate, they did,

one problem was in the receiver sketch, had to put the int M1=Serial.parseInt inside the if (Serial.read() == '\n') or it wont work, it doesnt make any sense but i just did it and worked

and for some reason pwm pins 3,4,5,6,7 and 8 didnt work, had to test every pin until i got 9 and 10 working,

have it working right now, thanks for the help

Did you try Serial.write(sensorValue) instead of Serial.print(sensorValue) ?