Posted on Leave a comment

SuperHouse Vlog #43: SMEE Robot Building Competition 2016

The second annual Society of Monash Electrical Engineers Robot Building Competition saw about 150 competitors spend a weekend building robots to solve a specific challenge. Their robots needed to follow a line down a track, detect when they approached a gate, sense the colour of the gate, transmit that colour to the course control computer using an RF transmitter module, wait for the gate to be opened, proceed to the next gate, and repeat until they reached the finish line. The finish line is a line across the track that matches the colour of the last gate, so they also had to detect multiple cross lines and ignore the ones that were the wrong colour.

The challenge turned out to be too complicated to complete within the time allowed, so it was simplified a little during the competition.

Freetronics was a major sponsor of the competition, providing prize packs for the first 4 place teams plus a bonus prize pack for a “best bling” category judged by me purely on who made the coolest looking robot.

Posted on 3 Comments

#16: Compiling Arduino sketches with Pocket C.H.I.P.

Do you ever find yourself inside your ceiling or under the floor working on your home automation system, and need to SSH to a remote machine or re-flash an Arduino?

Sure, you could drag your laptop under there with you, but I don’t want to have my expensive laptop lying around in the dirt or insulation.

I may have found the answer.

C.H.I.P. and Pocket C.H.I.P. will be available soon from getchip.com.

I used “arduino-mk” running on the Pocket C.H.I.P to compile and upload an Arduino sketch: github.com/sudar/Arduino-Makefile

The following sequence got everything working for me. You may want to do things a little differently, for example by managing the python-serial extension using Pip or storing your sketches in a different location. That’s totally up to you, just make sure you alter the paths shown below as necessary.

Start by making sure your package list is up to date, and that you have the latest packaged Arduino and Python serial extension installed on your C.H.I.P.:

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install python-serial arduino arduino-mk

Create a directory inside your home directory to keep all your Arduino sketches organised:

mkdir ~/sketchbook

Now go into your sketchbook and copy an example project out of arduino-mk, so that it includes the example Makefile:

cd ~/sketchbook
cp -a /usr/share/doc/arduino-mk/examples/Blink .

Note the space and the dot at the end of that line!

Now go into the Blink project and see what files it contains:

cd Blink
ls -l

You’ll see that there’s both the sketch itself and a Make file:

-rw-r--r-- 1 chip chip 509 Jul 12 2014 Blink.ino
-rw-r--r-- 1 chip chip 61 Jul 12 2014 Makefile

There’s nothing unusual about the Blink sketch. It’s just standard Arduino code that you could compile with the regular IDE. The magic is invoked through the Make file.

Open the Make file in your favorite text editor, and you’ll see that it looks like this:

BOARD_TAG = uno
ARDUINO_LIBS =
include ../../Arduino.mk

The “BOARD_TAG” value specifies that you want to compile it for an Uno or compatible board. You can change this to match other boards found in the Arduino board hardware definition file, which is located at /usr/share/arduino/hardware/arduino/boards.txt. In that file you’ll find other handy board types that I’ll list at the end. For now, we’ll assume that you’re using an Uno and leave that unchanged.

The “ARDUINO_LIBS” value allows you to specify a path to your own custom libraries in case you need them linked during compilation. We’ll ignore that for now, so leave that line unchanged.

The “include” line is a problem. It assumes the project is still located in the shared location where it was installed by the package, but we’ve made a copy in our local sketchbook. To fix that, change the “include” line to read:

include /usr/share/arduino/Arduino.mk

There are many other options you can add to the Make file to override the default settings within Arduino. For example, you can define the path to a specific version of AVRDUDE if you want to bypass the version that’s bundled with the Arduino environment.

But for a minimal example, you don’t need to change anything else.

Now you can compile the sketch, and upload it to your Arduino. To compile the sketch without attempting to upload it, just type:

make

That’s it! Can’t be much simpler. If there are any compilation errors, you’ll see them in the terminal.

