Go Down

Topic: Software serial in 04 (Read 694 times) previous topic - next topic


Hi there I am trying to drive a motor with a Little Step-U
Unipolar Stepper Motor Controller http://www.tla.co.nz/lit_step.html

Can someone please explain how to use the new software serial in 04?


Same question for me.

I've found some interesting files in Arduino libraries, like "uartsw.c" and "uartswconf.h". But no way to use them in my program for the moment.

Any idea?


See this thread for some info:


Aug 08, 2006, 08:25 pm Last Edit: Aug 08, 2006, 09:18 pm by hdeweyh Reason: 1
I just got the following code working based on the examples in the FAQ. Only weird thing is it sends two bytes for every byte, one is the correct byte one is  dec 192. Consistently over and over!

#define BAUDRATE 9600
// the width of a single bit of serial data in microseconds
// in each second (1000000 microseconds) there are a number of bits equal
// to the baud rate (e.g. 9600), so each bit lasts for 1000000 / baudrate
// microseconds
int width = 1000000 / BAUDRATE;
int fudge = -25;
int TXfudge = -20;
int rx = 6;
int tx = 7;

void setup() {
void SWprint(int data)
 int mask;
 delayMicroseconds(width + TXfudge);
 for (mask = 0x01; mask; mask <<= 1) {
   if (data & mask){ // choose bit
     digitalWrite(tx,HIGH); // send 1
     digitalWrite(tx,LOW); // send 1
   delayMicroseconds(width + TXfudge);
 //stop bit
 digitalWrite(tx, HIGH);
 delayMicroseconds(width + TXfudge);
int SWread()
 int val = 0;
 // one byte of serial data (LSB first)
 // ...--\    /--\/--\/--\/--\/--\/--\/--\/--\/--...
 //       \--/\--/\--/\--/\--/\--/\--/\--/\--/
 //      start  0   1   2   3   4   5   6   7 stop

 while (digitalRead(rx));

 // confirm that this is a real start bit, not line noise
 if (digitalRead(rx) == LOW) {
   // frame start indicated by a falling edge and low start bit
   // jump to the middle of the low start bit
   delayMicroseconds(width / 2);
   // offset of the bit in the byte: from 0 (LSB) to 7 (MSB)
   for (int offset = 0; offset < 8; offset++) {
     // jump to middle of next bit
     delayMicroseconds(width + fudge);
     // read bit
     val |= digitalRead(rx) << offset;
   delayMicroseconds(width + fudge);
 return val;
void loop()
   int SWval;
   SWval = SWread();



Are you sending between two Arduino boards?  If so, you might try sending to something else with a hardware serial port (like a Wiring board) to see if the problem is in the sending or the receiving.  


I am sending between Arduino and a PC. I have tested the code using hardware serial on half (first HW TX with SW RX then HW RX with SW TX) and the problem is definitely in the sending.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131