Cube follow up

I’ve been asked a few more questions about the Cube, so here is a follow up post with some answers.

Here are the previous posts with the information so far:

Questions

What toolchain did you use? 

I use Crosspack tool chain (formerly AVR MacPack) 
I also use V-USB (formerly AVR-USB) by the same author as Crosspack. This is a software USB implementation that works great in this scenario when only a small amount of information needs to be transferred.

How do you flash the chip?

I’ve created a small board powered by USB which I can insert the ATTiny into and attach an Atmel ISP mkII. Flashing the program is as simple as typing ‘make program’ from the firmware directory in the code.

 

Atmel AVR ISP mkII

Atmel AVR ISP mkII

How much did the components cost?

  • ATTiny45 £1.26
  • USB Connector £0.29 
  • LEDs approx £0.60
  • Resistors, Diodes, strip board approx £0.60

The cube itself was a freebie and I could have salvaged the LEDs. I’ve deliberately aimed to keep things simple with as few components as possible. It has cost less than £3 (~$5).

Is it fast enough to do colour fading?

Yes. It uses software PWM to create 24-bit colours. That means the LEDs are turning on and off really quickly to give the impression that they’re either bright or dim and mix in different proportions to create all the shades.

At the moment I just run the executable (in the commandline directory in the code) many times to create the fade. It wouldn’t be too complicated to extend the firmware to add smooth fading or alternatively to the command line tool.

How fast can you change the colours?

Pretty much instantly. However, it depends what you mean by ‘change’. As I mentioned before the LEDs are turning on and off constantly. You are limited by the transfer rate of the USB, but you could add colour fading in the firmware reducing he number of instructions required to change. 

Can I see more pictures?

I probably won’t revisit this project, but I promise to add more to future posts.

My cube is a bit dim how can I make it brighter?

It depends, I have build one board where I have removed the resistors protecting the LEDs as they are rated at approximately 3v. It is also possible to run LEDs at a higher voltage than their max rating if you reduce the duty cycle as described in this article.

Advertisements
Posted in ATTiny45, AVR, Electronics | Tagged , , , , , , | 8 Comments

USB caps lock fob

When building the USB mail notifier, I found this blog post describing how to build a tiny USB device that randomly turns the caps key on. One of my colleagues, Simon, particularly hates accidental caps presses, so much so that, he physically removed the key from his keyboard. This made him the ideal target for this joke.

The hardware required is very similar to the email notified I built. It is actually possible with a reprogram of the chip to use the same device. However I want to make this small enough to be hidden.

As with all my projects I’m trying to avoid making PCBs or using surface mount devices. I’m sticking with stripboard and normal sized devices. I used the same vertical mount of inline components.

I have removed the USB connector from an old memory stick and, although this is surface mount, the pins are spaced far enough apart to sit on a track each.

When all the parts a soldered and the chip is flashed I tested the device. It doesn’t seem to work on OS X, but fortunately it does on Windows.

Caps locker fob

Caps locker fob

As for Simon, he was perplexed for about 40 minutes, but saw the funny side when he figured it out 🙂

Posted in ATTiny45, AVR, build, Electronics | Tagged , , , , , | 2 Comments

LED Matrix

I’ve recently purchased a pair of 5×7 LED matrices. To learn how to use them I’ve decided to use my arduino to prototype them. I’ve downloaded the datasheet for the LEDs and I already have the arduino toolchain, so I’m ready to begin. The LEDs are in a matrix which means that you can not turn them on individually. Instead you have to strobe the LEDs at a frequency high enough that you can’t perceive any flicker and that each row or column is active at a different time.

To select each we need use a digital output for both the rows and columns. This means we need we need a total of 12 outputs. It might be possible to reduce this number further, but this will be fine as a first pass as we are not short on IO on the arduino.

The arduino has 13 digital outputs, but two are used for serial communication and I generally avoid using them as we might need them to help debug any problems. Instead I’m going to use the analog pins, which are referred to by using pin 14 to 20.

The arduino’s digital outputs deliver 5v, which is higher than the 2v required for each LED. As we are only going to drive one LED, per output, at a time the circuit decomposes to a standard series LED-resistor. I’ve calculated the value required using a web form using the information from the datasheet.

The column pins connect first to a resistor and then to the normal digital pins of the arduino. The row pins connect directly to the analog pins of the arduino.

The arduino sketch is simple to write, but care must be taken to ensure that the LEDs are on for similar durations, otherwise the will be different brightnesses. It is possible to write directly to the ports but for simplicity I’m going to just use digital write.

