Address

Author Topic: Multiple Shields vs. Serial  (Read 1500 times)

gdemeny

  • FamiLAB Member
  • Newbie
  • *
  • Posts: 15
  • Code. Create. Repeat.
    • View Profile
    • SmartFeeder
Multiple Shields vs. Serial
« on: March 21, 2012, 12:16:53 AM »
First.

Ehem, I mean I need help with a project I'm working on which involves a WiFly shield and an ID-20 RFID Reader. I successfully set them up and tested them separately, however, they both use the serial pins of the Arduino. I was thinking, to avoid reading/writing each other's data, I could use a multiplexer like the CD74HC4067 and switch the serial periodically between the two shields. I still have reservations whether or not that works because, for example, the RFID reader starts transmitting the moment it reads a tag, even if the MUX is pointing to the WiFly shield at the moment and that could result in data corruption/loss.

So, my question is, is there a better way to use multiple shields that need Serial?
-George

digitalman2112

  • Lab Dad (ex-treasurer)
  • FamiLAB Member
  • Hero Member
  • *
  • Posts: 1096
  • Work Hard, Play Hard!
    • View Profile
    • Raising Geeks
Re: Multiple Shields vs. Serial
« Reply #1 on: March 21, 2012, 09:17:30 AM »
I don't think you have a pin conflict (but I don't have the hardware in front of me, so YMMV)


Here's why I think you are ok:


1) The shield you linked from Sparkfun, doesn't use the Arduino's serial UART directly, it has its own UART and uses SPI (on pins 10 to 13)


2) Looking at the RFID module, I believe you could poll it for data (if polling is acceptable, and it often is...) using NewSoftSerial on any digital I/O pin - leaving your actual serial UART available for debugging.  When you need to have two items that both need serial on an arduino, often you can use the NewSoftSerial library and move to any digital pins. This won't work for applications that need the UART (timing sensitive receives for example), but I've used NewSoftSerial many times without issues.

















gdemeny

  • FamiLAB Member
  • Newbie
  • *
  • Posts: 15
  • Code. Create. Repeat.
    • View Profile
    • SmartFeeder
Re: Multiple Shields vs. Serial
« Reply #2 on: March 21, 2012, 08:23:26 PM »
Both shields use the same code to read data; they initialize the port with:
Quote
  Serial.begin(9600);

and then have a loop to read the data:
Quote
  while(Serial.available())

So I'm not sure how to differentiate between them without any workaround. I will definitely check out NewSoftSerial, which is apparently included in 1.0 by default as SoftwareSerial.

Thanks a lot for the tip!
-George

gdemeny

  • FamiLAB Member
  • Newbie
  • *
  • Posts: 15
  • Code. Create. Repeat.
    • View Profile
    • SmartFeeder
Re: Multiple Shields vs. Serial
« Reply #3 on: March 21, 2012, 11:19:56 PM »
This is simply awesome! It's super easy to set up and works like a charm. Thanks again for the tip, Ian.
-George

digitalman2112

  • Lab Dad (ex-treasurer)
  • FamiLAB Member
  • Hero Member
  • *
  • Posts: 1096
  • Work Hard, Play Hard!
    • View Profile
    • Raising Geeks
Re: Multiple Shields vs. Serial
« Reply #4 on: March 22, 2012, 07:06:09 AM »
Both shields use the same code to read data; they initialize the port with:
Quote
  Serial.begin(9600);

and then have a loop to read the data:
Quote
  while(Serial.available())

Quite often this is so that you can interact with the host PC for debugging (seeing output, sending test commands, etc).

Glad it worked!