NewSoftSerial

A New Software Serial Library for Arduino

News: NewSoftSerial is in the core!  Starting with Arduino 1.0 (December, 2011), NewSoftSerial has replaced the old SoftwareSerial library as the officially supported software serial library.  This means that if you have 1.0 or later, you should not download this library.  To port your code to 1.0, simply change all NewSoftSerial references to SoftwareSerial.

NewSoftSerial is the latest of three Arduino libraries providing “soft” serial port support. It’s the direct descendant of ladyada’s AFSoftSerial, which introduced interrupt-driven receives — a dramatic improvement over the polling required by the native SoftwareSerial.

Without interrupts, your program’s design is considerably restricted, as it must continually poll the serial port at very short, regular intervals. This makes it nearly impossible, for example, to use SoftwareSerial to receive GPS data and parse it into a usable form. Your program is too busy trying to keep up with NMEA characters as they arrive to actually spend time assembling them into something meaningful. This is where AFSoftSerial’s (and NewSoftSerial‘s) interrupt architecture is a godsend. Using interrupt-driven RX, your program fills its buffer behind the scenes while processing previously received data.

Improvements

NewSoftSerial offers a number of improvements over SoftwareSerial:

  1. It inherits from built-in class Print, eliminating some 4-600 bytes of duplicate code
  2. It implements circular buffering scheme to make RX processing more efficient
  3. It extends support to all Arduino pins 0-19 (0-21 on Arduino Mini), not just 0-13
  4. It supports multiple simultaneous soft serial devices.*
  5. It supports a much wider range of baud rates.**
  6. It provides a boolean overflow() method to detect buffer overflow.
  7. Higher baud rates have been tuned for better accuracy.
  8. It supports the ATMega328 and 168.
  9. It supports 8MHz processors.
  10. It uses direct port I/O for faster and more precise operation.
  11. (New with version 10).  It supports software signal inversion.
  12. (New) It supports 20MHz processors.
  13. (New) It runs on the Teensy and Teensy++.
  14. (New) It supports an end() method as a complement to begin().

*But see below for an important caveat on multiple instances.
**Be circumspect about using 300 and 1200 baud though. The interrupt handler at these rate becomes so lengthy that timer tick interrupts can be starved, causing millis() to stop working during receives.

Using Multiple Instances

There has been considerable support for an library that would allow multiple soft serial devices. However, handling asynchronously received data from two, three, or four or more serial devices turns out to be an extremely difficult, if not intractable problem. Imagine four serial devices connected to an Arduino, each transmitting at 38,400 baud. As bits arrive, Arduino’s poor little processor must sample and process each of 4 incoming bits within 26 microseconds or else lose them forever. Yikes!

It occurred to me, though, that multiple instances could still be possible if the library user were willing to make a small concession. NewSoftSerial is written on the principle that you can have as many devices connected as resource constraints allow, as long as you only use one of them at a time. If you can organize your program code around this constraint, then NewSoftSerial may work for you.

What does this mean, exactly? Well, you have to use your serial devices serially, like this:

#include <NewSoftSerial.h>

// Here's a GPS device connect to pins 3 and 4
NewSoftSerial gps(4,3);

// A serial thermometer connected to 5 and 6
NewSoftSerial therm(6,5);

// An LCD connected to 7 and 8
NewSoftSerial LCD(8,7); // serial LCD

void loop()
{
  ...
  // collect data from the GPS unit for a few seconds
  gps.listen();
  read_gps_data();  // use gps as active device
  // collect temperature data from thermometer
  therm.listen();
  read_thermometer_data(); // now use therm
  // LCD becomes the active device here
  LCD.listen();
  LCD.print("Data gathered...");
  ...
}

In this example, we assume that read_gps_data() uses the gps object and read_thermometer_data() uses the therm object. Any time you call the listen() method, it becomes the “active” object, and the previously active object is deactivated and its RX buffer discarded. An important point here is that object.available() always returns 0 unless object is already active. This means that you can’t write code like this:

void loop()
{
  device1.listen();
  if (device1.available() > 0)
  {
    int c = device1.read();
    ...
  }
  device2.listen();
  if (device2.available() > 0)
  {
    int c = device2.read();
    ...
  }
}

