Arduino to Arduino RS485 communication connection and code issues?


given:
arduino #1 leonardo  with robo mesh rs-485 serial shield (set automatic, , on when testing)
arduino #2 leonardo robo mesh rs-485 serial shield (set automatic, , on when testing)

when tested alone via usb serial arduino #1 responds correctly serial commands on usb.  responds 5 commands  y1, y2, y3, t1, t0.

when tested alone via usb serial arduino #2 sends 3 commands y1,y2,y3 (t1,t0 not implemented)  in response button presses.

connecting a , b b on rs485 results in no response @ arduino#1 when buttons pressed on arduino#2

connecting b , b on rs485 results in no response @ arduino#1 when buttons pressed on arduino#2

connecting a , b b on , ground ground rs485 results in rxd led on arduino#1 lights up, no resulting response button presses..

i admit totally new this, may obvious of you.   connecting robo mesh rs485 shield wrong? or code isn't sending serial command correctly using shield?

arduino#1 code
code: [select]



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) // if line read string 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 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 standing button

   currentstandingbutton = debouncestanding(laststandingbutton);  //debounce 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 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 lights on lights offaccording 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 last time blinked led
     previousmillis = currentmillis;  

     // if led off turn on , vice-versa:
     if (ledblinkstate == low)
       ledblinkstate = high;
     else
       ledblinkstate = low;

     // set led ledstate of 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);
  }
 

}






arduino #2
code: [select]

int wavingswitch = 10;
int standingswitch = 11;
boolean wavingcurrent = low;
boolean standingcurrent = low;
boolean yellowlightstate = low;
boolean lastwavingbutton = low;
boolean laststandingbutton = low;
boolean currentwavingbutton = low;
boolean currentstandingbutton = low;

float rawvoltage = 0;
float batvoltage = 0;


void setup()

{

 serial.begin(9600);
 pinmode(wavingswitch, input);
 pinmode(standingswitch, input);

}
 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()
{

   currentstandingbutton = debouncestanding(laststandingbutton);  //debounce 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("y2");
//      serial.println("loop 1");
   }
   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("y1");
//      serial.println("loop 2");

   }
   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("y2");
//      serial.println("loop 3");

   }  
   laststandingbutton = currentstandingbutton;
   
 // logic 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("y3");
//           serial.println("loop 4");

   }  
   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("y1");
//        serial.println("loop 5");
   
   }
   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("y3");
//            serial.println("loop 6");

   }
   lastwavingbutton = currentwavingbutton;
   
}





Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Arduino to Arduino RS485 communication connection and code issues?


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support