Here is the Arduino code, the pins (apins, cpins) need to be specified depending on how you have wired it up.

int ledPin = 13;  
int cpins[] = {15,17,18,16,19,0};
int apins[] = {6,8,7,2,5,3,4,0};
 
int pic0[] = {
  B00010000,
  B01010000,
  B00010000,
  B01010000,
  B00010000
};
 
int pic1[] = {
  B00010000,
  B01011000,
  B00011000,
  B01011000,
  B00010000
};
 
 
int pic2[] = {
  B00011000,
  B01010100,
  B00010100,
  B01010100,
  B00011000
};
 
int pic3[] = {
  B00011100,
  B01010010,
  B00010010,
  B01010010,
  B00011100
};
 
int *anim[] = { pic0, pic1, pic2, pic3, pic2, pic1, NULL };
 
void setup() 
{
  for (int i =0; apins[i]; ++i)
    pinMode(apins[i], OUTPUT); 
    
  for (int i =0; cpins[i]; ++i)
    pinMode(cpins[i], OUTPUT); 
  
}
 
int frame = 0;
unsigned long next_frame = 0;
void loop() 
{
  unsigned long time = millis();
  if (next_frame < time)
  {
    frame += 1;
    next_frame = time + 50;
    if (anim[frame] == NULL)
      frame = 0;
  }
  
  for (int j =0; cpins[j]; ++j)
  {
    for (int i =0; apins[i]; ++i)
    {
      digitalWrite(apins[i], LOW);
    }
    digitalWrite(cpins[j], LOW);
    for (int i =0; apins[i]; ++i)
    {
      digitalWrite(apins[i], anim[frame][j] & (1<<i));
    }
    digitalWrite(cpins[j], HIGH);
  }
}
LED Matrix and Arduino

LED Matrix and Arduino

Posted in Arduino, Electronics, Prototyping | Tagged , , , | 1 Comment

Building the cube

I’ve finally set about building the USB mail alert.
In my previous post, I showed the bread board prototype of my cube hack. Here is the adapted circuit diagram.

schematic

schematic

Note: There is an error in the diagram 2 is actually D+ and 3 is D-

When laying out circuits, it is a good idea to, start with the largest component first, in this case, the ATTiny45. I want to program the chip first so I am using a DIL socket. This also has the advantage of protecting the chip from excessive heat when soldering. I’d also like to use as small a board as possible so I am limiting the width to six tracks. Place all the components on the board before soldering so you can get an idea of how large the board needs to be. I followed the layout of the breadboard, however I want to make the circuit small so I have mounted the resistors and diodes vertically, with one leg bent back.

I also tried to avoid cutting tracks with the spot cutter and instead used a knife to allow components to be closer to each other. This requires a sharp knife and care must be taken to cut only one track. Soldering is also more challenging, solder sparingly, to avoid bridging across your cuts.

I cut the tracks under the chip; note that the reset pin is left disconnected. If you needed extra IO you can flash the chip to use it as such but after that you can no longer reprogram it so I avoid that as I may use the chips from previous devices in future things.

I soldered the LEDs at the end of their leads, towards the end of the PCB. This means they will be in the center of the difuser. They also have a series resistor to reduce the AVR output voltage from 3.6V to the approriate level. This resistor may not be required with some ultrabright LEDs.

To fit in the cube, I have removed the circuit, the coin cells and cover. The cube is going to be used as a cover for the new circuit so I have just cut a space using a sharp knife allowing space for the LEDs to fit into the diffuser. The circuit is slotted into the empty cube to complete the device. Plug it in and test it using the libusb command line tool, mentioned in a previous post.

The finished cube

The finished cube

Posted in ATTiny45, AVR, Electronics, Prototyping | Tagged , , , , , , , | 22 Comments

Cube Hack part II (software)

I’ve created a Google code project with the snappy title of avr-usb-rgb-led. It is based on the hid-custom-rq example from AVR usb examples. I’ve added 3 new commands, one for each LED. It uses a software PWM to control the brightness of each LED based on the value set.

There is a coresponding program using libusb which allows you to send the commands, it simply allows you to set the colour of the cube with an RGB tuple on the command line.

To get the code you need to check out using subversion. To flash the chip you probably want to use the makefile.

Posted in ATTiny45, AVR, Electronics, Firmware, Software, Uncategorized | Tagged , , , | 6 Comments

Glowing Cube Hack

One of the promotional things that Linden Lab gives away is a small colour changing, glowing cube. Last year, we attended a job fair were we gave several away. One of the people who received one decided to hack his cube and made a Gmail notifier.