This code will never do anything but activate one device after the other.

Signal Inversion

“Normal” TTL serial signaling defines a start bit as a transition from “high” to “low” logic.  Logical 1 is “high”, 0 is “low”.  But some serial devices turn this logic upside down, using what we call “inverted signaling”.  As of version 10, NewSoftSerial supports these devices natively with a third parameter in the constructor.

NewSoftSerial myInvertedConn(7, 5, true); // this device uses inverted signaling
NewSoftSerial myGPS(3, 2); // this one doesn't

Library Version

You can retrieve the version of the NewSoftSerial library by calling the static member library_version().

int ver = NewSoftSerial::library_version();

Resource Consumption

Linking the NewSoftSerial library to your application adds approximately 2000 bytes to its size.

Download

The latest version of NewSoftSerial is available here: NewSoftSerial12.zip.  Note: don’t download this if you have Arduino 1.0 or later.  As of 1.0, NewSoftSerial is included in the Arduino core (named SoftwareSerial).

Change Log

  1. initial version
  2. ported to Arduino 0013, included example sketch in package
  3. several important improvements: (a) support for 300, 1200, 14400, and 28800 baud (see caveats), (b) added bool overflow() method to test whether an RX buffer overflow has occurred, and (c) tuned RX and TX for greater accuracy at high baud rates 38.4K, 57.6K, and 115.2K.
  4. minor bug fixes — add .o file and objdump.txt to zip file for diagnostics.
  5. etracer’s inline assembler fix to OSX avr-gcc 4.3.0 interrupt handler bug added.
  6. ladyada’s new example sketch, fix to interrupt name, support for 328p.
  7. etracer’s workaround is now conditionally compiled only when avr-gcc’s version is less than 4.3.2.
  8. 8 MHz support and flush() and enable_timer0()  methods added
  9. digitalread/write scrapped in favor of direct port I/O.  Revised routines now get perfect RX up to 57.6K on 16MHz processors and 31.25K on 8MHz processors.
  10. inverted TTL signalling supported.  20MHz processors supported.  Teensy and Teensy++ supported.  New end() method and destructor added to clean up.
  11. added listen() method to explicitly activate ports.
  12. warn users about 1.0 conflict

Acknowledgements

Many thanks to David Mellis, who wrote the original SoftwareSerial, and to the multi-talented ladyada, whose work with AFSoftSerial is seminal.  Ladyada also provided the “Goodnight, moon” example sketch, fixed a problem with the interrupt naming (see v6) and tested NSS with the 328p.

Thanks also to rogermm and several other forum users who have tested NewSoftSerial and given useful feedback.

The diligent analysis of forum user etracer yielded the root cause of a tricky problem with NSS on OSX.  A bug in avr-gcc 4.3.0 causes the compiler to fail to generate the proper entry and exit sequences for certain interrupt handlers.  etracer identified the problem and provided an inline workaround.  etracer’s fix is in NSS 5.

User jin contributed a large body of work based on NSS and identified a potential problem that could result in data loss (fixed in NSS 5).  jin also made a variant of NSS that supports 4-pin serial, with the additional pins providing a very nice RTS/CTS flow control.  We may see this in NSS in the near future.

Thanks to Garret Mace, who contributed the delay tables for 20MHz processors and claims that he can send and receive at 115K baud.  Cool!

Thanks to Paul Stoffregen, both for his fine work with Teensy and Teensy++, and for contributing some useful suggestions that help NewSoftSerial run on them without modification.

I appreciate any and all input.

Mikal Hart

