David Findlay

TechShop

Recently I joined TechShop and started taking the classes they offer in the use of the tools (which are required in order to use those tools).

I made the kids a t-shirt and tote bag for their fake restaurant — DuckBill’s — in the silk screening class:

duck bill's templateduck bill's merchandise


And some acrylic trinkets on the laser cutter:

hello kitty laser cutter

daleks laser cutter

I still have lots to learn but I can see a multitude of projects in my head that access to all these tools opens up: including a proper case for that
badminton scoreboard.

Badminton Scoreboard IV: Working!

Last time I had just sent the boards for fabrication on February 22nd. I got them back on March 7th:

Boards

They look amazing. I find it hard to believe how easy, cheap ($9.10 for 3, shipped), and quick it was to go from the Sparkfun Eagle tutorials to a physical board in my hands.

Assembly


I should have left room on the board to fold over the bigger caps, but other than that putting together one of the boards went pretty well:

Initial Assembly

It didn’t work though, and after a minor panic I realized I had switched the 5V and GND pins for the radio when creating the schematic. Once I switched the jumper cables attached to them around it worked!

Next I hacked a bandaid box as a case. It works okay for now, but it was hard to cut and so the edges are pretty rough. I’ve joined my local
TechShop, so I plan to make a better case for it at some point.

Here’s the initial assembly in the case:

In the box

You can see what an awful mess of jumper cables I had. I realized at this point that I should have used male connectors on the board for the radio and display, not female. I have a solder sucker but no braid, so it took me ages to get them swapped, and I did something bad to the radio 5V connection in the process. Rather than go through the pain of taking the male connector off, after spending so long to get it on there, I took the easy way out and just used the 5V pin on the ICSP header. I will now for next time.

To clean up the jumper wire mess I tried making a ribbon cable using standard male connector pins, with heat shrink around each connection, but I could tell it wasn’t going to hold up to use. It also looked like crap.

I didn’t have any pre-made 1x5 cables but I realized I did have 2x5 cables, and who cares if you don’t happen to actually connect one row of the pins to anything? One of those cleaned up the display connection nicely.

The radio was more problematic since I had screwed up the 5V and GND connections—if they’d been right I could have plugged the radio directly into a female socket on the board as originally intended. Instead I used a 1x3 servo cable and 3 jumper wires. Not ideal, but much better than the mess I had before.

This left me with:

After Cable Cleanup

Field Test

I took the roughly assembled version to our next badminton evening to try it out. The range of the key fobs was much greater than it had been on the breadboard: they worked from every corner of the gym. I suspect the difference is due to interference from the breadboard’s many connections, but whatever it was the real-world range with the custom board meant the key fobs were actually going to be practical.

The scoreboard worked pretty much perfectly, except that sometimes if you released the button too quickly it wouldn’t register the button press. That meant we ended up having to look at the scoreboard while pressing the key to make sure it registered. By the end of the evening it was clear that adding a beep when it recognized a button press would make it more user friendly.

Adding a Buzzer

A piezo buzzer ought to do the job just fine, but I hadn’t broken out any of the other digital I/O pins. However the ICSP header has connections to MOSI, MISO and SCK. These correspond to digital pins 11, 12 and 13 of the Arduino respectively, so I was able to hook up the buzzer between SCK and GND and add a tone() call for D13. It seems like it will be loud enough, but I won’t know until we play next if it really is.

Updating the Firmware

I updated the code to add the beep then tried to upload it using my AVRISP mkii, via the File/Upload Using Programmer menu item in the Arduino IDE. It kept failing with a “bad AVRISPmkII connection status: MOSI fail” error. It took me a really long time to figure out why: I probed the pins, double checked the schematic, compared it to a SparkFun arduino clone design, asked a question on the Electronics Stack Exchange and got nowhere. Then, a week later as I was redoing the cables I noticed a solder bridge between MOSI and GND on the underside of the board, where I’d soldered the ICSP header pins. I fixed the bridge and it started working. I can’t believe I didn’t find that earlier!

Fin

Here’s the final state of the connections, including the buzzer:

Final

And here it is in action (taken before I added the buzzer):

In Action


