Go Down

Topic: Softwareserial (Read 11 times) previous topic - next topic


SoftwareSerial has some timing issues. It doesn't push the tx pin high when started, that can ruin the first character, but you can work around that by setting it high when you set the pinmode for it.

Worse, the rather expensive math operation to compute the bit delay gets shuffled into an unfortunate code path and makes the start bit be about 1.5 bit times long ensuring that your bits are sampled on the edges instead of the centers

Still, I wouldn't expect you to get nothing from that. I'd expect you to get a few percent of your characters garbled, or all of them, depending on the timing of your receiver's uart.

(Patches are in the works for 0008 software serial to stabilize it.)

SoftwareSerial::begin() just stores your bit rate in an instance variable. It seems unlikely that could cause a problem directly unless you have run out of SRAM. If you don't do a ::begin() you will get a divide by zero error in print. I don't know what that does.


Interesting to see that someone came across a similar problem.

I am currently using the Arduino Mini to read data from an RFID reader and send it through the serial. To communicate with the RFID reader (which also talks through serial, 9600 baud rate) I need to use a SoftwareSerial.

Whenever a call to SoftwareeSerial.read() is made I get some character printed out on the USB Serial (usually 'b') *even* if I don'call any printing function; and then the Mini resets  :-?

This is exactly the same behaviour that I get if I don't have anything plugged onto my designated software serial ports.

I have previously connected the RFID reader directly to the Arduino USB and I am sure that it is working. I also have tried programming the Mini so that the RFID reader is connected to the hardware serial pors and the USB to the software ones. The result is the same, the Mini keeps on resetting.

Code follows:

#include <SoftwareSerial.h>

#define rxPin 3
#define txPin 2
#define ledPin 13

// set up a soft serial port
SoftwareSerial mySerial(rxPin, txPin);

void setup()  {

 // define pin modes for tx, rx, led pins:
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 pinMode(ledPin, OUTPUT);
 // set txPin high (as recommended in forum)
 digitalWrite(txPin, HIGH);
 // set the data rate for the serial ports
 // say something
 Serial.println("Hello World!");


void loop() {  

 char someChar = '0';
 someChar = mySerial.read();

 // print out the character:
 Serial.print(someChar, DEC);

 // toggle an LED just so you see the thing's alive.  
 // this LED will go on with every OTHER character received:


So does SoftwareSerial implement the whole serial protocol or should I be sending some character to start the serial communication? Altough the reset thing is quite strange....



it's interesting i'm having trouble implementing softwareserial also. i am just trying to use the basic example at the arduino.cc site to see how it works  - http://www.arduino.cc/en/Reference/SoftwareSerialExample - but it does not run properly. i've also tried some of the suggestions here (setting tx high in setup) but that has had no effect. has anybody run this successfully?


Apr 23, 2007, 09:54 pm Last Edit: Apr 23, 2007, 09:54 pm by Daniel Reason: 1

in order for use to give you a good answer you need to give us more detail.. code, pictures, videos, text description. Unfortunately most of us failed our courses on mind-reading at school. :)



Apr 23, 2007, 10:33 pm Last Edit: Apr 23, 2007, 10:34 pm by myusername Reason: 1

in order for use to give you a good answer you need to give us more detail.. code, pictures, videos, text description. Unfortunately most of us failed our courses on mind-reading at school. :)


i'm not sure what additional information you would need. i am using the exact same code used in the softwareserial example - http://www.arduino.cc/en/Reference/SoftwareSerialExample - with no modifications or changes. i wanted to see first if the example would actually work. i have an arduino NG i am running the latest version (0007). in the example serial data is sent through pins 2 and 3 - again as described in the example which i have not modified.

pins 2, 3 are connected to a FTDI rs232 usb-serial adapter. using the regular serial commands it works just fine. when i switch the code over to use softwareserial it does not work.

the only thing changed in this setup is the addition of the softwareserial declaration and changing the instances of send.serial(), read.serial(), etc. to the softwareserial command detailed in the example.

so i'm still wondering what the problem might be.

just wondering, has anybody implemented the example successfully?

Go Up