To upload (and automatically compile if necessary) make sure your Arduino is plugged into your Pocket C.H.I.P. using a USB cable, and type:

make upload

You’re all done! Your sketch should now have been uploaded to your Arduino.

There are other commands available as well. Check out the Arduino-MK documentation for more information:

github.com/sudar/Arduino-Makefile

Alternative board types

These are all the board tags list in the standard /usr/share/arduino/hardware/arduino/boards.txt file:

uno: Arduino Uno
atmega328: Arduino Duemilanove w/ ATmega328
diecimila: Arduino Diecimila or Duemilanove w/ ATmega168
nano328: Arduino Nano w/ ATmega328
nano: Arduino Nano w/ ATmega168
mega2560: Arduino Mega 2560 or Mega ADK
mega: Arduino Mega (ATmega1280)
leonardo: Arduino Leonardo
esplora: Arduino Esplora
micro: Arduino Micro
mini328: Arduino Mini w/ ATmega328
mini: Arduino Mini w/ ATmega168
ethernet: Arduino Ethernet
fio: Arduino Fio
bt328: Arduino BT w/ ATmega328
bt: Arduino BT w/ ATmega168
LilyPadUSB: LilyPad Arduino USB
lilypad328: LilyPad Arduino w/ ATmega328
lilypad: LilyPad Arduino w/ ATmega168
pro5v328: Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328
pro5v: Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168
pro328: Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328
pro: Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168
atmega168: Arduino NG or older w/ ATmega168
atmega8: Arduino NG or older w/ ATmega8
robotControl: Arduino Robot Control
robotMotor: Arduino Robot Motor

You can also use custom board profiles, but that’s beyond the scope of this post! Most common Arduino compatible boards match something on this list. For example, the Freetronics EtherMega operates just like an Arduino Mega with a 2560 processor, so you’d select “mega2560” as the BOARD_TAG in the Make file.

Update 6 Jan 2017: Quick Setup Script

My friend Alec has written a script to simplify the process of installing the packages I used in the video and also to fix a few things he doesn’t like about the default setup. His script installs the necessary packages, blocks root access to the terminal and SSH, locks the root account, changes the default password, changes the hostname, and forces public key authentication via SSH. Definitely worth a look:

gist.github.com/alecthegeek/434325b6ea261ba84499f4966795073e

Posted on 4 Comments

#15: Watchdog timers for Arduino home automation

A watchdog timer helps keep your embedded devices running, by making sure they are responding properly and automatically hitting reset or cycling the power if they die. I’ve added a simple hardware watchdog timer to an Arduino compatible board running inside my ceiling, where it’s difficult to access if I need to reset it manually.

View directly on YouTube: https://youtu.be/GC6dGypGctQ

Links for this episode:

Posted on 6 Comments

#14: Ambient tile using Arduino, ESP8266, and NeoPixel compatible LEDs

Ambient information displays allow a home automation system to provide you with subtle feedback embedded within your environment. Concealing RGB LEDs behind a wall tile allows them to display status information when they are turned on, but still be totally invisible when turned off.

View directly on YouTube: https://youtu.be/cQtFoTWKa9o

Parts Required

Assemble Hardware

Because I installed the tile so many years ago, I used original Freetronics Addressable RGB LED Modules that came out before the term “NeoPixel” was invented and used the WS2801 driver IC. Newer modules use the WS2812B, which integrates the controller chip into the LED body itself.

Connect up as many LEDs as you need, and glue them in place behind the tile. It’s best to keep the controller somewhere accessible in case you need to replace or repair it, so just have the LEDs permanently fitted behind the tile. You don’t want to have to rip out tiles and then re-tile your wall just to plug in a USB cable and update the firmware!

Software

I’ve published an example sketch that has two separate functions: firstly it subscribes to an MQTT topic and watches for messages telling it to change the colour of an LED, and secondly it reads periodically from a DHT-22 temperature and humidity sensor and publishes the readings to other MQTT topics.

You can see the example sketch at https://github.com/jonoxer/BasicOTAFastLEDHumidMQTT