Lessons Learned

  • Get the schematic right!
  • Allow more room around the outside so the lettering isn’t chopped off.
  • Check for solder bridges when things don’t work.
  • Make room for strain relief for the battery power connection cables.
  • Make room for mounting holes.
  • Make room for bending capacitors flat to the board.
  • Think harder about whether male or female connectors are what’s needed before soldering them.

Badminton Scoreboard III: PCB

Now that I got it working with a bare ATmega168, the next logical step is clearly to create a custom circuit board for the Badminton Scoreboard.

I followed along with SparkFun’s excellent tutorials on
setting up Eagle and using its schematic and board layout tools. For getting the PCB created, one of the places SparkFun recommended was OSH Park. OSH Park lets you upload an Eagle board file, so you don’t need to generate Gerber files. Their site gives you a nice preview of what the board will look like, so you can check out the solder masks and your silkscreening before committing to an order. They charge $5/square inch for 3 boards, including shipping, which seems pretty reasonable to me.

Here’s what I came up with:

The top:

top


and the bottom, which is supposed to look like a bit like a badminton court (not to scale, as I positioned the court lines to avoid the pads as best I could):

bottom

I read a few tutorials on bare board Arduinos and never really got a consistent answer on what values to use for the bypass capacitors, so I winged it a bit. I’ve no idea how well the winging went, if I spaced the components out enough, or if I laid the tracks properly, but I should find out when I get the boards back in a couple of weeks.

Badminton Scoreboard II: Bare

I managed to find my AVRISP mkII and I had a regulator and resonator and other sundry parts necessary, so I switched the Badminton Scoreboard from an Arduino to a bare ATmega168 on the breadboard, just because I hadn’t tried that before. Getting the Arduino boot loader onto it was easy, using the Arduino IDE. Getting the sketch onto it was unnecessarily complicated: for one, there are out of date instructions out there telling you that you need to edit the Arduino IDE settings file by hand: you don’t any more — you just need to hold down Shift when you press the Upload button, or choose File/Upload Using Programmer; and for two, Upload Using Programmer has a bug, where it will fail if you don’t have any device connected via USB serial, even though you aren’t actually going to program a device over USB serial. I plugged in a Spark Core and it merrily went on it way and used the programmer to get the sketch onto the 168.

So it’s still a rats nest of jumper cables, but no more Arduino board:

Bare 168 Badminton Scoreboard

Badminton Scoreboard

My wife and I play badminton every Friday with a couple of friends. We have a great time, but we’re usually so busy chatting as we play that we keep on forgetting the score.

My friend suggested that I ought to make a scoreboard, so here we are. I knew I would need a display, some buttons, and a microcontroller, and that for simplicity the microcontroller should be Arduino-compatible. As I was looking at displays I came across the M4 receiver at Adafruit. It’s a simple RF receiver with four digital output pins; you press a button on a key fob and the matching digital output goes high. The range is supposed to be in the 20-30 feet range, and so it ought to work for my needs. Using key fobs instead of buttons on the scoreboard means I can make the scoreboard smaller too.

Here’s what I’m using:

I wrote an
Arduino sketch that watches for the button presses and adjusts the score accordingly. Here are the controls I decided on:
  • Keyfob A button: left player + 1
  • Keyfob B button: right player + 1
  • Keyfob C button: left player - 1
  • Keyfob D button: right player - 1
The sketch knows the scoring system of badminton, so when the game is over it makes the display blink. Any key press after that resets the score to 0-0, ready for the next game.

It pretty much worked first time, except that the range of the key fobs in my prototype is only about 18 inches. I noticed that if I remove the display the range improves dramatically, so I think it’s just that I’m powering the Arduino from USB and there’s not enough current to power the receiver and display properly. That shouldn’t be an issue when I switch to a battery pack. [
UPDATE: Yup, that’s what it was: the range is fine when powering it from a 4xAA battery pack.]

Here’s the working prototype:

Badminton Scoreboard Prototype

And here’s the sketch:

First Alarm

My Freezer Monitor sent me my first alarm notification yesterday while I was eating lunch at work:

Freezer Alarm

(That timestamp is in UTC: I should tweak the monitoring script to adjust that for me.)

