Making a Robot With Arduino Bonus Material: NewSoftSerial

November 19, 2011 by · Leave a Comment 

This is the last post of the robot adventure. Along the way, I am debugging the robot, and realized that the zigbee is hijacking the serial port. Once again the arduino community to the rescue. Introducing NewSoftSerial. What this do is, it provide ‘soft’ serial, i.e another serial port to be used for let say, your xbee shield.

A sample usage is below, it is just a relay from the real serial to a soft serial, which I set to run on digital 2 and 4. The seeestudio doc says it can run on digital 11 and 12, but digital 11 and 12 is used by the motor driver. So I set it to use digital 2 and 4.

#include <NewSoftSerial.h>

uint8_t pinRx=2;
uint8_t pinTx=4;
long BaudRate = 57600;

NewSoftSerial mySerial(pinRx,pinTx);

void setup(){
  Serial.begin(BaudRate);
  mySerial.begin(BaudRate);

}

void loop(){
  if(mySerial.available()){
    int val = mySerial.read();
    mySerial.print(val);
    Serial.print(val);
  }
}

It just echo what the hardware serial to the serial I set for the zigbee. As you the library is pretty easy to use. To me anyway. You can download it on that page. And install it like any arduino library.

Share this article

About sweemeng
One of the resident code monkey,

Performance Optimization WordPress Plugins by W3 EDGE

Switch to our mobile site