Page last updated on July 3, 2013 at 7:37 pm
647 Responses → “NewSoftSerial”

  1. Mikal

    12 years ago

    @Jay,

    There is no way that you can handle *all* the data from each of the three 4800 baud ports. The best you can do is handle one port for 2+ seconds or so, then shift to the next one and cycle between them similarly.


  2. Klaus

    12 years ago

    Hi, I might be too tired to find it at the moment, or just stupid, but… is there anywhere a documentation of the functions & argument supported by NewSoftSerial? Or is it just looking through examlpes and the C++ source code?

    Regards, Klaus


  3. Pent R.

    12 years ago

    Did the “write” function at one point take in a pointer (uint8_t*) and a length? I recompiled some of my old code (from 4 months ago) using this library and it failed because my code was sending the write function a pointer and message length. I’m just a bit curious because it worked fine months ago.


  4. David

    12 years ago

    Is it possible to use NewSoftSerial to send data while simultaneously receiving data on a UART? I understand the Arduino UART can lose data if it arrives while I’m in an interrupt handler, and NewSoftSerial is interrupt-based.


  5. Lutorm

    12 years ago

    Thanks for your work on this, it’s a great addition! I’m having a weird problem, though. I’m reading data from a Matrix Orbital display at 19200. There is very little traffic. When I build my code on a Mac, with avr-gcc 4.5.3 and Arduino-0023, I get the expected results:

    23 2A 03 52 01 FF FF

    However, if I build the code on a PC, using avr-gcc 4.6.2 and Arduino-0023, I’m getting:

    23 AA 83 A8 80 FF FF

    Notice how it’s *almost* as if the packets after the first one have 0x80 added to them. The results are totally stable, so it’s not a one-off spurious thing. Do you have any idea what could cause one bit to “hang” like that?


  6. Justin

    12 years ago

    My 2c: I’m using it with an XBee Shield project, and Uno.
    It does work. That is good. The problem is that you definitely cannot send while receiving, the reception of the data is corrupted if it is sending.
    So you must carefully think about how you might want to use this for two-way communication.


  7. Tyler DeWitt

    12 years ago

    I’ve been out of the Arduino world for a while, sorry if this has been answered. When I try to compile to library I get the following error:

    In file included from NewSoftSerialTest.cpp:2:
    C:\Users\tyler.HQ\Documents\Arduino\libraries\NewSoftSerial/NewSoftSerial.h:71: error: conflicting return type specified for ‘virtual void NewSoftSerial::write(uint8_t)’
    C:\Users\tyler.HQ\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error: overriding ‘virtual size_t Print::write(uint8_t)’

    I took a look at those files, and the names of the function are the same (write), but they are declared in different classes. Is there a fix for that?

    PS-I made a reverse geocaching box years ago and still love playing with it. Thanks for the great idea!


  8. Jason R. Smith

    12 years ago

    This worked like a charm! Great job! I am using it to talk to a CrystalFontz CFA632-NFA-KS LCD display. One thing, though – The board was expecting inverted signal, but it didn’t work when I used the “true” designator when I created the NSS instance. I removed that, and it worked fine. Not sure what to make of that.


  9. Roy

    12 years ago

    Hi, new to your website. Great work.

    I recently downloaded your newsoftserial library and attempted to use it with the latest Ardino l download. I am experiencing compiler errors for
    NSS.write on a UNO target. Compiling worked when using an older version 0022. Any suggestions?? Compile error follows.

    In file included from sketch_dec12b.cpp:1:
    C:\Users\Roy\Documents\Arduino\libraries\NewSoftSerial/NewSoftSerial.h:71: error: conflicting return type specified for ‘virtual void NewSoftSerial::write(uint8_t)’
    C:\arduino-ONE\hardware\arduino\cores\arduino/Print.h:48: error: overriding ‘virtual size_t Print::write(uint8_t)’


  10. Cenek

    12 years ago

    hello, I need 2 stop bits, how should I change the code? thanks


  11. amok

    12 years ago

    after I moved to Arduino IDE 1.0, the NewSoftSerial doesn’t compile anymore. Any trick/tweak on how to get that fixed? Thx!


  12. Mikal

    12 years ago

    Things have changed in Arduino land. I need to build new versions of all my libraries.

    M


  13. Mikal

    12 years ago

    @David,

    No, unfortunately, both sending and receiving a byte require total control of the processor. You can’t (reliably) receive data while transmitting.


  14. Mikal

    12 years ago

    @Lutorm,

    Gee, I don’t know. 19.2K is not a very fast speed. I’m not sure. Anyone?


  15. Jim

    12 years ago

    Hello Mikal.
    I have two serial displays that I have been using with a Basic Stamp project. I am now converting the entire project over to an Arduino UNO. I am using NewSoftSerial software so I can have two serial ports. However I can not get either display to work. After much diagnosis I have learned that the way the Basic Stamp was talking to them was a serial command of 9600baud 8bit no parity inverted. I had no idea that I was using an inverted command until I dug into the old stamp code. So I added the “,true” statement to the NewSoftSerial but no help. Is it posible there is more I need to do?

    Thanks


  16. Mikal

    12 years ago

    @Justin, yes, unfortunately it does require some careful thought to get it just right.


  17. Mikal

    12 years ago

    @Tyler, if you’re using 1.0 you should use SoftwareSerial, which is really just NewSoftSerial renamed and inserted into the core.


  18. Mikal

    12 years ago

    @Roy/@Amok,

    With Arduino 1.0 you no longer use the external NewSoftSerial library. It has been renamed “SoftwareSerial” (replacing the old SoftwareSerial) and place in the core.


  19. Mikal

    12 years ago

    @Jim,

    I would expect that to work with the “true” parameter for inverted logic. Hmm..


  20. Jan Krueger

    12 years ago

    hi out there,

    i have an issue with the serial port of my ArduinoProMini (16MHz), which i hope might be no big deal for someone with more insight than me…

    i am reading serial data from a Spektrum Satellite receiver (16bytes every 22msec), in 115200 baud. to have good accuracy, i used the hardware serial port for this (only RX).

    to monitor the data, i use SoftwareSerial (output) via the FTDI (only TX), with 115200 baud, too – works very well!

    NOW when i change the baud rate of the SoftwareSerial monitor to 38400 baud (which i will later need to control a Pololu-Servo-Interface-board), the data gets corrupted! that is, you can still recognise the pattern, but there are many damaged or missed bytes.

    any idea, comment, help? thanks so much –

    jan from berlin

    ps. here comes the very simple script that doesn’t work (or does work with MonitorSerial.begin (115200) instead of (38400))…

    #include
    SoftwareSerial MonitorSerial(5, 6); // serial monitor on Pin 6 (only RX)

    // serial data from Satellite receiver is connected to RX1 on the
    // ArduinoProMini, 5V, 16MHz, ATmega328; Arduino Software 1.0

    int index = 1;
    int val[17];
    int burp = 0;

    void setup()
    {
    MonitorSerial.begin(38400); // to monitor on screen, or later forward
    MonitorSerial.print(“Test”); // processed values to Servo-Interface
    MonitorSerial.println(); // with max. baudrate 38400

    Serial.begin(115200); // serial data rate of the Spektrum Satellite
    }

    void loop()
    {
    if (Serial.available() > 0)
    {
    val[index]= Serial.read();
    if (val [index] == 0x01 && val [index-1] >=0)
    {
    for (index =0; index <17; index++)
    {
    MonitorSerial.print(val[index]);
    MonitorSerial.print("\t");
    }
    MonitorSerial.print(burp);
    MonitorSerial.println();
    index=0;
    burp++;
    }
    index++;
    }
    }


  21. Ian

    12 years ago

    Hi Mikal,
    Great work :)
    It isn’t clear to me how timing is managed. It seems to me that ‘MsTimer2’ conflicts with your library?
    Cheers

    Ian


  22. Mikal

    12 years ago

    @Ian,

    Anything that generates interrupts (read: Tone, Servo, MsTimer2) has the potential of interfering with the NewSoftSerial timing, and vice versa.


  23. conrad

    12 years ago

    Hi Mikal,
    I just read your response to @Ian and realised that is my problem as well! I’m reading a compass and GPS with the SoftwareSerial and triggering a camera with the Servo.h library. Alone, the Servo trigger works great, the moment I SoftwareSerial.begin(), the signal when Servo.write(0) then the signal fluctuates. I don’t get this behaviour though when Servo.write(180) – the max.
    Any thoughts on a solution to this?
    Thanks and have a great day,
    Conrad :)


  24. Mikal

    12 years ago

    @Conrad,

    Yep, it’s a pretty well-known problem. One workaround that I often use is to employ the older version of the Arduino Servo library, which I have posted here as PWMServo. It doesn’t use interrupts to drive the motor, but has the disadvantage of only being usable on pins 9 or 10. Will that work for you?


  25. Marjan

    12 years ago

    Hi, Mikal!

    1. Library works great for enabling another serial to ATmega328 series – having universal code for both boards (below).

    2. Now I would like to attach a (non-default) logger which has 4800,8E2,no handshake protocol.

    @Cenek, @Tinker, … Maybe anyone heard of configurability options, i.e.style parity, data and stopbit configuration options below already implemented?

    3. What about adding code to TX – void SoftwareSerial::write(uint8_t b), between 8th bit and “restoring pin to natural state”, sth. like:

    if Even(b) { // calculate Even
    tx_pin_write(HIGH); // send 1
    tunedDelay(_tx_delay);
    }
    tx_pin_write(HIGH); // send 1st stop bit
    tunedDelay(_tx_delay);
    tx_pin_write(HIGH); // send 2nd stop bit
    tunedDelay(_tx_delay);

    ===================
    Here’s my code part:

    #ifdef MEGA
    const byte rxPin = 19; // (just for breadboard /proto reference)
    const byte txPin = 18; //
    #define serDevice Serial1 // substitute
    #else
    const byte rxPin = 6; // receivePin
    const byte txPin = 7; // transmitPin
    SoftwareSerial serDevice = SoftwareSerial(rxPin, txPin);
    #endif


  26. David (D9W)

    12 years ago

    I was wondering if you have run across problems with using the LS20031 GPS from SparkFun and the SoftwareSerial? You can read over at the Sparkfun forum what I have ran into with this library >> http://forum.sparkfun.com/viewtopic.php?f=32&t=26325&p=139796#p139796

    If I do a direct serial dump to the monitor I get clean good GPS “code”, but using SoftwareSerial I get things like >>

    $GPGLL,4751.6603,N,1214™—¦’&’éŊ’ʒ¢r†‚‚b
    ±©ÑÝ5R”:A›Šub$GPGGA,182925.000,4751.6603,N,12142.3928,W,1,7,1.42,64.7,M,-16.9,M,,*5D
    $GPGLL,4751.6603,N,12142.3928,W,182925.000,A,A*4E
    $GPGAº$GPGGA,182925.200,4751.6603,N,12142.3928,W,1,8,1.04,64.7,M,-16.9,M,,*52
    $GPGLL,4751.6603,N,1214™—¦’&’¥ŠÂ’Ê’ªr&‚‚b
    ±©Ñ
    5)‘:A›bšÂ¹$GPGGA,182925.400,4751.6603,N,12142.3928,W,1,8,1.04,64.7,M,-16.9,M,,*54

    Not all of the characters are showing up in that example, but I think you can see some of them.

    What kills me is that back in .22 IDE I got both this library and tinyGPS to work with expanding the buffer out >>
    changed ->
    define _NewSS_MAX_RX_BUFF 64 // RX buffer size

    to

    define _NewSS_MAX_RX_BUFF 256// RX buffer size
    but changing that or changing Baud rates has no effect now with the new 1.0 IDE.
    (When I say that if you have the wrong baud rate you just get nonsense- meaning if I had it wrong you don’t get sense and nonsense mixed together).

    Do my question- What am I doing wrong?


  27. Nacho Mas

    12 years ago

    Hello,

    I have interferences with my code using softwareserial to read a gps. My code use timer2 isr to implement a modem.

    Modem function are critical for my application. Loosing some gps data frames are not a problem so I want to stop gps rx when modem is in use.

    ¿What is the best way to disable temporally all serialsoft interrupts and processing?

    Thank you for this great soft!

    Thank you in advance
    Nacho Mas


  28. yrame

    12 years ago

    Hi! I am working with a Gizduino with GSM module which will act as an SMS controller of appliances. The user will text ON/OFF or may inquire about the switching state of the appliance being controlled. My problems are:

    1. I don’t know how to interface AT commands with Arduino.

    2. I’m not sure if the GSM module gets the text message being sent, because when I tried to text ON, there was no output in the serial monitor.

    3. Serial.print(“AT”) – does this really make the GSM module respond? Or is it just a mere text output?

    Help me please… I wanna graduate already! T-T


  29. Mikal

    12 years ago

    @Marjan,

    I don’t have time right now to develop the necessary support for differing serial protocols, but I’m pretty sure that your proposed solution would work. There are two places in NewSoftSerial where bits are serialized either in or out. If you modify this code slightly you should be able to support 8E2 or 7N1 or whatever you like. Ultimately, it would be cool to supply a parameter on the NewSoftSerial constructor that allowed the user to specify the protocol. They are talking of doing this with the HardwareSerial port. Thanks for the feedback.

    M


  30. Mikal

    12 years ago

    David, 57.6K baud is pretty dicey for software serial. Does the unit you mention support lower baud rates? What other devices are you using that may be interfering with timing?


  31. Cenek

    12 years ago

    hello, I need “2 stop bits”, how should I change the code? thanks. f.


  32. Mikal

    12 years ago

    @Cenek, and everyone who wants a protocol other than the default N81,

    You need to modify two functions, the ones responsible for serializing the bits of a byte for TX and RX. These are, respectively, write() and recv(). In write() you look for this code:

     if (_inverse_logic)
      {
        for (byte mask = 0x01; mask; mask <<= 1)
        {
          if (b & mask) // choose bit
            tx_pin_write(LOW); // send 1
          else
            tx_pin_write(HIGH); // send 0
        
          tunedDelay(_tx_delay);
        }
    
        tx_pin_write(LOW); // restore pin to natural state
      }
      else
      {
        for (byte mask = 0x01; mask; mask <<= 1)
        {
          if (b & mask) // choose bit
            tx_pin_write(HIGH); // send 1
          else
            tx_pin_write(LOW); // send 0
        
          tunedDelay(_tx_delay);
        }
    
        tx_pin_write(HIGH); // restore pin to natural state
      }

    To add additional bits, simply set the line in the correct state using tx_pin_write(HIGH) (or LOW) and delay using tunedDelay(_tx_delay);

    On the recv() side, look for this code:

       // Wait approximately 1/2 of a bit width to "center" the sample
        tunedDelay(_rx_delay_centering);
        DebugPulse(_DEBUG_PIN2, 1);
    
        // Read each of the 8 bits
        for (uint8_t i=0x1; i; i <<= 1)
        {
          tunedDelay(_rx_delay_intrabit);
          DebugPulse(_DEBUG_PIN2, 1);
          uint8_t noti = ~i;
          if (rx_pin_read())
            d |= i;
          else // else clause added to ensure function timing is ~balanced
            d &= noti;
        }
    
        // skip the stop bit
        tunedDelay(_rx_delay_stopbit);
        DebugPulse(_DEBUG_PIN2, 1);
    
        if (_inverse_logic)
          d = ~d;
    
        // if buffer full, set the overflow flag and return
        if ((_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF != _receive_buffer_head) 
        {
          // save new data in buffer: tail points to where byte goes
          _receive_buffer[_receive_buffer_tail] = d; // save new byte
          _receive_buffer_tail = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF;
        } 
        else 
        {
    #if _DEBUG // for scope: pulse pin as overflow indictator
          DebugPulse(_DEBUG_PIN1, 1);
    #endif
          _buffer_overflow = true;
        }
      }
    

    and add another line like tunedDelay(_rx_delay_stopbit); to skip another stop bit. Make sense?


  33. Mikal

    12 years ago

    @yrame,

    I’ve never played with a GSM module. What’s the model number? I suspect that it’s a simply matter of wiring it up correctly, and yes, I would expect that Serial.print(“AT”); would generate some results. Or rather serial.print

      ln

    (“AT”); will. The latter sends the LF character after the AT, and I think that’s crucial for a modem-like device.


  34. Vladimir

    12 years ago


  35. Vladimir

    12 years ago

    Example initialization SoftwareSerial8E2 port:

    SoftwareSerial mySerial(2, 3);

    void setup()
    {

    // set the data rate for the SoftwareSerial8E2 port
    mySerial.begin(38400, 1, 2);

    }

    38400 – bound
    1 – parity bit enable (0 – parity bit disable)
    2 – two stop bit (1 – one stop bit)


  36. David (D9W)

    12 years ago

    Mikal,
    I am right now just have an I2C backpack hooked up to my Arduino from Adafruit, plus their AM2302 (wired DHT22) temperature-humidity sensor, and sparkfun’s 66 Channel LS20031 GPS 5Hz Receiver. But right now the only software I am running is for the LS20031. I am using the example code that came with the Arduino 1.0 IDE. What I am after is getting the GPS time, and once I correctly the hookup the GPS to the Arduino, it worked with the test_with_gps_device from the 1.0 IDE.

    What’s frustrating is when you had Ver 9 of the TinyGPS and the NewSoftSerial, I tweeked the NewSoftSerial buffer and got it working great with .22 IDE (when most people were having problems with it.) Same things connected to the Arduino, and I was just focusing on getting the TinyGPS code to work on the Arduino minus any other code for the other parts. I followed Sparkfun’s tutorial on the LS2031 { http://www.sparkfun.com/tutorials/176 } and used their example to make sure the Arduino could see the data stream. Now with the new Arduino 1.0 IDE, using the softSerial as I pointed out I am getting garbage part of the time, but your TinyGPS is able most of the time to pick out what it needs to show the time in the test_with_gps_device. I have played around with that code to see how the two libraries worked, and most of the time it looks like the buffer is hit and miss, but it still shows the correct time. The static_test always give a bad first line but after that it’s able to parse out the correct info in the data stream.

    I know you have said my baud rate is too fast on the LS20031, but then why was I able to get the Ver 9 to work? All I had to do was increase the buffer size to 128 in NewSoftSerial? And now not even that has an effect with the 1.0 IDE?
    One other question: With the TimeGPS library that’s floating around on the main Arduino.cc site, is that any good with the current TinyGPS? I corrected the newSoftSerial to softSerial for the 1.0 IDE, but it seems in never get’s out of setup(). Again all I am after is the time from TinyGPS.


  37. Jorge

    12 years ago

    Hi Mikal, thank you very much for your SoftwareSerial.

    I have one question, I’m using the Arduino 1.0 with low power consumption, I realize when I turnoff my serial devices (GPS&GSM) and set the atmega328 to power down the current consumption is in my case 0.3mA, but when I declare SoftwareSerial XYZ(A,B);
    and I execute the same previous steps, the current consumption goes higher, as 0,7mA. I’ve tested different scenarios and it happens always when I declare 1 or more SoftwareSerial Objects.
    Question: Do you see any reason for that?, Maybe SS is using some extra microcontroller setup that requires more energy??

    Thank you very much!

    -Jorge


  38. Mikal

    12 years ago

    @Jorge,

    Yes, when a SoftwareSerial object is activated with a valid transmit pin, the first thing the library does is bring the TX line high. This is required because a serial pin is high when in the idle state.


  39. Jorge

    12 years ago

    Thank you Mikal, I’ve set the TX and RX pin to Down, just before PowerDown mode and the consumption went back to 0.5mA. You saved me!


  40. Manash

    12 years ago

    Sir, Can I use your NewSoftSerial library in WinAVR? If yes, then what would be the syntaxformat be like?

    Thanks.
    Regards


  41. Jorge

    12 years ago

    Hi Mikal, I’m back ;-.)

    I’m facing some challenges to send SMS using the latest SoftwareSerial on Arduino 1.0.
    It’s acting very strange, some times I need to call the same code twice to send 1 SMS, other times i need to add a huge delay.
    The same code use to work fine with NewSoftSerial on Arduino 0.22/0.23.
    I’ve simple changed the old nss.println(26,BYTE) form for the new nss.write((byte)26), but it’s not working all times.
    Question:
    Do you believe this is something related to the way the new implementation works? Some waiting or sync issue? Any ideas?

    Thank you, once again!


  42. Mikal

    12 years ago

    @Manash, if you’re asking for permission, the answer is a definite “yes”. If you’re asking how it might be done, I don’t know exactly, but I suspect that it wouldn’t be too hard to port. The code itself doesn’t rely over much on Arduino particularly. Has anyone tried to port NSS to a non-Arduino environment?


  43. Mikal

    12 years ago

    @Jorge,

    Can you describe what you mean by “it’s not working at all times”? Does that mean simply that the SMS device isn’t responding like it should?


  44. Jorge

    12 years ago

    @Mikal

    What I mean is that sometimes the AT commands do not go thru, for instance, I have the same code sending SMS in 5 different devices (SM5100-B) with the old NSS and they work fine, I’ve upgraded to arduino 1.0 and I’m using the SoftwareSerial (NSS official) changed the nss.print for nss.write for byte, but sometimes the command doesn’t go thru, I had to add many AT, delays. Sometimes it sends the first, but no the next sms;
    Another example:
    I have an AT command to turnoff the GSM module, depending which command was sent to the serial before the turn off command, it doesn’t work, I have to type it twice or more.

    Below the old and new code:

    OLD:
    CELL.println(“AT+CMGF=1”); // set SMS mode to text
    CELL.print(“AT+CMGS=”); // now send message…
    CELL.print(34,BYTE); // ASCII equivalent of ”
    CELL.print(mobilenumber1);
    CELL.println(34,BYTE); // ASCII equivalent of ”
    delay(500); // give the module some thinking time
    loop to read message from file (in_char); // Read file char by char;{
    CELL.print(in_char);
    }
    CELL.print(“\x1A”);
    delay(15000);

    NEW:
    // CELL.flush(); //Attempt to make it work
    // CELL.println(“AT”); //Attempt to make it work
    // delay(500); //Attempt to make it work

    CELL.println(“AT+CMGF=1”); // set SMS mode to text
    delay(500);
    CELL.print(“AT+CMGS=”); // now send message…
    CELL.write((byte)34); // ASCII equivalent of ”
    CELL.print(mobilenumber);
    CELL.write((byte)34); // ASCII equivalent of ”
    CELL.println(“”);
    delay(500); // give the module some thinking time
    loop to read message from file (in_char); // Read file char by char;{
    CELL.print(in_char);
    }
    CELL.write((byte)26);
    CELL.println(“”);
    delay(15000);

    Thank you again.

    -Jorge

