Programming with Adafruit Trinket

I’m very excited about using the Adafruit Trinkets, which are essentially small breakout boards for the Atmel ATtiny85 microcontroller.  It is intended to be used with the Arduino IDE (and I hoped this would be easy), and I found this to work well for compiling source code into a HEX file.  However, I was never successful getting the upload to work directly with Arduino IDE.  At this point, I learned to use avrdude from the command line (I’ve been working in Windows XP up to this point, but I’m switching to Ubuntu since MS doesn’t support XP anymore).

I followed the instructions from Adafruit given here.  These are well written and got me a long way.  I only had trouble uploading with avrdude.

I found this to be a two step process:

1.  I used this command to clear the on-chip flash:  avrdude -c usbtiny -p attiny85 -U flash:w:<hexfile.hex>

This would flag tons of errors that would require a CTRL-C to stop.

Inline image 1

 

2.  Then run this similar command:  avrdude -c usbtiny -p attiny85 -D -U flash:w:<hexfile.hex>

This will actually write to the flash.  If you don’t do step 1, you will get a verification error.

Inline image 1

 

Once the chip was programmed, everything worked well.  Many of the Arduino commands work with the ATtiny85.

Wireless Temperature Sensor

In continuing with my quest to automate my house, I want to have better temperature control of various rooms.  My goal is to create a few digital thermometers connected to the nRF24 radios that I have started working with.  I’m using an Adafruit Trinket microcontroller, a DHT11 temperature and humidity sensor, and an nRF24L01+ 2.4GHz radio.  I wired together a quick prototype pictured below.

Image

The Trinket has 5 pins:

– D0: SPI Clock to nRF

– D1: SPI Data Write to nRF

– D2: SPI Data Read From nRF

– D3: SPI Chip Select Bar to nRF (CSN)

– D4: Chip Enable to nRF (CE) \ Data Wire to DHT11

Notice how I had to overlap the 5th Trinket pin.  The nRF was powered down in software in order to read from the DHT11.  I learned several important things about programming with the Trinket.  I’ll discuss that next time. 

Photo Booth

I’ve started making a photo booth camera box for a wedding I’ll be going to soon.   I should have been documenting my progress a little earlier, but it’s better late than never.  The top picture below is the front side that the users will see entering the booth.

Image

The picture below is what the inside of the box looks like from the back.

Image

 

The box is built around a 12″ monitor with capacitive touchscreen that I wasn’t using.  I knew I wanted to use a Raspberry Pi and the Raspberry Pi camera had just come out when I began working on this project, so I thought it would be a great fit.

The first major hurdle was getting the Raspberry Pi to fully use the monitor.  The monitor part only has a VGA input, so I had to get a converter to translate the Pi’s HDMI video into VGA.  Not too bad.  The trickier part was being able to move the cursor by touching the screen.  I am using Raspbian (because it seems to have the most support) and it comes with the source code for many, many drivers; so many that most aren’t compiled into the kernel for the released build.  My monitor uses a 3M Microtouch hardware with serial I/O and fortunately, Raspbian included the 3M uTouch driver code.  I just had to rebuild the kernel which, after much Googling, wasn’t too difficult.  It just took forever (actually about 11 hours) because I had the Pi create the new image. After telling the Pi to use the USB to serial adapter (connected to the touchscreen serial port) as a mouse, I was in business.  The cursor moves with your finger!

Next, I got a Raspberry Pi Camera and it was pretty straightforward.  I use the basic raspistill function to take still pictures.  I did learn that the timeout option is critical.  I’m not sure why it’s necessary, but your pictures will be very dark if you set the timeout to 0.  The best compromise between picture quality (brightness) and speed was setting the timeout to 300 ms.  I still would like to have a function that could keep the camera from shutting down after each shot, like an indefinite time lapse option.

I then got a 2 x 2″ piece of plywood to start the box.  I cut out holes for the monitor, the camera, and the 16 LEDs around the border.  The LEDs are square, 3 color Piranha LEDs that I got from Adafruit.  I used a mortise chisel tool to cut out the small square holes for the LEDs to fit in.

With the front panel mostly complete, I built the sides of the box, drilled the last holes for the EL wire to poke through, and spray painted the box black.  I cut wires and soldered them directly to the LED leads and installed the LEDs into the front panel.  I used 2 PWM 24-channel drivers (also from Adafruit) to drive all 16 of the 3 color LEDs.  Each color of each LED gets its own 12-bit channel.  I know this is probably overkill, but I’m hoping to make some interesting dancing lights.  Getting these to work was very easy with the Pi’s GPIO pins and it is nice that the breakout boards are “daisy-chain”-able.

At this point, I started working with the EL wire.  I learned a couple things: 1, the EL wire inverters make an annoying hum and I didn’t want this to prevent people from using the booth, so I wrapped them in many layers of paper towels and duct tape (as shown in the second picture).  This worked out well.  2, I had planned to use hot glue to attach the formed EL wire directly to the painted plywood surface.  I’ve found that the glue only hold for about a day.  My new strategy is to glue the wire and then use tape to hold it into place.  I may even leave it and just take the tape off the day of the wedding.  If the glue loosens after that, I won’t care as much.

I added a small board with a pair of 12V relays so that I can turn the EL wire on and off using Pi pins.

I think that’s about it for the hardware.  I’ll describe the software in another post. 

Arduino Garage Door Opener

As the first sensor in a long line of future home automation contraptions, I put together a small board that can sense the current state of the garage door (up or down), toggle the garage door motor, and wirelessly send and receive commands.  Here’s what I’ve got so far.  It’s built around the Arduino Nano that controls a NRF24L01 breakout for wireless, a Parallax PING proximity sensor for determining if the door is up or down, and a 5V relay for toggling the door motor.  The hardware is mostly finished, now I’ve got to get to coding.  I’m planning on developing several more sensors around ATMEGA and NRF24 chips.

IMG_20130626_201740_824 IMG_20130626_201827_172

Garage Door Opener

The theme of this blog is taking stuff apart with the goal of adding some awesome features.  Today I am going to start with the mission of taking my regular garage door opener and adding smart phone control to it.  I want to see if it is up or down and be able to open or close it from anywhere.

To start with, I have a Liftmaster 1/2 HP Security Plus motor and it has a button that I am taking apart.  The button has 2 wires going to it and it has 3 buttons on it: 1 large button for opening/closing the garage door, 1 small button for the light on the motor, and one for locking the door.  When I got the button open, the basic circuit looks like this:

Image

I’m going to guess the white wire is a GND and the red wire is either straight 24V or 24V through a pull-up resistor inside the motor.  Anyway, with the button disconnected, touching the red and white wires together will open and close the door.  That part is easy.  As for the light and the lock, my guess is there is a circuit that measures the charge up time of these capacitors and this tells the motor to activate either the light or lock.  However, what I am not seeing is a easy way to tell the current state of the garage door electronically (i.e. not just looking at it).  These controls can toggle the state, but not tell me what state I am currently in.  The nice part about these switches being in parallel is I can create my own set of switches to be controlled via Arduino, put them in parallel to this button, and then I can use either this button or Arduino to open/close the door.  I’ll likely use either a proximity or light sensor to tell me the current state of the door.