Given:
Arduino #1 Leonardo With Robo mesh RS-485 serial shield (set to Automatic, and ON when testing)
Arduino #2 Leonardo With Robo mesh RS-485 serial shield (set to Automatic, and ON when testing)
When tested alone via USB serial Arduino #1 responds to correctly to serial commands over USB. Responds to 5 commands y1, y2, y3, t1, t0.
When tested alone via USB Serial Arduino #2 sends three commands y1,y2,y3 (t1,t0 not implemented) in response to button presses.
Connecting the A to A and B to B on the RS485 results in no response at Arduino#1 when buttons pressed on Arduino#2
Connecting the A to B and B to A on the RS485 results in no response at Arduino#1 when buttons pressed on Arduino#2
Connecting the A to A and B to B on and ground to ground RS485 results in Rxd LED on Arduino#1 to lights up, but no resulting response to button presses..
I admit I am totally new to this, so this may be obvious to some of you. Am I connecting the Robo mesh rs485 shield wrong? or is it my code that isn't sending the serial command correctly using the shield?
Arduino#1 code
int ledpin = 8;
int ledpin2 =9;
int ledpingreen =5;
int ledpinred = 6;
int wavingswitch = 10;
int standingswitch = 11;
int ledblinkState = LOW;
int ledblinkStateinv = LOW;
long wavingInterval = 200;
long previousMillis = 0;
boolean wavingCurrent = LOW;
boolean standingCurrent = LOW;
boolean yellowlightState = LOW;
boolean lastwavingbutton = LOW;
boolean laststandingbutton = LOW;
boolean currentwavingbutton = LOW;
boolean currentstandingbutton = LOW;
boolean trackgreen
void setup()
{
Serial.begin(9600);
pinMode (ledpin, OUTPUT);
pinMode (ledpin2, OUTPUT);
pinMode (wavingswitch, INPUT);
pinMode (standingswitch, INPUT);
pinMode (ledpingreen, OUTPUT);
pinMode (ledpinred, OUTPUT);
}
boolean debouncestanding(boolean last)
{
boolean current = digitalRead(standingswitch);
if (last != current)
{
delay(10);
current = digitalRead(standingswitch);
}
return current;
}
boolean debouncewaving(boolean last2)
{
boolean current2 = digitalRead(wavingswitch);
if (last2 != current2)
{
delay(10);
current2 = digitalRead(wavingswitch);
}
return current2;
}
void loop()
{
if (Serial.available() > 0) // this if line is to read string for yelllow state
{
if (Serial.peek() == 'y')
{
Serial.read ();
if (Serial.peek() == '2')
{
Serial.read();
yellowlightState = HIGH;
wavingCurrent = LOW;
standingCurrent = HIGH;
currentstandingbutton == HIGH;
currentwavingbutton == LOW;
}
if (Serial.peek() == '1')
{
Serial.read();
yellowlightState = LOW;
wavingCurrent = LOW;
standingCurrent = LOW;
currentstandingbutton == LOW;
currentwavingbutton == LOW;
}
if (Serial.peek() == '3')
{
yellowlightState = HIGH;
wavingCurrent = HIGH;
standingCurrent = LOW;
currentstandingbutton == LOW;
currentwavingbutton == HIGH;
}
}
if (Serial.peek() == 't') //This if line is to read track state
{
Serial.read();
if (Serial.peek() == '1')
{
digitalWrite(ledpingreen, HIGH);
digitalWrite(ledpinred, LOW);
}
if (Serial.peek() == '0')
{
digitalWrite(ledpingreen, LOW);
digitalWrite(ledpinred, HIGH);
}
}
while (Serial.available() > 0)
Serial.read();
}
// battery voltage reading
rawvoltage = analogRead(Abatterypin);
batvoltage = rawvoltage/85.25;
// logic for standing button
currentstandingbutton = debouncestanding(laststandingbutton); //debounce the button input
if (laststandingbutton == LOW && currentstandingbutton == HIGH && yellowlightState == LOW && wavingCurrent == LOW)
{
yellowlightState = !yellowlightState;
standingCurrent = !standingCurrent;
Serial.print("standing state =");
Serial.println(standingCurrent);
Serial.print("waving state =");
Serial.println(wavingCurrent);
Serial.print("yellow light state =");
Serial.println(yellowlightState);
Serial.println();
Serial.print("battery voltage =");
Serial.println(batvoltage);
Serial.println();
}
else if (laststandingbutton == LOW && currentstandingbutton == HIGH && yellowlightState == HIGH && wavingCurrent == LOW)
{
yellowlightState = !yellowlightState;
standingCurrent = !standingCurrent;
Serial.print("standing state =");
Serial.println(standingCurrent);
Serial.print("waving state =");
Serial.println(wavingCurrent);
Serial.print("yellow light state =");
Serial.println(yellowlightState);
Serial.println();
Serial.print("battery voltage =");
Serial.println(batvoltage);
Serial.println();
}
else if (laststandingbutton == LOW && currentstandingbutton == HIGH && yellowlightState == HIGH && wavingCurrent == HIGH)
{
standingCurrent = !standingCurrent;
wavingCurrent = !wavingCurrent;
Serial.print("standing state =");
Serial.println(standingCurrent);
Serial.print("waving state =");
Serial.println(wavingCurrent);
Serial.print("yellow light state =");
Serial.println(yellowlightState);
Serial.println();
Serial.print("battery voltage =");
Serial.println(batvoltage);
Serial.println();
}
laststandingbutton = currentstandingbutton;
// logic for waving button
currentwavingbutton = debouncewaving(lastwavingbutton);
if (lastwavingbutton == LOW && currentwavingbutton == HIGH && yellowlightState == LOW && standingCurrent == LOW)
{
yellowlightState = !yellowlightState;
wavingCurrent = !wavingCurrent;
Serial.print("standing state =");
Serial.println(standingCurrent);
Serial.print("waving state =");
Serial.println(wavingCurrent);
Serial.print("yellow light state =");
Serial.println(yellowlightState);
Serial.println();
Serial.print("battery voltage =");
Serial.println(batvoltage);
Serial.println();
}
else if (lastwavingbutton == LOW && currentwavingbutton == HIGH && yellowlightState == HIGH && standingCurrent == LOW)
{
yellowlightState = !yellowlightState;
wavingCurrent = !wavingCurrent;
Serial.print("standing state =");
Serial.println(standingCurrent);
Serial.print("waving state =");
Serial.println(wavingCurrent);
Serial.print("yellow light state =");
Serial.println(yellowlightState);
Serial.println();
Serial.print("battery voltage =");
Serial.println(batvoltage);
Serial.println();
}
else if (lastwavingbutton == LOW && currentwavingbutton == HIGH && yellowlightState == HIGH && standingCurrent == HIGH)
{
wavingCurrent = !wavingCurrent;
standingCurrent = !standingCurrent;
Serial.print("standing state =");
Serial.println(standingCurrent);
Serial.print("waving state =");
Serial.println(wavingCurrent);
Serial.print("yellow light state =");
Serial.println(yellowlightState);
Serial.println();
Serial.print("battery voltage =");
Serial.println(batvoltage);
Serial.println();
}
lastwavingbutton = currentwavingbutton;
// toggle from lights on to lights offaccording to state
if (yellowlightState == HIGH && standingCurrent == HIGH)
{
digitalWrite(ledpin, HIGH);
digitalWrite(ledpin2, HIGH);
tone(tonepin, 200);
}
if (yellowlightState == LOW && standingCurrent == LOW)
{
digitalWrite(ledpin, LOW);
digitalWrite(ledpin2, LOW);
noTone(tonepin);
}
if (yellowlightState == HIGH && wavingCurrent == HIGH)
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > wavingInterval)
{
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledblinkState == LOW)
ledblinkState = HIGH;
else
ledblinkState = LOW;
// set the LED with the ledState of the variable:
ledblinkStateinv = !ledblinkState;
digitalWrite(ledpin, ledblinkState);
digitalWrite(ledpin2, ledblinkStateinv);
if (ledblinkState == HIGH)
tone(tonepin, 500);
else noTone(tonepin);
}
}
if (yellowlightState == LOW && wavingCurrent == LOW)
{
digitalWrite(ledpin, LOW);
noTone(tonepin);
}
}