I decided to copy the hack, bought myself an Arduino, and set about hacking the cube. I went for a slight improvement where I individually wired each LED. This means that using the PWM from the Arduino I was able to set the colour of the cube to whatever I chose. 

Arduino and Cube

Arduino and Cube

The main problem with this hack was the physical size of the Arduino. It’s too large to fit inside the cube. I could have attempted to use one of the smaller Arduino variants, but it would have been a bit pricey, costing about £30 for the Mini and the USB adapter.

I’d recently discovered AVR USB, which implements, USB in software, for any AVR microcontroller. USB needs two wires and I needed another 3 to control my LEDs, so even the smallest microcontroller would be enough and it doesn’t even need a crystal. AVR USB needs at least 2K of flash memory. There is an example project, EasyLogger, that uses ATTiny45 so that’s what I’ll use too.

ATTiny45

ATTiny45

The EasyLogger project is a good starting point, but I’m going to make some changes. First, I want to control the LEDs, so I replace the input voltage and start switch with a resistor LED pair. 

USB uses 2.8-3.6V for high on the data pair but provides 5V for power. Since I’m going to be powering the ATTiny from the USB I need a way to make the outputs deliver the lower voltage. The EasyLogger project uses Zener diodes to provide level conversion, but unfortunately, I don’t have any Zener diodes. 

The AVR USB provides an alternative suggestions of using a 3.3V voltage regulator for reducing the power (which again I don’t have any of) or a cheaper alternative, using a pair of normal diodes. Each diode has a drop of 0.7V so the pair drops the power voltage to 3.6V. 

Here is the first prototype circuit on my bread board. 

Breadboard prototype

Breadboard prototype

I’ll describe the code for the firmware and driver in later blog posts.

Posted in Arduino, ATTiny45, Electronics, Prototyping | Tagged , , , , , , , , | 7 Comments

Getting started with Arduino; things to buy.

A friend of mine, Simon, has recently purchased an Arduino. He asked me, “how do I get started?”. Here is a list of the things that I’d recommend you purchase and why.

LEDs

Probably the simplest output indicator you can get: the LED. You can place the LEDs directly into the Arduino, as in the Blink tutorial. They provide a simple mechanism of getting information from the Arduino to you. With the Arduino’s 13 digital outputs can drive 13 LEDs. This number can be increased using components, such as, Shift Registers or techniques like charlieplexing.

Resistors

LEDs usually have a maximum voltage of ~2V. The Arduino’s outputs are 5v. For an Arduino to be able to power an LED the voltage must be reduced to by 3V. The simplest component to do this is a resistor. To figure out which values of resistor you will need, you can, use this helpful calculator. Make sure you get ~1/4W resistors as higher wattage means bigger components!

Breadboard

When you start to make circuits more complex than Blink, you will need something to prototype circuits on. A breadboard is a a solderless way of prototyping, which can be quickly put together and reused an unlimited number of times. Depending on the type, breadboards usually have horizontal strips, a gap in the middle for DIL components, such as ICs, and a pair of power lines marked on the sides. I only have two types of board, both are small, as I don’t make very complex circuits.

Wire & cutters/strippers


You can get quite far using the component leads to prototype, but its likely you are going to want to make connections from place to place, either from Arduino to breadboard or between components on the breadboard. To use wire with breadboard it needs to be solid core. To strip and cut wire, I just use a small pair of sharp side cutters.

Buttons

Although the above button has bent legs, they can easily be straightened to fit into a breadboard. Some electronics tutorials will tell you you require ‘pull-down’ resistors to use with the switch but this is not the case for the Arduino, as it has built in resistors, that can be turned on from software. It may still be worth getting a few 10K resistors to use with your switches.

What can I do with this stuff?

There is a good introduction to Arduino on Ladyada, where you will use need the stuff above to get started. In addition, I’ve made several different projects using just the above components, including, a POV Toy, an email notifier and a colour changing light.

Where next?

When you’ve finished with this stuff, you’ll probably want to look a different kinds of sensor. You can get a huge array of different types, such as temperature, light, acceleration or even blood alcohol content! For most simple sensors, you can use the Arduino’s analog inputs, for more complicated things you might have to use a number of digital pins or possibly I2C or SPI. There is a lot to learn about sensors, but that probably another blog post.

Posted in Arduino, Electronics, Prototyping | Leave a comment

New blog

My first blog. Let’s see if I ever use it. 

It will probably be mostly programming and hardware hacking.

Recent projects I might write up include:

  • AVR prototype parts
  • Rock Band pedal Arduino
  • Caps locker device
Posted in Uncategorized | Leave a comment