Issues with serial.print

I have an Arduino Zero with an XBee shield and module. On the other side is a RPi with another XBee module. I've verified the XBees are transmitting and receiving data fine. The code below works with the RPi+XBee on the Uno, but not with the Zero. The output appears in the serial monitor with the Zero, but the other XBee never sees the data.

int i=1;
 
void setup()
{
    Serial.begin(9600);
}
 
void loop()
{
    Serial.print("serial-test: ");
    Serial.println(i);
    i++;
    delay(1000);
}

Any suggestions? Thanks!

Hi prolucid,

try to use Serial1 instead of Serial.

The current mapping of serial ports for the Zero is:

Serial -> to Programming Port
Serial1 -> UART on pin 0 and 1
SerialUSB -> to Native Port

Thank you for explaining the serial assignments. I tried using Serial1 and was not able to see any data pass through to the other XBee. I've tried three different shields and XBees I have working with other boards so I don't think the problem is there.

Any other suggestions? Thanks.

From the posts above I know only that you have a Zero with an XBee module connected to pins 0 and 1, using Serial1 should be enough to send data to the module but since this is not sufficient to solve your issue you must explain a bit more:

  • your hardware setup
  • copy here the full sketch you're trying to use
  • the expected result
  • what are you currently getting

Hardware
Programming with the latest IDE (1.6.5) on Windows 7
Radio-A is the laptop with XBee Pro 900 on an explorer
Radio-B is the Arduino Zero, SainSmart XBee Pro shield, XBee Pro 900

Full Sketch for Radio-B

int i=1;

void setup() {
  Serial1.begin(9600);
}

void loop() {
  Serial1.print("zero-serial1-test: ");
  Serial1.println(i);
  i++;
  delay(1000);  
}

For troubleshooting, I'm monitoring with XCTU. With this sketch on the Arduino Zero I expect to see:

zero-serial1-test: 1
... (1 second)
zero-serial1-test: 2
...

However I see no output ("zero-serial1-test: [n]") and no packets in XCTU on the laptop. When I use the same shield and XBee on Radio-B with an UNO with the same sketch, it works fine. In both situations I can see Radio-B via XCTU so I know that XBee-B is powered up and has a link, just no data from the Zero.

Is the shiled compatible with a 3.3v equipment? (just trying to figure out the possible cause of the problem)

I was wondering about that. Their product page doesn't say either way:

There is a schematic here but I'm still learning and unable to decipher if it's 3.3v compatible or not:

I've also tried with this shield:

And it says it supplies 3.3v to the XBee so I imagine that ought to work.

I'd love suggestions on a particular (known to work) shield if you have any ideas.

Thank you!

I'm not sure about the SainSmart shield, but the SeeedStudio one does have a voltage regulator built in. Also, wouldn't the voltage only be an issue for 5v arduino boards? Since both the XBee and Zero are 3.3v, I'm guessing they shouldn't need to adjust the voltage.

The sainsmart shield has a voltage divider made with a resistor partition of 10K and 15K:

  • with a Vin of 5.00v you get a Vout of 3.00v on the DIN pin of the XBee module, that is fine
  • with a Vin of 3.30v you get a Vout of 1.98v that is under the minimum needed by the Xbee module (from the datasheet I read that the minimum is 0.7Vcc = 0.73.30v = 2.31v).
    I can say for sure that the sainsmart shield is not 3.3v compatible.

The SeeedStudio shiled instead use a level converter so it seems to be compatible with both 5v and 3.3v (even if the IOREF pin is not used the level converter accepts any voltage between 3.3v and 5.5v and always outputs 3.3v, great choice for the shield). So let's focus on this shield.

@prolucid, can you confirm that:

  • you mounted the seeedstudio's shield on the zero board
  • you selected pins 0 and 1 as RX/TX with the jumpers provided on the shield
  • you loaded the following sketch on the zero:
int i=1;

void setup() {
  Serial1.begin(9600);
}

void loop() {
  Serial1.print("zero-serial1-test: ");
  Serial1.println(i);
  i++;
  delay(1000);  
}

what I expect is to receive from the other XBee module (the one connected to PC) the strings "zero-serial1-test"... etc.

I do not expect to see the strings coming from the serial monitor on the Zero because the Serial and Serial1 are two completely separated serial ports. This is different from the Uno where you use Serial to print on both pin 0/1 AND serial monitor.

If this do not work we should check the functionality of UART on pins 0/1.