[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).
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:
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-
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.
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 !
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!
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!
@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.
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!
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.
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.