Sunday, September 20, 2015

Misterhouse controls a traffic light?

Okay, I've taken a bit of liberty with the title. The traffic light part consists of 3 LEDS (red, yellow, and green) on a breadboard with the Fubarino Mini, WIZ550io network interface and a DHT22. The Furbarino uses an Arduino type environment but uses the Microchip PIC32 instead of the AVR. I've mentioned my IoT boards in previous posts and decided it's time I shared a bit. First: pictures of the boards. At the moment I have 2 wired network prototypes working. I'm also working on wireless network prototypes but they're a long ways from being setup. The first working prototype was the simple Chipkit UNO32 with a WIZ550io board and a DHT22 temperature and humidity sensor. The code has the MQTT topics hard coded to specific topics. This board just sends updates about humidity and temperature. It can receive commands but doesn't really do anything with them other than send them to the serial debug port. Between iterations of that and the latest IoT device, the Fubarino Mini, I found all sorts of interesting features in the Chipkit libraries. The one that interested me the most was the createTask() function. It allows me to create tasks that run periodically outside the Arduino loop function. Very cool, I'm using that as a heartbeat function to see if the board has been disconnected or hung up and if necessary reboot. There are various interrupt functions I'll take a look at later so I can do things like push a button and get a reasonable response. But for now, lots of baby steps.

The second working prototype is my Fubarino Mini, in addition to working out the differences with the Arduino, the UNO32 and the Mini I started adding to the code so I could control the Mini from MQTT topics. Again, hard coded topics, but now the Mini is sending periodic updates and monitoring topics for commands. In this case a simple set of commands to turn on 3 LEDS. Since I've already added MQTT to Misterhouse, I wrote a simple routine to issue the commands to turn on the lights in a US traffic light pattern but with much shorter intervals. Other than a few minor glitches (power related?) both boards have been running for weeks with no reset (yea!). I still have a lot more work to do, such as finishing my methods of automatic configuration of the IoT device from MQTT topics. I also need to work on security as I really want to be able to install the devices in remote sections of the internet, subscribe/publish to an MQTT cloud service and still have my local Misterhouse control, configure and monitor these devices. I'm part way there but more thinking and coding needs to be done.

Okay so now I need to put together a web page explaining how to setup Misterhouse, MQTT, and my IoT devices. I'll also have to add to my other IoT publishers and subscribers also. I have a number of them including Node-Red and bash scripts. Most are publishers, get web information, filter what is needed then republish for local subscription. But there is also business (?) logic in things like Misterhouse and the different flows of my Node-Red code. I must say that I'm very excited about the 32 bit microcontroller and the use of MQTT in home automation. While a simple 4 bit processor can flip a bit add networking and security and more resources are required. I really don't need a Linux system such as a Raspberry Pi running a light switch when a PIC32 can handle all the requirements. Boy this is going to be one interesting IoT web page. ;-)

Thursday, September 17, 2015

Playing with Kicad

I've been busy enjoying the summer, getting in my miles, and building my IoT stuff for my HA. I've mostly worked on the PIC32MX/WIZ550io boards and the ESP8266 boards. I'll post my Fubarino SD Mini, Misterhouse controlled, traffic light (it's just LEDS) in a few days. Yes, I know, pictures or it didn't happen. With all these different processors that means I've spent a lot of time finding software and getting environments setup under Linux. I've managed to setup the Arduino env to work with the ESP8266. I've also got UECIDE working but I'm not sure if I setup the ESP8266 with that. I use MPIDE and UECIDE for my PIC32MX related projects. I'm now at the point where I'd like to build a few of my own boards. I've tried Eagle in the past and though I understand the process, Eagle never felt comfortable to me. In the 80's, I used to do all of this by hand on paper with a pencil (and tape for the layout). Tedious work! I'm now working with Kicad and I'm finding that a lot more natural to me. So far I've laid out the schematic (no so hard), selected parts (okay kind of, I've selected valid parts just not the one's I wanted but close enough for learning), laid out the PCB, ran FreeRouting to do autorouting (more on that in a minute), and finally got it to print out (printer not CNC). I mostly followed the tutorials which are numerous and useful. I've added my own parts (PIC32MX1xx/2xx) and I need to work on the footprints for various parts as I can't find what I really want on the board. Okay, I couldn't find the footprint because I'm floating in a sea of too-much-information. :-) Besides I want to learn for those times when I need some odd interface that is pretty much a one-off (like my Atari SIO port). Kicad, very cool and I am so surprised at how quick I learned the software.

I finally found some other's BOM to use as a reference for parts. When I was building boards in the 80's it was thru-hole. Now I need tiny parts I can barely see with a microscope. So far I've had a lot of fun learning Kicad and I know I have a lot more to learn such as templates, copper pours, various layout lessons and better handling of the rules.

After following the link on how to download, compile and install FreeRouting using Netbeans, I found I couldn't run the autorouter from inside Kicad (pcbnew specifically). Seems I failed to perform the optional parameters step so when I ran the command:

java -jar /usr/local/bin/freeroute.jar 
I'd get the following error:
 no main manifest attribute, in /usr/local/bin/freeroute.jar 
After poking around the internet I derived this:
 mkdir t
cd t
# If you've already copied the jar from Netbeans
# to the Kicad Binaries directory
unzip /usr/local/bin/freeroute.jar
jar cfe fr.jar gui.MainApplication $(find -type f)
sudo mv fr.jar /usr/local/bin/freeroute.jar
# To test
java -jar /usr/local/bin/freeroute.jar

My intention with all of this is to build a few boards I can easily 'throw out' there as complex sensors. Connected to MQTT to allow any HA software to control and monitor the devices. I'm not sure how well the ESP8266 will work with the Arduino env. You have to be real careful with the code in the loop as the WiFi isn't a background process. But an ESP8266 as the network interface to the PIC32 would be useful. The ESP8266 is not the only wireless I have. I have a couple of RF transceivers and other WiFi boards that I will be playing with. Most of what I am doing is for the sake of curiosity (learning).