Arduino Mega 2560 and ThingShield = no upload?


(Steve S) #1

[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


Ardunio Shield not receiving events
(Todd Wackford) #2

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

Twack


Getting started with the SmartThings Arduino shield
(Steve S) #3

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?


(Steve S) #4

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.


(TD) #5

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: !


(Steve S) #6

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.


(Doug) #7

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!


(Bruce) #8

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


(Doug) #9

@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.


(Bruce) #10

It’s on Github, here:


(Doug) #11

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


(Bruce) #12

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.


(Doug) #13

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:


(Doug) #14

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


(Dan) #15

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!


Lutron RadioRA (version 1) and SmartThings saga. (Prologue)
How to make sure tiles show the proper state for garage door control
(Justin Eltoft) #16

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.


(Ben Wolodko) #17

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