2 serial ports on 328 ( again ).

I have been searching the many posts about 2 serial ports on a 328 chip, and most replies point me to using a mega chip, but I have painted myself into a corner price wise with this project, and am getting rather confused.

I have a prototype display board, that can be updated by a wireless remote using virtualwire. That is working fine.

Now I want to add a GSM update facility, which I have working separately with a SIM900 module on an arduino , using SoftwareSerial on pins 10, and 11 ( without having the virtualwire system running )

I know I might have to change from pin 10 as virtualwire is using pins 9 and 10 timer ?

But now I want to use an infrared instead of rf remote control, using the IRremote library. ( I would have to have the RF link approved which would be a nightmare )

As the IR is only using the RX part of the serial, can I use physical pin 2 ( DIO0, Rx ) to input the data?

Presumably it will buffer any data, and I can check it every loop with a SerialRead ?

But what happens if I connect my FTDI lead to reprogram it, once written to the chip, would it take the first data from the USB as an IR command, and go off on a tangent ?

Or should I try using two SoftwareSerial ports, and switch between them ? Would they each have a separate buffer ?

I don't want to waste a lot of time if there is preferred way to do it.

Your Post is a bit confusing. Have I interpreted it correctly ?

  • You want to add SoftwareSerial to an existing program so that you can connect a GSM module.
  • You also want to use a serial Rx to receive data from an IR remote?

First thing - two instances of SoftwareSerial probably will NOT work.

If your program does not normally use HardwareSerial you could use it to receive the IR data. However you may need to physically disconnect the IR receiver from the Rx pin if you want to upload new code.

There is no risk of your code for receiving the IR data becoming confused with the program-upload data. Your code will not be running at that stage in the process (assuming you are using the normal Arduino bootloader).

It is possible that my Yet Another Software Serial will work alongside SoftwareSerial - but I have not tried that.

...R

Thanks Robin, I did see a lot of your posts while searching this morning, and yes, that is what I need to do.

I will try hooking up an IR receiver to the Rx pin, and see what happens.

I havn't had a good look at the IRremote library yet, but will do now

An IR receiver is almost never an Async Serial (UART) device. It does not need a UART port (Serial or SoftwareSerial). It should be able to use any data pin.

If you switch to a Leonardo you can use Serial1 for a device without interfering with Serial used for PC communication and upload.

Thanks John
I have embedded hundreds of 328s but have no experience of the later chips I am embarrassed to say ( if it aint broke ---- )

"It does not need a UART port (Serial or SoftwareSerial). It should be able to use any data pin."
But how do I read the data coming in ?

Boffin1:
But how do I read the data coming in ?

You need to provide a link to the datasheet for the IR receiver you plan to use.

I had assumed (based on your original question) that it produces a serial output. @johnwasser thinks it may not.

...R

I think, IIFC, IR receiver, with an IR demodulator 3-pin IC, is just getting bit-banged into 328. Your particular IR library may be using a timer, which will break SoftwareSerial. If your IR library is using pin-change-interrupt, on the same IO port, it may also break SoftwareSerial, since it is ALSO using that.

Give us link to the said IR library source code already (Is it Shirriff's library?).

I take it back! The SoftwareSerial uses no timers at all, all "smart" delays that's all. Shirriff's IR library uses no PCINTs, just raw timed read of the input pin at 50ms intervals. That makes it easy. Use any pins on one IO port for SoftwareSerial and use a single pin on a different IO port for IR receive.

Say, you can use analog pins for SoftwareSerial port and any digital-only pin for IR remote.

Jump up to a smaller uC - 1284P, little more than 328P, but like $10 less than a Mega2560. 2 hardware serial, and use software serial for a slower 3rd port if needed (or not, for IR receiving).
DIP too for easy prototyping.