Arduino Mega 2560 and ThingShield = no upload?

[I sent this into support as well - but posting here to hope the greater community can help]

I am having an issue with my Arduino Mega and my ThingShield. I have both the UNO and the Mega 2560. The ThingShield works fine with the UNO - I am able to load and run all of the examples just fine. For my project I need to communicate with an Audio Receiver which takes commands on an RS-232 serial port and since ThingShield uses the SoftwareSerial library to communicate - I cannot use it at the same time. Therefore I needed to use the Mega since it has 4 hardware serial ports. This is a long way to explain that 1) I have a ThingShield which works fine on the UNO and 2) Why I cannot use the UNO for my project and I need to use the Mega.

When I attach the thing shied to my Mega, I cannot upload programs from the Arduino IDEā€¦ I simply get a bunch of messages like so:

stk500v2_ReceiveMessage(): timeout

and then it aborts the upload.

If I unplug the ThingShield, the exact same program will upload fine. This is true for any Arduino program. If I unplug the ThingShield and upload the ā€œBlinkā€ example, it loads and executes fine. When I plug the ThingShield into the Mega and try the exact same thing - Timeout. I should point out that ā€œBlinkā€ seems to execute with the Shield attached, but I cannot upload anything. Also, no programs that use the Shield will work either.

Have any of you successfully used an Arduino Mega 2560 with a ThingShield? Is there something I am missing? Please Adviseā€¦ I need the extra serial ports (unless you can tell me how I can use SoftwareSerial on the UNO while using the ThingShield - I think the limitation is SoftwareSerial can only ā€œlistenā€ on one port at a time).

cc: @urman

Have you tried to change the com switch on the shield? It can be set to (D0-D1) or (D2-D3). Might work.

Twack

Yeah, according to the Arduino documentation on SoftwareSerial that you canā€™t use pins 2,3 on the Mega for an interrupt driven serial port. So, what exactly do I do in the software to use either different pins (10,11), which I prefer, or as a last resort use pins 0,1? Is there a different constructor call?

Ok so support was very helpful here, so let me share the solution to save others some griefā€¦

You can NOT use the ThingShield on a Mega out of the box. ThingShield uses the SoftwareSerial library for the Arduino to communicate on pins 2 and 3. This works fine on the UNO. The issue with the Mega (and the Leonardo, and maybe others) is that pin 3 does not support interrupts, so it cannot be used as a serial port with the SoftwareSerial library. So you have two options:

  1. In your code when you set up the ThingShield change the line:
    #define PIN_THING_RX 3
    to
    #define PIN_THING_RX 10
    (or some other pin that the Mega can use with SoftwareSerial)

then install a jumper wire from pin 10 (or whichever one you picked) and pin 3.

-OR-

  1. Contact support and get them to give you the version of the SmartThings library that works with hardware serial ports. In this case you have to use that flip switch on the ThingShield which jumper 0 and 1 to 2 and 3. So the procedure would be: a) flip switch to 2/3, b)upload code, c)flip switch to 0/1 (note in this scenario, you canā€™t use the serial monitor to debug you code while running as the ThingShield will now be using those pins to communicate).

Very frustrating as it clearly states on the ST site that the ThingShield works with ANY Arduino board with the R3 layout. Iā€™m impressed with the level of support I received and am very happy with that.

3 Likes

Steve, OMG thank you! After all of this time, this is crazy that this requirement is still undocumented, I just received it 2 days ago and after surfing for these 2 days finally landed on this. Arrrgh .
But thanks again :grin: !

Holy old threads! Yeah, I started to think there really wasnā€™t much of a ā€œthing shieldā€ community out there. So when I figured this out, I posted it in hopes it would help someone ā€“ I had no idea it would help someone 2 years down he road! :sunglasses:

Honestly since I wrote my GarageDoor controller and hooked it up, I havenā€™t touched it in almost 2 years. These days, Iā€™d accomplish the same thing with the MimoLite from FortrezZ. At the time, SmartThings was a wee baby platform and didnā€™t have as many devices as it does now.

Thank you so much!! I also canā€™t believe this is not documented. I just started this up this morning, and couldnā€™t figure out why it wasnā€™t working. Did the jumper 3 to 10 trick, and everything is working now. Phew. Thanks!

@ogiewon has a ThingShield library that supports the Mega 2560 and hardware i/o. You might want to check it out.

@bravenel do you know where we get the one for 2560? I could only find one library linked from the SmartThings page, and I couldnā€™t get it to work without changing the PIN_THING_RX to 10 and adding the jumper wire.

Itā€™s on Github, here:

1 Like

Thank you!! Looks like there is still a wire patch needed for Mega, but this is definitely a more up to date library. Thanks!

I use that library with a Mega 2560 + ThingShield + RS232 Shield for my Lutron RadioRA integration. Wire jumpers for ThingShield to use hardware i/o instead of SoftwareSerial, and RS232 Shield likewise.

Thanks. Just reading all the code to understand it, and plan to use the hardware I/O. Looks like a great implementation. Thanks again for pointing me there. Canā€™t wait to play with this and the groovy side! :slight_smile:

Hi Bruce, not sure if you can help me. I copied all the libraries over and am trying to compile the ST_Anything.ino file. It gets stuck with the below error. Iā€™m sure this is something stupid, but I canā€™t figure out what the issue isā€¦

ST_Anything:93: error: ā€˜namespacestā€™ does not name a type
void setup()
^
exit status 1
ā€™namespacestā€™ does not name a type

Let me know if you have any questions about my improved version of the ThingShield library. Using one of the extra Hardware Serial ports on the Mega 2560 is definitely the best way to go. During testing, the HW serial outperformed the Software Serial.

Good luck and have fun!

Hi all, took me a while to find this thread, but it was just what I needed. Thanks @stevesell for sharing the solution for mega and serial interrupts.

Question though. Iā€™m able to now use the ā€œonā€ and ā€œoffā€ button to control the ThingShield RGB Led per the example, but if I go out and back into the Arduino ThingShield device on my phone, it loses the state information. It always is defaulting to ā€œonā€ state in the android app for that particular device. If I toggle it off and on it works and shows the right state until I leave that device ever again.

I have version 2 of the hub by the way. Any ideas?

UPDATE: well, I was using the smart device handler from here and that seem to have been my problem. I moved to using the standard type ā€œOn/Off Shieldā€ and now it works to always show the right state in the app on the phone.

Hi Allā€¦

Itā€™s me againā€¦ like a broken record ā€¦( Old School )

If anyone has an Arduino ThingShield available for sale, please let me know
still looking for a couple units.

Thanks a lot

Ben