Let's Make Robots!

TX2,RX2 on SPIDER board

I am using SPIDER for next project to run 30 servos plus XBEE with voice/sound control.

Never work with 2nd TX/RX port on Arduino before and not to sure if I do this correctly. I have search on web and see how it should be setup in any easy I could understand and following code is what I found and modified a bit to start of:

#define sndSerial Serial1

void InitSnd(void){
    sndSerial.begin(9600);
}
void setup(){
  Serial.begin(9600);
  InitSnd();
}
void loop(){
  Serial.println("Serial");
  delay(500);
  sndSerial.println("Sound");
  delay(500);
}

The result only shows "Serial". Wondering which part goes wrong and hope anyone could give me a hand. Thank you!!

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

It sounds like you have 3 arduinos, 2 of which will later be connected with an x-bee, but are now connected with wires. You are also using the terminal to keep an eye on what is being sent. I am a bit confused as to what serial is going where but I think I can break this down a bit.

If the goal is to send a "command" from one arduino to the other, I would try to make this a LOT simpler. First off, start with just 2 arduinos. Program one that whenever it receives "65" it will blink a LED. Then wire it to the first serial port of the spider. TX to RX, Rx to TX, and connect grounds together. Now, send a "65" and see if you can get your LED to blink. If does not work, fix it. If it does, do the same thing, but use serial1 to transmit the "65" (you will have to move your wiring over to the serial1 pins).

Assuming these 2 tests work, you have eliminated a ton of stuff that "could be" the problem. You may now try a similar test but using both serials in the same sketch at the same time. Try to send 65 from serial and 66 from the other. Program the receiving arduino to do one blink for 65 and 2 blinks for 66. Now you know that both serials are working, the connections are right and the receiving code is working.

Next, add your X-bees and repeat the tests above again.

If you got this far, try sending more complicated data.

First of all, it was stupid me for not wire Gnd.

2nd, I end up using <NewSoftSerial.h> and it works now.

Master(SPIDER):

void setup()  {
  Serial.begin(9600);
  Serial3.begin(9600);
}
void loop()  { 
  Serial.println("on");
  Serial3.print("n");
  delay(5000);
  Serial.println("off");
  Serial3.print("f");
  delay(5000);                           
}

 


 

Slave(Atmega328):

#include <NewSoftSerial.h>

NewSoftSerial mySerial(2, 3);
int c;
void setup()
{
  pinMode(12,OUTPUT);
  pinMode(13,OUTPUT);
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop()  { 
  while (mySerial.available() < 1) {}
   
  c = mySerial.read();
  Serial.println(c);
  if(c=='n'){
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
  }else{
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
  }
}

 


So the result is :Serial3 on SPIDER is sending data to newSerial pin3 on slave Arduino. Works :)