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
646 Responses → “NewSoftSerial”

  1. Mikal

    14 years ago

    Probably– at 8MHz you are somewhat capped on baud rate though. If you’re using using one of those 4800-baud GPS, I would expect it to work ok.


  2. Mikal

    14 years ago

    Jeff–

    If someone could generate the appropriate timing tables for 12MHz — I don’t have any test devices — I’m sure it would work fine. You could just do an approximation by averaging the 8 and 16MHz values.

    Mikal


  3. Obi

    14 years ago

    Hello Mikal thank you for your support with these libraries I was wondering if the Mega supported newsoftserial library have been released yet


  4. Patrick

    14 years ago

    I could use some help. I am using this for my GPS. I am trying to get the bearing and i understand that the GPS does that for you.

    // track angle
    parseptr = strchr(parseptr, ‘,’)+1;
    trackangle = parsedecimal(parseptr);

    Is the above in the code for the bearing?
    if it is, i can not get it to tell me bearing.
    It prints random numbers and sometimes some weird characters. Every other part of the code works and i have written my own distance code that works. I also wrote code for telling me bearing from my current location to a different GPS point. I would like to get my current bearing when i move but i can not get the above code to work. Any help would be appreciated.


  5. Mikal

    14 years ago

    Hi Obi–

    No, not yet. But the next version of Arduino will likely contain a version of NewSoftSerial that does support Mega.

    Thanks,

    Mikal


  6. Mikal

    14 years ago

    Patrick, are you using TinyGPS? TinyGPS does support the “course” field. Is that what you’re talking about?

    Mikal


  7. Patrick

    14 years ago

    Mikal

    I am using your newsoftserial library and the example gps code that comes with it.


  8. Patrick

    14 years ago

    Mikal

    I was able to easily switch my formulas over to the tinygps library. So i will use that one since it gives heading. Thank you.


  9. kee nethery

    14 years ago

    Not to be unappreciative but … is there any documentation? For example: it is not obvious in NewSoftSerial myGPS(3, 2); if pin 3 is TX or RX. I’m sure I can connect up to a serial LCD and figure it out but it would be nice if there was documentation.

    As a suggestion, perhaps grab all the docs associated with: http://arduino.cc/en/Reference/Serial and alter them to describe NewSoftSerial. Less work for you (or someone knowledgeable) and it would allow beginners to compare and contrast. Thanks!


  10. Joe

    14 years ago

    I am using 10c of your NewSoftSerial and see strange behaviour in my sketch.
    I can call the print method from the sketch but when it is called from a lib
    via a ptr passed in to the “translator” contructor, print does nothing. I have put this on the o-scope to verify.

    nss.print(‘X’, BYTE); // Put this in for DEBUG. It works.

    translator.sendPackerRequest();

    if (translator.waitForPacket() == true) { // The “print” in “waitForPacket()” does nothing…
    Serial.println(“DEBUG: Received Packet”);
    // Received packet, and passed checksum. Now parse it.
    //translator.parsePacket(); // Done in waitForVipecAPacket now
    //translator.translate();
    //translator.sendPacket();
    }
    else {
    //Serial.print(“.”);
    Serial.println(“DEBUG: Failed to Receive Packet”);
    }


  11. Mikal

    14 years ago

    Kee, the documentation is indeed a little weak I agree. For your specific situation the RX is always the first parameter (just like in SoftSerial).

    Mikal


  12. Mikal

    14 years ago

    Joe, without looking at the code for this “translator” object I wouldn’t be able to guess why your application doesn’t print anything.

    Mikal


  13. Spencer

    14 years ago

    I am trying to load your code into my arduino and its not working. I am new and maybe I don’t understand what to do. I have an Arduino and a gps and I am pasting your code into my version 18 of the arduino IDE and it comes up with errors. Do I need to download TinyGPS to arduino? Please help.


  14. Mikal

    14 years ago

    You didn’t say what code you are trying, but if it requires TinyGPS, then you need to install it correctly. Perhaps if you listed the first couple of error messages?…


  15. Phlogi

    14 years ago

    Hi there

    Is there any development version of this that has already support for the Arduino Mega? If not I’ll start porting it soon.


  16. pantelis

    14 years ago

    Does the new newsoftserial version (10c) makes the feedgps() function of tinyGPS not compatible or something?

    i mean:
    ////////////////////////////////////////////////
    from newsoftserial
    /////////////////////////////////////////////////
    This means that you can’t write code like this:
    void loop()
    {
    if (device1.available() > 0)
    {
    int c = device1.read();

    }

    ////////////////////////////////////
    tinyGPS
    bool feedgps()
    {
    while (nss.available())
    {
    int c = nss.read();
    if (gps.encode(c))
    {
    // process new gps info here
    }
    }
    }
    ////////////////////////////////////////////

    I’m using tinyGPS with a ping ultrasonic sensor. I didnt try to create a newsoftserial object for the sensor (yet), but it seems that it fails to work as it does, when I use it without the gps and a newsoftserial object.
    For example, I have set my vehicle to stop its motors when the sensor reads an obstacle in a distance of 70cm. Instead, the vehicle stops well below 70cm and sometimes it does not stop at all.

    here’s what I do:

    void loop()
    {
    get_gps_data();
    if (newdata)
    {
    if(sensor_readings < 70) avoid_obstacle_routine();
    forward();
    }
    }
    —————————————–
    bool feedgps()
    {
    while (nss_gps.available())
    {
    if (gps.encode(nss_gps.read()))
    return true;
    }
    return false;
    }

    void get_gps_data()
    {
    nss.begin(4800);
    unsigned long start = millis();

    // Every 1 second we print an update
    while (millis() – start < 1000)
    {
    if (feedgps()) newdata = true;
    }

    if (newdata) gpsdump(gps);
    nss_gps.end();
    } // end of get_gps_data()

    ——————————————-

    What am I doing wrong? Should I declare an nss object for my sensor? Maybe not use the nss.end() method in the end of the get_gps_data function. I’m kind of lost here :(


  17. Larry

    14 years ago

    Very impressive library! I’m just having one weird issue: I have to use the same baud rate on the NewSoftSerial instance as I do on the hardrware UART or there seem to be sync issues.

    I explain: First, I successfully H/W 4800 read, parse and H/W 4800 serial print NMEA data from a GPS module, confirming the data by looking at it in a serial monitor app. Second, I repeat this success now using NewSoftSerial, connecting the GPS to RX pin 2 and setting 4800 baud on both NewSoftSerial pin 2 and H/W UART. Third, all I change is baud to 9600 on UART and now there is a problem. The board generates correct output for a second or two, but then the data generated gets choppy and corrupted and finally ceases. It’s like it’s having trouble synchronizing the 4800 baud on pin 2 and the 9600 on the H/W. Though I know the two are really uncorrelated.

    Can you help? Does this have to do with trying to use two serial interfaces at once? Any suggested corrective action?

    Thank you!


  18. Mikal

    14 years ago

    @pantelis –

    In most cases you would never call nss.end(). There shouldn’t be any incompatibility between TinyGPS and NewSoftSerial. You should probably only call nss.begin() once at the beginning of your program.

    Mikal


  19. Wolfgang

    14 years ago

    High Mikal,

    Many Txs for the NSS!
    Unfortunately I cannot receive proper datas from my 9DOF Razor board (8Mhz) sent by the standard serial to my 2009Board (16Mhz), no matter which boud rate. The razor reports properly via the 3.3V FTDI to the serial screen on the computer. Sending datas from the razor to the 2009board (receiving with nss) and resending via standard serial to the computer does not work. If I send 1 digit with one serial.print from the razor it is ok, two digits it still receives the first one only. If I do it with two serial prints (one digit each), I can put it through to the computer.- Strange
    May I kindly ask to help?- many thanks in advance,
    b.r.
    Wolfgang


  20. pantelis

    14 years ago

    Right, after running some more tests, also using a nss object for the ping, I realised that the lib was working fine. It was actually the ping that was closing obstacles in a shallow angle and couldn’t detect them, unless it was close enough so the echo was able to reflect and return to the ping in order to take a measure.


  21. jab

    14 years ago

    Thanks for what might be the most useful Arduino library ever! But.. :)
    Recently I have started using some Teensy2.0 boards, and I have a problem with NSSv10c and receive when using high pin numbers. I have a test controlling four Sony camera modules. Cam1 on arduino pin 14&15, cam2 16&17, cam3 18&19 and cam4 on pin 20&21. Cam1 works fine both send and receive. But cam2,3&4 will only transmit and does not receive incoming data (read() == -1). I have scoped the pins and conformed there is data on all tx&rx pins, but only the NNS instance using pin 14&15 receives data. I have also made sure only one NSS instance will send and receive before moving one to the next one as stated in the using multible NSS examples.


  22. Mikal

    14 years ago

    @Wolfgang: is NSS used only for receiving on the Arduino? Or are you transmitting too? Transmitting with NSS can cause received bytes to be lost, but I wouldn’t expect transmitting with Serial to affect NSS reception. Hm…

    Mikal


  23. Wolfgang

    14 years ago

    High Mikal,

    Yes, it triggers the datas to be sent, thereafter 25 mills delay, as faster I can´t receive anything. If I want to send -179 from the razor with hardware serial to the 2009board receiving with nss, what would be the best code at what max speed?

    many thanks in advance for your help!

    b.r.
    Wolfgang


  24. Mikal

    14 years ago

    Wolfgang, I can’t immediately figure out why that doesn’t work. Perhaps if you shared your code?

    Mikal


  25. Mikal

    14 years ago

    @jab,

    Thanks for that most useful data. I haven’t played with a teensy 2.0, so I haven’t been able to verify anything, but it seems like good data. If you connect only one camera (and one NSS object to support it) to, say, pins 20 and 21, does that work in isolation? (I’m trying to figure out whether the pin mappings are wrong for high pins, or whether there is a problem with multiple objects.)

    Thanks!

    Mikal


  26. Wolfgang

    14 years ago

    Dear Mikal,

    this send the datas from the razor at 38400 baud, rolli is type int and is defined in main page. If connected to the comp directly, datas are received in perfect order.

    void printdata(void)
    {
    rolli= int(ToDeg(roll)+180);
    if (Serial.available()) {
    Serial.read();
    Serial.print ((rolli));
    }
    }

    This receives the data from the razor and send to serial window of Arduino 0018:

    #include
    NewSoftSerial Gyro(4,5);
    byte roll=0;

    void setup() {
    Gyro.begin(38400);
    delay(100);
    Gyro.flush();
    Serial.begin(57600);
    delay(100);
    }

    void loop() {

    Gyro.print(1);
    delay(30);
    if (Gyro.available()) {
    delay(25);
    Serial.println(Gyro.read(),BYTE);
    }

    Gyro.flush();
    Serial.flush();
    }

    If I add more Serial.print(Gyro.read(),BYTE), I receive more bytes (amount how many digits are sent), which are not correct ASCII characters. If there are no more bytes, I receive -1.

    many thanks again,
    b.r.
    Wolfgang


  27. jab

    14 years ago

    @Mikal: It is most likely a pin mapping/interrupt related problem. I can swap pins on any of the four NSS instances controlling cameras, and the one using pins 14&15 start working both ways. While the others will only transmit.


  28. jab

    14 years ago

    @Mikal: Sorry, forgot to answer you specific question about a single NSS on high pins. I left the project at work, so I will test that first thing tomorrow morning.


  29. jab

    14 years ago

    @Mikal: I have just confirmed that a single NSS object on pin 20&21 does not work with the Teensy 2.0, so the problem is most likely not related to using multiple objects.


  30. jab

    14 years ago

    @Mikal: After some more testing, it would seem that NSS receive on the Teensy 2.0 will only work if PORTB (PCINT) pins are used as RX pins.


  31. JLux on Arduino

    14 years ago

    But supposing I need send to this command to Arduino:

    Print #4 , Chr(&H80) ; Chr(&Ha4) ; Chr(&H30) ; Chr(&H02) ; Chr(&H09);

    (this command is a command to be send to a fingerprintsensor)

    How can I accomplish that task with NewSoftSerial ??

    JLux


  32. Mikal

    14 years ago

    See email JLux…

    Mikal


  33. aka ged

    14 years ago

    Hi Mikal,
    I really like the idea of what you’re doing with NewSoftSerial, but
    I’m having trouble compiling it into a sketch for my Serial graphicl LCD 128×64.
    Using Arduino-0018 with a duemillanove 328p.
    OpSys:Win2000 Pro SP4. Have the used run.bat to sort the java PATH.
    The NewSoftserial directory is in my sketch folder.
    Getting these compile errors:-

    27: error: NewSoftSerial.h: No such file or directory In function ‘void setup()’:
    In function ‘void loop()’:
    Bad error line: -2

    Now, I have been a programmer in days gone by, is the any other way to direct the compiler to non-standard libraries ? Or, am I missing something really basic?? :-(

    tia aka ged


  34. Eric

    14 years ago

    @Mikal
    I’m having some issues using your library with my Parallax RFID reader.
    I have outlined the issue on the Arduino forums here http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1273612596/0
    If you have any insight on what might be wrong it would be greatly appreciated.

    Thanks


  35. Mikal

    14 years ago

    @aka ged–

    You don’t put libraries in your sketch folder; they need to go whereever the built-in libraries are. In Windows this is in the hardware\libraries folder underneath Program Files.

    Mikal


  36. Mikal

    14 years ago

    Hi Eric–

    See my response on the forum. You need to check rfid.available() before trying to read bytes.

    Mikal


  37. Darin

    14 years ago

    Mikal:

    Isn’t you “object.available()” caveat in “Using Multiple Instances” violated in you TwoNSSTest.pde example?

    Thanks.


  38. Fred

    14 years ago

    Hey Mikal,

    Great work with this library !!

    But I have a little trouble using it … I saw in other forum that the delay function can have trouble while using the librarie, so I try to avoid this problem (Ì really need delay in my application) by openning and closing the serial connection each time I need it. But I can’t figure why, but my program seems to be block when I call the begin function (in the loop place for example) …
    Can you help me figure what’s the problem ??
    A little response would be really appreciated, and if you really need it I can send you a sample code…

    Thank you very much !!!

    Fred


  39. Fred

    14 years ago

    Oups just a modification for my previous post, I’m using the serial to communicate between two arduino (or more) with simple RF component…

    And the begin does not fully block, it seems to stay on the begin function for a random time, or perhaps the time to the RF receiver to get any signal on its pin …

    Just for you to know, I’m trying to build an simple architecture with one arduino for the server role, and many other arduinos in emitters role, and each emitter arduino send data to the server arduino.
    So I need to use both hardware serial to send data, because with this one the end() method really disable the pins allowing me to send data with an other arduino (two RF transciever cannot be active in the same time), and then newsoftwareserial to do the listen task, because I need to know if an other arduino is sending data in order to know if can emit something…

    I really need help on this, I’m not an electronik an arduino specialist !!!

    Thank you anyway for your great work !!


  40. Mikal

    14 years ago

    @Darin,

    Perhaps I could have been a bit more clear in describing the hazards of multiple instances, but the main point is this: the first call of object.available() on an inactive NSS instance always returns 0. The function simply activates the instance and returns without waiting for any data to show up. This architecture works reasonably well except in the case where you write code that repeatedly checks available() first on one instance and then another. Each will never do anything but return 0. You must

    The sample code in TwoNSSTest.pde is a little different. It calls available() many, many times on each instance — continuously for 10 seconds — before switching to the other instance. This makes all the difference.

    In the real world, you probably would use time to decide to switch to a new device. You’d probably wait for a specific message or condition.

    Does that help?

    Mikal


  41. Mikal

    14 years ago

    @Fred,

    Delay is only a problem with NewSoftSerial in the sense that you run the risk of overrunning your receive buffer. You won’t solve that by calling begin and end repeatedly. Don’t do it! :) And if you do worry whether you’ve lost data, you can always check object.overflow(). Does that help?

    Mikal


  42. Fred

    14 years ago

    Hi Mikal,

    I’m going to have a look at the overflow() function to see if it can help me. But if I don’t open and close the connection when I need to use the serials functions, like if I start the serial function only in the setup, then when I use the delay() function somewhere in my code, the delay seems to be really untrustable… (1000ms in the code looks like 5000ms in the reality !!)
    Do you think there’s a way to avoid this kind of trouble ??
    Perhap’s by disabling the interuption while I’m not using it, but I’m not sure how to realize this (maybe I remember I see a function for that…) ?


  43. Darin

    14 years ago

    Thanks, Mikal.
    If I do want to repeatedly cycle between multiple instances, would you recommend 2 consecutive calls to object.available()…the first to “activate” the instance, and the second to do the work…or is there a more elegant approach? Just curious: Why did you choose not to automatically “activate” an inactive instance that is being referenced? Efficiency? I am, after all, making a conscious attempt to use the instance.

    Regards.


  44. Mikal

    13 years ago

    @Darin,

    Yes, checking twice is what I recommend, but that’s usually what happens because in nearly every application, NewSoftSerial::available is called repeatedly in a loop and not just once.

    I think I have concluded that it would have been a better architecture to require the user to explicitly activate the instance. When NewSoftSerial gets folded into the Arduino kernel in the next few weeks, I think it will have this explicit activation feature.

    Mikal


  45. Mikal

    13 years ago

    Fred,

    I don’t think there is anything wrong with delay(). And before you substitute repeated begin/end calls, keep in mind that you were not having success there either. I suspect that there is something else going on in your code that is causing problems. I recommend incrementally simplifying your structure until you isolate the problem.

    Mikal


  46. Fred

    13 years ago

    Hi,
    I manage to isolate the part that was causing problem in my program. There’s two weird things, the first one is the begin method, I don’t know why but she take time to pass if there’s no data on the RF receiver … the second one still the delay that are not acurate when the serial is activated …

    I found a solution to my problem by modifiying the HardwareSerial librairie, I manage to create differents methods like endTX() or endRX() for the serial, in order to allow me to use them like I want…

    Thank you anyway for your help, really appreciate it … But If you manage to identify the problems I was talking about don’t hesitate to contact me !!!

    Bye !!


  47. Chibi

    13 years ago

    I have been having issues with incorrect read data. It is consistently corrupted. I am running at 115,200 BAUD. I have not had any problems sending data, but I keep getting -32640 when I should be getting zero. I am really confused because 0 is always 0 in all binary number systems. I was wondering if I was having an issue with the timing on the stop bit or perhaps my BAUD rate is too fast.


  48. Guz

    13 years ago

    @Wolfgang

    Hi, I try to connect the 9DOF to Arduino 2009 too.
    I try to power supply it with the external connector because I read that it needs 70mA and Arduino 3.3V is limited to 50mA.

    I use your code and I receive caracters but it is scrambled.

    I don’t succeded in receiving good caracters.

    Do you get that ?

    Regards.


  49. Mikal

    13 years ago

    chibi — there most definitely is a timing issue. The Arduino process just isn’t precise and fast enough to do 115.2K baud RX reliably.

    Mikal


  50. Mikal

    13 years ago

    @Guz–

    Do you have the grounds connected together?

    Mikal

93 Trackbacks For This Post
  1. NewSoftSerial 5 « Arduino

    [...] NewSoftSerial version 5 is available. A lot of people have been using this library — thanks! — but I really need to recognize the exceptional work of two contributors. [...]

  2. NewSoftSerial 6 « Arduiniana

    [...] I posted the new library. [...]

  3. เริ่มต้นสร้าง GPS จอสีกับอาดูอี้โน่ | Ayarafun Factory

    [...] ในรอบนี้ผมได้ใช้ newSoftwareSerial3 จะได้ลองด้วยว่า มีปัญหาไหม

  4. Unlogic » USB Storage and Arduino

    [...] of the first things to do is download NewSoftSerial

  5. The Hired Gun » GPS project: the Bluetooth saga

    [...] to the task at hand, which happened to be adding 3 lines of code: declaration of an instance of NewSoftSerial, calling the instance constructor with a baud rate, and a single call to pass the char from the [...]

  6. layer8 » Controlling A Roomba with an Arduino

    [...] and the XBee module has a serial interface.  So how does this really solve my problem?  Enter NewSoftSerial, an updated version of the Arduino software serial library, which basically lets you drive a serial [...]

  7. This and That » Blog Archive » Arduiniana - What else would it be?

    [...] is probably the coolest gift idea I’ve seen.  Mikal, you rock.  And also, thank you for NewSoftSerial.  [...]

  8. Interfacing the Arduino with the DS1616

    [...] way.  Let’s move onto the software.  Communication with the DS1616 is established using the NewSoftSerial library.  Getting data is essentially a case of lots of bit banging.  The DS1616 library [...]

  9. Serial Multiplexing « Interactive Environments Minor 2009-2010

    [...] So we started looking for a solution to overcome this tiny inconvenience. First we looked into a software serial but this didn’t work out, it was a bit too much for the arduino’s little processor to [...]

  10. Atmega/Arduino (Soft-) Serial Ports | Jochen Toppe's Blog

    [...] software serial port. I briefly thought about writing one, but then I found this great libary, the New SoftSerial. It is as simple to use as the original library, but unfortunately once I connect the RF receiver, [...]

  11. The Frustromantic Box, Part 4: Software « New Bright Idea

    [...] developers for the great libraries, and to Mikal Hart in particular for his work on the TinyGPS and NewSoftSerial [...]

  12. side2 » Bimeji Client for Arduino

    [...] このソースでは、PS2ライブラリとNewSoftSerialライブラリを利用しています。 コンパイルするには、これらのライブラリを有効にしておく必要があります。 [...]

  13. Live Twitter Table using New Bluetooth Shield | Club45

    [...] as a well. The shield can be wired to any of the pins on the Arduino. Right now we’re using NewSoftSerial on pins 4 and 5. It can be attached to the hardware RX and TX pins, but interferes with [...]

  14. tokyo->kobe->osaka << Motoi Ishibashi

    [...] 急遽、Arduinoでシリアル通信をふたつやる必要が発生してホテルで開発。といっても手元にハードがないので、ほとんど勘でプログラムしているようなもの。 次の日現場で試すも、予想通り動かない。そりゃそうだ。 NewSoftwareSerialなんていう便利なものがあるのを後で知った。 [...]

  15. VDIP1 USB Host Controller « Arduino Fun

    [...] chose the NewSoftSerial library to give access to the VDIP1.  The first attempt was to use the AFSoftLibrary and it just [...]

  16. Project Lab

    [...] software running on the Arduino ATMEGA328 chip utilizes the wonderfully robust NewSoftSerial library for communicating with the EM-406a GPS module and the very convenient TinyGPS library for [...]

  17. Box Round 2 « Stromberg Labs

    [...] is available here. I borrowed from a couple of people’s Arduino libraries to get this done, notably NewSoftSerial from Arduiniana and the GPS Parsing code from the Arduino website for parsing the NMEA strings. [...]

  18. Grok Think » Blog Archive » I got Arduino sending temp to the computer using xbee wireless.

    [...] I had to use this library to communicate with the xbee from the arduino:  http://arduiniana.org/libraries/newsoftserial/ [...]

  19. GPS – Welcher Chip? | Ranzow im Umbau

    [...] wird über die Serielle Schnittstelle angesteuert. Die werde ich wahrscheinlich über die NewSoftSerial Library [...]

  20. GPS – Welcher Chip? | Ranzow im Umbau

    [...] GPS Modul wird über die Serielle Schnittstelle angesteuert. Die werde ich wahrscheinlich über die NewSoftSerial Library [...]

  21. Cititor RFID 125KHz « Tehnorama

    [...] metoda de a afla codul cartelei este de a utiliza biblioteca NewSoftSerial, disponibila gratuit aici. Fisierul zip se dezarhiveaza si se copiaza in folderul libraries al distributiei [...]

  22. Lightweight software UART -> custom serial « Robotics / Electronics / Physical Computing

    [...] updated the NewSoftSerial library from Arduiniana (thanks Mikal !) so that it takes 2 extra [...]

  23. Control Camera with Arduino | SenSorApp

    [...] http://arduiniana.org/libraries/newsoftserial/ [...]

  24. GPS testing with LCD Character Display

    [...] the TinyGPS library from Arduiniana downloaded and installed for it to work. They suggest using NewSoftSerial, but I couldn’t get that to work, so I scrapped that portion. Here’s my [...]

  25. #Rallylog Fusebits

    [...] it as a fail and moved on, however last night when I set about writing the RFID read function using NewSoftSerial on the RFID I was getting nothing reported back back on the AVR, not a thing coming back from the [...]

  26. 433 MHz receiver and NewSoftSerial at mitat.tuu.fi

    [...] http://arduiniana.org/libraries/newsoftserial/ http://www.sparkfun.com/commerce/product_info.php?products_id=8950 [...]

  27. Moving Forward with Arduino – Chapter 17 – GPS « t r o n i x s t u f f

    [...] devices. At this point you will need to install two libraries into the Arduino software – NewSoftSerial and TinyGPS. Extract the folders into the libraries folder within your arduino-001x [...]

  28. Moving Forward with Arduino – Chapter 17 – GPS « Hey it’s my blog…

    [...] this point you will need to install two libraries into the Arduino software – NewSoftSerial and TinyGPS. Extract the folders into the librariesfolder within [...]

  29. Sonar | Starter Kit

    [...] there is one more library – “NewSoftSerial”, which is free of these defects and, in addidion, handles inverted serial [...]

  30. Advanced RFID with Arduino and Python! | App Delegate Inc

    [...] NewSoftSerial [...]

  31. RFID Door Opener – Update 3 – LCD Woes - Sommineer

    [...] one on some other pins.  Per the suggestion of some people on the Arduino forums, I decided to use NewSoftSerial to do the communication.  Being interrupt driven, it was much more efficient than the older [...]

  32. keyHelper final project

    [...] the code you will need a very useful NewSoftSerial library, that, among other things, allows you to assign TX and RX on other pins then 0 and 1 and that way [...]

  33. Step-by-Step Guide on using the Bluetooth Bee, Bees Shield & Arduino to communicate via bluetooth | Michael Chuah

    [...] up would be to try and use the awesome NewSoftSerial library by Mikal Hart to communicate with the Bluetooth Bee by emulating the UART [...]

  34. Tutorial: Arduino and GSM Cellular – Part One « t r o n i x s t u f f

    [...] a software perspective we will need the NewSoftSerial Arduino library, so please download and install that before moving [...]

  35. Interfacing Arduino to GSM shield | Embedded projects from around the web

    [...] goes step by step how to connect Cellular shield to Arduino mega and communicate to it by using newsoftserial Arduino library. Whole process steps are monitored in terminal window, so it is easy to follow [...]

  36. Fully functional Arduino GPS logger « Liudr's Blog

    [...] NewSoftSerial library [...]

  37. LCD117 Controller Library - Jack Kern

    [...] also need the NewSoftSerial library installed in your Arduino sketchbook’s library [...]

  38. Touch game for the offspring | NinjaTool inc.

    [...] GLCD that I bought (without knowing ANYTHING about it beforehand I might add). The code uses the NewSoftSerial library which apparently does wonders, but as of yet has not been validated as the code assumes a 9V [...]

  39. Arduino GSM and GPRS shield | Open Electronics

    [...] the pin 4 and 5 there aren’t problems to upload the sketch but the maximum baudrate for NewSoftSerial (the serial library) is 57600. We performed a GSM library to controll easly the module. The GSM [...]

  40. Moving Forward with Arduino – Chapter 19 – GPS part II « t r o n i x s t u f f

    [...] forget the 10k ohm pull-down resistor). You will need to install the SdFAT library, NewSoftSerial library, TinyGPS library and the SdFat library if not already [...]

  41. Blog What I Made » YAHMS: Base Station

    [...] of just the standard Serial interface, see the links below for that too. You’ll also need NewSoftSerial of course and the Flash library which I’ve used to decrease memory usage. Follow the [...]

  42. Infovore » Nikon D-Series Intervalometer

    [...] a single wire, which again, keeps the number of wires from the Arduino down. I’m using the NewSoftSerial library to talk to it, which makes life [...]

  43. Arduino Experiments

    [...] you can use multiple serial “ports”, that are actually digital I/O lines, by using the NewSoftSerial library. This works exactly like the Serial library, but you can read from multiple pins, as long as you [...]

  44. EasyTransfer Arduino Library « The Mind of Bill Porter

    [...] it’s easier to pick which Serial port to use; Serial, Serial1, etc. AND support for the NewSoftSerial library for creating software serial ports on any pin. Inside the download zip file are two versions of the [...]

  45. Research: RFID, XBee and Arduino « Beyond the keyboard

    [...] neat thing is the NewSoftSerial library for Adruino, allowing you to turn any set of pins into additional RX/TX pins with free to set baud [...]

  46. jomuoru weblog » Blog Archive » Esto es Camus Party

    [...] de instalar la librería NewSoftSerial pude compilar e instalar el Arduino Firmware en mi placa. A continuación necesitaba descargarme [...]

  47. Update: Design review « Appiphania

    [...] a bit of this code at the end of this journal entry. The “NewSoftSerial” library http://arduiniana.org/libraries/newsoftserial/ was extremely easy to get working (code example [...]

  48. Anonymous

    [...] Modul per Software-UART? Bitte einen Link oder Hinweis wo ich nachlesen kann. danke Schaust du hier __________________ FHZ1300 | 2x JeeLink | AVR-NETIO | FS20 | 1-Wire | 2x XBEE Pro | 4x XBEE 2.5 [...]

  49. Using A Second (Software) Serial USB To Debug Your Arduino | Utopia Mechanicus

    [...] actually really easy, using some code called NewSoftSerial (available from this site, at the ‘Download’ subheading). This software is much like your Serial device you use on the Arduino, but it’s in software [...]

  50. Kemper LED / Arduino Interface » Powerhouse Electronics

    [...] provided by the software library “NewSoftSerial”. The library can be downloaded from:: http://arduiniana.org/libraries/NewSoftSerial/. Since the communications port is created using software any of the Arduino port pins can be used. [...]

  51. Android talks to Arduino | ★ Elmindo Blog ★

    [...] NewSoftSerial library from Mikal Hart: http://arduiniana.org/libraries/newsoftserial/ [...]

  52. Utilizando a Bees Shield em uma Arduino Mega « A arte do hardware

    [...] via jumper na própria shield. Para comunicação com essa Bee, é necessário o uso da biblioteca NewSoftwareSerial, permitindo fazer que dois pinos digitais se tornem mais uma [...]

  53. Arduino camera and geotagger | jarv.org

    [...] NewSoftSerial lib was used for communicating over serial using an IO [...]

  54. Bluetooth + Arduino + Android – 1 : Transmettre des données d’un capteur branché sur une carte Arduino vers un Smartphone Android via bluetooth

    [...] 1– télécharger la bib­lio­thèque New­Soft­Se­r­ial pour Arduino NewSoftSerial10c.zip. Des expli­ca­tions et exem­ples plus détail­lés con­cer­nant cette bib­lio­thèque sur cette page (http://arduiniana.org/libraries/newsoftserial/). [...]

  55. Arduino + fon + OpenWRT + ser2net + NewSoftSerial « sea side she side

    [...] そのためソフトウェアシリアルを再現させたライブラリがありますのでそれを利用します。とはいっても標準ライブラリのSoftwareSerialは利用しません。高機能で速度もでるようになったNewSoftSerialを利用します。 [...]

  56. David C. Dean Arduino GPS – On the Cheap

    [...] NewSoftSerial Library - http://arduiniana.org/libraries/NewSoftSerial/ [...]

  57. 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"); [...]

  58. 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 [...]

  59. 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. [...]

  60. [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/ [...]

  61. 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 [...]

  62. 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 [...]

  63. I can solder! 7-Segment Serial Display & Nunchucky operational « I Am Chris Nolan.ca

    [...] already.  I found this wall of text which I managed to digest down into this gist (and updated it thanks to these notes) which you can see running in the above [...]

  64. S2 » Android + Bluetooth + Arduino

    [...] そして、シリアル通信のテストに利用したArduinoのソースです。 NewSoftSerial(Arduinoライブラリ)を利用しています。 [...]

  65. Getting started with DroneCell and Arduino.

    [...] DroneCell and the GPS simultaneously. I stumbled upon this interesting behavior in NewSoftSerial. NewSoftSerial*|*Arduiniana. I seem to at least have something to go on… Using Multiple Instances There has been [...]

  66. Emular pines Serial de Arduino con la librería NewSoftSerial » Blog Archive » el blog de giltesa

    [...] eso es lo que es capaz de hacer la librería NewSoftSerial (más documentación aquí). Usándola podremos emplear el resto de pines como puertos serial, ya [...]

  67. Time - He's waiting in the wings - Cuyahoga

    [...] in the download is TimeGPS.pde, but it’s a touch outdated now that Mikal Hart’s NewSoftSerial library has been rolled up into the core (since 1.0) and renamed SoftwareSerial. The problem I had [...]

  68. Arduino的通讯扩展板介绍 | 爱板网

    [...] GPS模块与Arduino的通讯程序 [...]

  69. Giving Arduino a second UART over I2C by stacking another Arduino on top « CyclicRedundancy

    [...] tried using the SoftSerial (or the NewSoftSerial) library but ran into data corruptions even at the low speeds, so I decided to look for ways to get another [...]

  70. RFID Reader #1 « Tesla UIs

    [...] the example code. There some issues on the Arduino library SoftwareSerial, which changed to the NewSoftSerial once in a while. Share this:TwitterFacebookLike this:LikeBe the first to like this. Categories [...]

  71. Resources for the VCNL4000 IR Proximity Sensor | Sciencearium

    [...] - http://arduiniana.org/libraries/NewSoftSerial/ Share this: This entry was posted in AT Physics Class and tagged arduino, IR, proximity [...]

  72. Serial LCD do-it-yourself(DIY) kit | BUILD CIRCUIT

    [...] NewSoftSerial Library - Required for the example sketches. Sets up a second (third, fourth,…) serial port on the Arduino. [...]

  73. How to assemble serial LCD kit | BUILD CIRCUIT

    [...] NewSoftSerial Library - Required for the example sketches. Sets up a second (third, fourth,…) serial port on the Arduino. [...]

  74. Android talks to Arduino board - Arduino for ProjectsArduino for Projects

    [...] from this project (bluetooth_chat_LCD.pde attached below) – NewSoftSerial library from Mikal Hart: http://arduiniana.org/libraries/newsoftserial/ – Eclipse – Android Development Kit (explicitly follow all of Google’s installation [...]

  75. Burn Arduino Bootloader on an ATtiny45 for SoftwareSerial | No bread? Make it!

    [...] http://arduiniana.org/libraries/newsoftserial/ いいね:いいね 読み込み中… カテゴリー Arduino, [...]

  76. Burn Arduino Bootloader on an ATtiny for SoftwareSerial | No bread? Make it!

    [...] http://arduiniana.org/libraries/newsoftserial/ いいね:いいね 読み込み中… カテゴリー Arduino, [...]

  77. Please wait your turn! Stratoballoon GPS Sensor Sketch « Mark Gilbert's Blog

    [...] to the GPS receiver, I’d be writing to the data logger serially.  I found information here about running multiple devices serially – the short answer is that you have to access the serial [...]

  78. Going to Arduino from C#, Java, … string trouble | Hydroinformatix the Gaul

    [...] kB). I used this method and solved my intermitting (and making me crazy…) problems 2) Using PString library, added by NewSoftSerial and put in official version of Arduino. It is very handy: it hands you a [...]

  79. The Frustromantic Box, Part 4: Software | New Bright Idea

    [...] developers for the great libraries, and to Mikal Hart in particular for his work on the TinyGPS and NewSoftSerial [...]

  80. Le Dan-TECH » 2ème Partie : Reconnaissance vocale avec Arduino

    [...] , les ports 12 & 13 de l’arduino sont utilisés (liaison arduino-module via la classe newSoftSerial) et ne permettent pas l’emploi du shield Ethernet sur une platine « arduino [...]

  81. on the trail of the elusive Power Cost Monitor signal | We Saw a Chicken …

    [...] I rewrote the logger to use the Arduino’s internal UART, since — lovely though NewSoftSerial may be — it causes millis() to report wildly inaccurate times at low bit rates. I recorded a [...]

  82. 86duino

    [...] require that protocol. The version of SoftwareSerial included in 1.0 and later is based on the NewSoftSerial library by Mikal [...]

  83. 86duino

    [...] This requires the TinyGPS and NewSoftSerial libraries from Mikal Hart: http://arduiniana.org/libraries/TinyGPS and http://arduiniana.org/libraries/newsoftserial/ [...]

  84. Kerry D. Wong » Blog Archive » RF Data Link Using Si4021 And Si4311

    [...] BT1 pin settings (which are done in hardware), the receiver is totally configuration free. I used NewSoftSerial library in the code below. The main loop simply print out the incoming bit stream. You may also use [...]

  85. how to set up arduino + pololu mini maestro (for an 18 servo hexapod) | orange narwhals

    [...] newsoftserial should be downloaded from the internet and the folder inside the zip put in (path to where you [...]

  86. Starter Kit Sonar » Starter Kit

    [...] szczęście jest jeszcze jedna biblioteka „NewSoftSerial”, która jest pozbawiona tych wad i na dodatek obsługuje zanegowany sygnał [...]

  87. Twitter Poem Box -Use Arduino for Projects

    [...] Download the TrueRandom http://code.google.com/p/tinkerit/wiki/TrueRandom, NewSoftSerial http://arduiniana.org/libraries/newsoftserial/, and Twitter [...]

  88. Подключение GPS L30 модуля используя GPS Шилд от SparkFun » Arduino Market

    [...] NewSoftSerial [...]

  89. Tema 5 – Proyectos Arduino | Aprendiendo Arduino

    [...] NewSoftwareSerial: http://arduiniana.org/libraries/newsoftserial/ [...]

  90. Twitter Poem Box -Arduino for Projects

    [...] Download the TrueRandom http://code.google.com/p/tinkerit/wiki/TrueRandom, NewSoftSerial http://arduiniana.org/libraries/newsoftserial/, and Twitter [...]

  91. 아두이노의 통신 방법, 핀 정리 (Serial, UART, Software Serial, SPI, I2C) | Hard Copy Arduino

    [...] NewSoftSerial (Arduino IDE 1.0 이후 버전만 지원) – Serial 모듈별로 인스턴스를 생성해서 여러개를 사용할 수 있지만 한번에 하나의 인스턴스만 전송/수신 할 수 있습니다. 다른 라이브러리와의 충돌 가능성도 약간 있는 듯 합니다. http://arduiniana.org/libraries/newsoftserial/ [...]

  92. Please wait your turn! Stratoballoon GPS Sensor Sketch « Mark Gilbert's Blog

    [...] to the GPS receiver, I’d be writing to the data logger serially.  I found information here about running multiple devices serially – the short answer is that you have to access the serial [...]

  93. RFID cat door using Arduino -Use Arduino for Projects

    [...] This project consists of several ‘modules’ that you need to hook up to the Arduino and test in advance. First hook-up the RF reader. You can use the 5v output of the Arduino to power it, and a digital port (I used 2) to get the signal. The RDM630 that I used also has pins for a led that I don’t use. It also has an RX pin to send info back to the RF reader, but I don’t use that either. Hook-up your antenna, get a tag and use the serial monitor of the Arduino to see if it’s detected. Now you can also start working on improving the antenna by trying adding or removing turns, trying different shapes et cetera. Power the Adruino with the 9v power supply, not just USB because at least in my case that didn’t work. You can download the file named ‘rfid3.pde’ to test. The code requires NewSoftSerial.h which can be obtained here [...]

Leave a Reply