When I got the alarm I pulled up a CGI page in MobileSafari to query the current temperature. The temperature was back to normal pretty quickly so I didn’t need to be concerned further. When I got home I mentioned it to my wife and sure enough she had opened the freezer at around that time, so the alarm makes sense. Maybe I’ll extend the monitoring script so that after it sees an alarm-triggering temperature it will poll for a few minutes to see if it goes back to normal.

Freezer Monitor

As I mentioned previously, my primary motivation — or at least my justification for playing with the Spark Cores ;) — is to monitor the temperature in the old freezer out in our garage: it stores a cache of pig and cow that would be expensive to replace.

I wrote a Python script to read the temperature and issue a notification to my iPhone via the API that goes with
Prowl.app. It will also send a notification if it is unable to retrieve the temperature for an extended period.



I have this script installed as a launchd service on our always-on house Mac, via
Lingon X (easily worth the $10 to save me from having to edit plist files like an animal).

Now to see about hooking the other Spark Core up to the
BlinkyTape

Spark Core Freezer Monitoring Success

After installing the Spark Core as a freezer monitor last night, I ran curl in a while loop in bash to pull the temperature reading every minute overnight and append the results to a text file. This morning, after a little bit of sed and grep tweaking, I pulled the readings into Numbers and charted them:
Freezer Temperature Chart
You can see that the temperature rises to around 3. The compressor then kicks in and lowers the temperature to around −3. The temperature then slowly rises up to around 3 again, and so on — illustrating the hysteresis of the temperature control system in the freezer.

I wrote a Python script to automate the process of grabbing the result, parsing the JSON and adding the result to the table being charted in the spreadsheet:

This isn’t particularly practical, but was interesting to see nonetheless. My main goal is monitoring, so I will drop the charting part in favour of a simple notification to my phone via
Prowl.app when the temperature gets too high.

Spark Core

Spark Core
My Spark Core modules arrived a week or so ago. I got one with a chip antenna and one with a u.FL connector, because I plan to use it in a building that’s too far from my router for the chip antenna to work. I also picked up a battery board and relay board, although I don’t have specific projects in mind for either.

The Spark Core contains an STM32F103 microcontroller (ARM Cortex M3) paired with a TI CC300 WiFi module. An iPhone app lets you easily gets your cores onto your network. They come with a bootloader that supports reflashing over WiFi. In fact Spark even provides an IDE that allows you to edit code and flash it to any of your modules from the comfort of your favourite browser.

Spark Build IDE
Spark have made the Spark Core as compatible with Arduino as they can, so many Arduino libraries should work providing they aren’t doing anything AVR-specific, although currently the IDE doesn’t support multiple files so you’ll need to copy-paste the library code. Despite the single-file limitation, which they’re working on, the IDE is pretty nice: it even supports some Emacs key bindings. The IDE also allows you to expose variables from the Spark Core; these variables can be accessed via a REST API on Spark’s servers, which mean you don’t need to configure tunneling or DynDNS for your cores.

I already had a Maxim
DS18B20 1-Wire digital thermometer chip lying around, and it took just a few minutes to get that temperature sensor working thanks to Miles Burton’s Dallas Temperature Control Library for Arduino.

The non-library part of the sketch is shown above. It registers an integer variable called
temperature in setup(), which is then populated each time around in loop().
Here’s a sample of the JSON you get back from querying that
temperature variable:

$ curl "https://api.spark.io/v1/devices/1234567abcdef/temperature?access_token=feedbeef”
{
"cmd": "VarReturn",
"name": "temperature",
"result": 3,
"coreInfo": {
"last_app": "",
"last_heard": "2014-02-03T04:30:09.921Z",
"connected": true,
"deviceID": "1234567abcdef"
}
}

Between the REST and the JSON it’s pretty trivial to digest the output programmatically. I put together a little CGI script in Python to make it easy to query the temperature:
Temp CGI
After I had the breadboarded sensor working, I prepared it for duty monitoring the temperature of the freezer in our garage, I put the DS18B20 on the end of a cable with some heat shrink over the connections and mounted the Spark Core in an old iPod touch box, with holes drilled for the sensor cable, antenna and USB power cord. Here it is, gently clamped to the top of the USB power adaptor:

Freezer Monitor