Blog Housekeeping

I’m making some changes to this blog. I’ve been unhappy about the fact that all the code is static, not the code I use every day. Instead, I want a nice code repository, so whatever I write on my machine can be published directly, and if I update it, the updates end up here. I would also like syntactical highlighting of the code. And now, ta dah! It’s all done. Here’s what I did, for your reference and my own, because I’ll forget next time I need to update it.

So from now on, new code on this blog will look like this:

[include file="../../code/Arduino/helloTom/helloTom.pde" start="3" clean="true"]

And it’ll all be updated whenever I make changes.  Exciting, isn’t it?

Continue reading “Blog Housekeeping”

A Few Good Reasons Why Peter Knight Rocks

Peter Knight works with Massimo and Alex and co. at Tinker.it. He’s written some great AVR code, which is useful in Arduino.  For example:

Secret Thermometer takes advantage of the ATMega’s internal thermometer. Turns your ‘328-based Arduino into a thermometer with no extra parts.

Secret Voltmeter same idea, but this reads the internal analog-to-digital converter to tell you the Arduino’s supply voltage. Also works on the ATMega168.

He’s also done Cantarino, a speech synthesis engine; Auduino, a granular sound synthesis engine; a DMX library; and more.  Check them all out at the tinker.it code repository.

Controlling Lots of Outputs from a Microcontroller

Making LED displays is fun. There are a a few tools that get used all the time, from row-column scanning to LED driver chips to multplexers and shift registers. This tutorial discusses some of the more popular methods for controlling large amounts of LEDs from a microcontroller, including their various strengths and weaknesses, and how they work. For more on this subject see chapter 14 of “Physical Computing“, where Dan O’Sullivan and I discussed it in more depth.  I’ll also include some notes on how to apply these ideas to controlling multiple motors or other high-current loads.

Most microcontroller modules have a limited number of outputs. Even if you use the analog inputs as digital I/O, there are only 19 pins on an Arduino, for example. That’s a fairly typical number for an 8-bit controller, and it seems not nearly enough if you want to control, say, 100 LEDs or more.  There are a couple ways around this problem.  Without adding any additional hardware, you can make a matrix of your LEDs and control them using row-column scanning.  If you want discrete analog control over one output at a time, you can use a multiplexer. For digital control over multiple pins, you could use an addressable latch or a shift register. If you need pseudo-analog control over multiple pins, you could use a PWM driver.  There are also several LED driver chips that are designed specifically to control groups of LEDS.

Continue reading “Controlling Lots of Outputs from a Microcontroller”

STP16C596 Shift Register

This tutorial will show how to control multiple LED outputs from a microcontroller using an STP16C596 shift register. The STP16C596 is similar to the popular 74HC595 shift register, but it’s nicer because it can sink a constant current to the LEDs it’s driving. It works slightly differently, however, so this code won’t work exactly for the ‘595.

This is a stub. More explanation will follow, but for now, here are schematics and code for Arduino.

Parts you’ll need:

  • STP16C596 shift register
  • Arduino microcontroller
  • LEDs
  • 1-kilohm resistor

Continue reading “STP16C596 Shift Register”

Tilty ball: Controlling 64 LEDs and a 2-axis accelerometer

This example shows how to control 64 LEDs and read the input from two axes of an accelerometer on an Arduino.  The Arduino used here is a Duemilanove, but it will work on any of the models out there prior to the Duemilanove as well.  This example uses row-column scanning as a way to control more LEDs than you have output pins.  It also uses some of the analog pins as digital I/O pins.

Parts you’ll need

  • Arduino Duemilanove or equivalent
  • 2-axis accelerometer. I used the ADXL335 breakout board from adafruit.com, and only used two axes.
  • 8×8 LED matrix.  I used one I bought surplus.  See this post for details on figuring out your matrix’s pins if you don’t have the data sheet.
  • Breadboard or prototyping shield.  I used the proto shield and tiny breadboard from adafruit.com.

Continue reading “Tilty ball: Controlling 64 LEDs and a 2-axis accelerometer”

A Tale of Two (three) Pongs

Created 2 April 2009, updated 1 Nov 2020

When I start learning a new  platform, I have a simple rule: If you don’t know what to do with it, make pong. What I love about pong is that it’s a simple rule set, easy to understand, and implementable on just about anything with a pixel display.  You can generally implement it in a day or less on any platform. And it’s a great example of engaging interaction.  People understand what’s going on right away, and, when implemented well, it’s just challenging enough to keep you engaged for several minutes at least.  That’s good interaction, to me.

I’m a big believer in starting with the application rather than the platform.  I think you do better work when the tools serve the need rather than the other way around.  But sometimes you get stuck with the assignment to learn a particular platform or tool, and you have to make up a project on the spot.  When that happens, make pong.

As an example of this, I built pong for two platforms yesterday [1 April 2009]: an Arduino Mega with 2 8×8 LED matrices (based on my earlier post), and Processing.  Since Arduino’s programming syntax was based closely on Processing’s, I figured it should be possible to port the code from one to the other pretty quickly. It took about ten minutes to go from Arduino to Processing.  In 2020, I updated this exercise to write the program in p5.js as well. Following, I’ll describe the thought process of putting the game together for all three, as a hopeful aid to beginning programmers.

Continue reading “A Tale of Two (three) Pongs”