Saturday, December 05, 2015

The Arduino, the good and the bad. (cont'd)

Seems my Arduino Uno, with the W5200, is unstable. The MQTT code mostly worked yesterday but today fails completely. Part of the problem is that the SD card wasn't inserted. Seems it needs to have that SD card in there (hmm, need to look at that). I already suspect the library. I really love those crazy, complex confusing macros. They make the code so easy to understand (not!). I'll look into those later. Right now I need to sit down get some notes together (and my SPI tools) so I can debug this properly. One of the first notes I need to understand is the byte order of Little Indian/Big Indian. This part will be easy as I've been working Indian-ness for years (Intel x86 vs Moto 68K).

Thursday, December 03, 2015

The Arduino, the good and the bad.

I'm working on another article, along the lines of what I want to present at TCF 2016 (March 19, 2016). A full, working, home automation set up using a VM (to allow users to download and run with a minimal of fuss). Virtual controllers, virtual devices and working software. Of course I want to go a bit further than the virtual devices and have actual working devices. So I decided to see what I could build to demo with. I have the Fubarino, the Uno32, the Teensy 3.2 and the Arduino Uno. The Uno has a W5200 shield and the rest the W550io boards (not a sheild). What possibly could go wrong? Yes, that's sarcasm. I've built all sorts of code that was pretty much portable between AT&T Unix, BSD Unix, Linux, DOS and Windows. It's not easy but with careful coding and consideration it has worked. Then I got to the Arduino env and poof, can't do that with an Arduino (at least no easily). Assume I ranted here and we can get to the point. I now have an Arduino env for the AVR Uno (of course), the Fubarino and Uno32 (MPIDE). I'm working on getting the Teensy 3.2 setup. I've got a lot more work to do there. And I decided to compile the MQTT code for all the boards. Getting the WIZNET code to work with the PIC32MX was interesting. I found out the 1.0 version of the Arduino env did things one way and the later version did something else (grrr). Eventually I figured out the quirks and I pretty much had a stable platform to work with. I decided to get a Teensy 3.2 to see how well the PIC32 compares. Wow was I surprised when the code compiled (with some fuss) and the size difference was dramatic (uses less RAM and Flash than the PIC32MX and only slightly more than the AVR). I still need to check into that as it could be a lack of knowledge. I don't know it all. But a compile does not a program make. So I haven't yet wired up the W550io to the Teensy. I also decided to compile the MQTT code on the Arduino Uno with the W5200 sheild. I couldn't believe how difficult this was. 1.0, 1.5, 1.6, all caused different issues. So I stepped back and tried to compile and run the example code (which didn't support the W5200). It compiled, wow the ram usage was the lowest of the bunch. But now I needed to get the W5200 libraries loaded (and adventure in frustration). To make a long story short (too late) I got it compiled and uploaded. But it doesn't work. The data in the valid packets contains junk along with the data (like buffer overflow issues). I think I've traced it down to the W5200 chip. Probably bad initialization or setup.

So what have I learned? Well first, be careful with the libraries you use. The w5200 shield is a Seeed shield. I discovered I should be using their library rather than the Wiznet library (yes, now the Uno and the w5200 and my MQTT code work fine). Next these environments don't remove complexity, they just hide it. And sometimes it hides it very annoyingly. Next, to abuse Anton Ego's quote from Ratatoille: In the past, I have made no secret of my disdain for Chef Gusteau's famous motto, "Anyone can cook." But I realize, only now do I truly understand what he meant. Not everyone can become a great artist; but a great artist *can* come from *anywhere*. Today's call for everyone to learn to program is silly (in my opinion). But that doesn't mean that more people shouldn't learn to program. With these tools (hardware and software) make things made more interesting. Perhaps we need better tools that the non-programmer can program with. Yup some really cool stuff has come out of the Arduino environment. And I think my environment solution will be to use UECIDE (The Universal Embedded Computing IDE). It supports the PIC32MX boards (Fubarino, Uno32, Pinguino32, Teensy, and ESP8266). I'm hoping soon they'll have the Teensy 3.2 added.

The one surprise in all of this is that the Arduino and the AVR is pretty efficient. My MQTT sketch (it's a program) uses very little RAM. The Teensy 3.2 is pretty good also. The PIC32MX env (MPIDE) is not so good. I wonder why this is and hope to experiment and improve this. This doesn't mean the MPIDE env is bad, there are many features that I wish I could get on the other environments. Think the right tool for the job.