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?