SoftwareSerial + Photon Questions

I have a Photon and I need to read Serial Data at 9600 Baud that is being sent out every second by two different devices.

I know the Photon had the Hardware Serial UART port I can use and it has the 2nd Serial UART port that can be used if you want to disable the RGB status LED on the Photon which I would rather not do.

So this leads me to use the SoftwareSerial library which I have never used in the past to my knowledge.

Would it be best for me to use the Photon’s TX and RX pins for one device and just use the Software Serial Port for the other device? Not sure if dual SoftwareSerial Ports would be better somehow?

Can the Photon read incoming data on both Serial ports at the same time or should I just read one port for a few seconds and then switch to reading the other port only so I’m only reading one serial port at a time? Seems like this would be a better approach but I wanted to ask.

I’m basically parsing the incoming status info and saving that status info into variables. It’s OK if only pull data every couple seconds and miss a few readings while switching back and forth between devices.

Is SoftwareSerial pretty reliable at 9600 Baud, I assume so considering it’s one of the slowest speeds but just looking for potential issues from more experienced users instead of running into them later?

Any info is appreciated!

@RWB, first off, you are best to use the Serial1 hardware UART pins in combination with ParticleSoftSerial on any combination of pins you want. This library uses SparkIntervalTimer and interrupts to receive and send serial data at the bit level. It will do 9600 baud very reliably.

I suggest you create a non-blocking loop() where you can sample each of the serial ports sequentially, grabbing data and decoding “on-the-fly” much like tinyGPS does for NMEA strings (read FSM). The Photon’s Serial1 has a 64 byte circular buffer for receiving data and I believe so does ParticleSoftSerial (cause @ScruffR does things right!). So as long as you don’t allow these to overflow (ie, lose data), you won’t have any problems. Or, if the data is nicely structured and there is a “start” character, then you can sample anytime and wait for the “start” byte before starting your decoding FSM.

1 Like

All good to hear.

I will also be using the NCD Ethernet Shield to provide a Local Device Server so other devices can connect over Ethernet and request current variable data stored in variables that we update as we read data over the two Serial UART ports.

Will be using this recommended library:

A library on Particle called NCD_Ethernet_Overlay. It’s just a port of WizNet’s W5500 Arduino library really. For your application you would probably want to create a TCP Server(See this example):
https://build.particle.io/libs/NCD_Ethernet_Overlay/1.0.0/tab/example/TCP_Server.ino1

Other devices can connect to that server and request data from the Photon in that way.

Any issues you can see trying to use this library along with the SoftwareSerial Library?

@RWB, there shouldn’t be but testing is always a good idea!

2 Likes

Just wanted to say that the Software Serial running at 19,200 & the RX port on the Photon are both running at the same time and data is being parsed from both ports just fine :slight_smile:

First time I have attempted reading dual serial ports at the same time, so I 'm glad it just worked as desired.