6 Trackbacks For This Post
  1. Telemetry Using Xbee Modules | Anacortes RC Sailors

    […] arduino remotely can be found here. For communication over XBee the Arduino appears to need the NewSoftSerial library. LD_AddCustomAttr("AdOpt", "1"); LD_AddCustomAttr("Origin", "other"); […]

  2. NewSoftSerial, Attachinterupt() and Pins 2,3 | Anacortes RC Sailors

    […] for attacheinterupt() are 2 and 3. The GPS shield uses digital 2 and 3 for GPS communication using NewSoftSerial. So I tried moving the GPS to other pins, 8 and 9 worked. Now pins 2 and 3 are free for my […]

  3. Telemetry Using Xbee Modules | Anacortes RC Sailors

    […] arduino remotely can be found here. For communication over XBee the Arduino appears to need the NewSoftSerial library. […]

  4. [Arduino] Lecteur RFID à écran lcd, avec stockage du tag “valide” en EEPROM externe I2C « Skyduino – Le DIY à la française

    […] Dans ce projet vous pouvez remarquer que je suis obligé d’utiliser deux port série, un à 9600 bauds pour l’écran lcd, et un autre à 2400 bauds pour le lectuer RFID. Normalement il me faudrait une mega (qui possède 3 port série) pour faire ce projet en hardware, mais il existe aussi des librairies Serial software ! C’est pourquoi je vais utiliser la librairie NewSoftSerial disponible ici : http://arduiniana.org/libraries/newsoftserial/ […]

  5. An Idiot and an Arduino: Pretty WiFly for a White Guy « ~jmoskie

    […] went through each error, and tried to resolve it myself. Some were easy. The "NewSoftSerial" libraries were incorporated into the core libraries, and they replaced the default SoftwareSerial […]

  6. Arduino vs Arduino Mega – Which To Use? | Utopia Mechanicus

    […] speed if you need a second or third (or fourth) port. On the Uno, you can do similarly using the NewSoftSerial library; however, software is slower, and if your program is pushing the limits, you may find a hardware […]

Leave a Reply