Fun with retro gaming sounds and airwick air fresheners.

You know, inspiration can come from the strangest of places.

About a year ago, I spotted at my local supermarket an airwick automatic air freshener unit. It cost about $10 and I bought it right away thinking that it could be used to keep our toilet smelling nice and fresh and limit the amount of matches that are chucked in there to keep it from stinking the house out. So I arrived home from the shops with the brand new $10 automatic air freshener under my arm. And, predictably, my Mum wasn’t happy about me spending money on robotic air fresheners. I ended up having to pay for it myself. Oh well. It was still cool.

My airwick freshener thingy.

My airwick freshener thingy.

So I put in the freshener cartridge that came with the device, set it to the right mode, and left it alone. The little air freshener went off every time you walked into the toilet keeping it smelling nice. But airwick (the company that makes these) are just as bad as the printer companies. They get you on the toner, or in this case the cartridges. The cartridges cost about $10 and only last about a week or so. Needless to say, the freshener sat and collected dust with an empty cartridge just blinking its little light.  Until yesterday when I noticed it had a PIR detector mounted in the front for detecting motion.

The PIR sensor

The PIR sensor

For more on what a PIR sensor is and how it’s used see here: http://www.ladyada.net/learn/sensors/pir.html

So what am I going to build with this? A super mario brothers room greeting robot.

Let’s start by taking the freshener apart.

The back of the freshener. It looks like some sort of crashed spaceship.

The back of the freshener. It looks like some sort of crashed spaceship.

The gas cartridge in position.

The gas cartridge in position.

The gas cartridge.

The gas cartridge.

The back cover with the batteries out exposing two screws.

The back cover with the batteries out exposing two screws.

The circuit board and it's plugs. The PIR is on the other side of the PCB.

The circuit board and it's plugs. The PIR is on the other side of the PCB.

A very nice looking PCB with the PIR, switches and some handy connectors.

A very nice looking PCB with the PIR, switches and some handy connectors.

After disassembling the device I wanted to find out how the PIR is wired up on this particular device. To do this I used this tutorial on hacking the airwick fresheners found here:

http://www.instructables.com/id/Re-purposing-an-Air-Wick-Freshmatic-Compact-i-Moti/step3/Approach-1-Digitized-Sensor-Output-Simplest-way/

It was a very simple procedure and worked straight away. Thanks for posting your method Doug! Here’s a picture of my finished hack.

The white wire is the modification.

The white wire is the modification.

I tested it using the code found on the ladyada PIR tutorial mentioned above. It worked fine and was surprisingly good at detecting people. So now I have the sensor and I’m ready to put a little music into this project. Here’s what I used for the music: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1253920105 (the RTTTL example). The music sounded surprisingly good and is pretty easy to modify. I shortened the mario song by referencing the sheet music found here: http://www.mariopiano.com/mario-sheet-music-overworld-main-theme.html . Once I had figured out which bit of the song I wanted I simply lopped off the bit I didn’t need and was left with this RTTTL text:

char *song = “smb:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g,”;

It’s much shorter than the original code from the arduino forum. You can load any RTTTL ringtone into it so it’s not like this thing is limited to playing super mario bros. Cool. Now to bring it all together.

I did this by modifying the bottom section of the RTTTL example to this:

void loop(void)
{
//I chose pin 2 to read the PIR signal
  if (digitalRead(2) == (LOW)){
      play_rtttl(song);
      delay(5000); //delay to make sure it doesn't go off too often.
  }
}

Now that I have the code so that it only plays the song when the sensor detects motion, I can show you a video of it working. This a pretty cool project and is a fun addition to any room. Here’s the hastily made video (made on my mobile phone because my HD webcam isn’t working with youtube):

It could also be used for something like this: http://www.youtube.com/watch?v=cbEKAwCoCKw .

A very retro one-day project:

The finished project with the PIR in it's case.

The finished project with the PIR in its case.

Cool. My room is now complete with retro gaming noises.

Here’s the full version of the code because it was requested:

//Below is a modified version of the example RTTTL sketch that I used to power the project.
//You need to have the tone library installed. 

// A fun sketch to demonstrate the use of the Tone library.

// To mix the output of the signals to output to a small speaker (i.e. 8 Ohms or higher),
// simply use 1K Ohm resistors from each output pin and tie them together at the speaker.
// Don't forget to connect the other side of the speaker to ground!

// You can get more RTTTL (RingTone Text Transfer Language) songs from
// http://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation

#include <Tone.h>

Tone tone1;

#define OCTAVE_OFFSET 0

int notes[] = { 0,
NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4,
NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5,
NOTE_C6, NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, NOTE_AS6, NOTE_B6,
NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7, NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7
};

//char *song = "The Simpsons:d=4,o=5,b=160:c.6,e6,f#6,8a6,g.6,e6,c6,8a,8f#,8f#,8f#,2g,8p,8p,8f#,8f#,8f#,8g,a#.,8c6,8c6,8c6,c6";
//char *song = "Indiana:d=4,o=5,b=250:e,8p,8f,8g,8p,1c6,8p.,d,8p,8e,1f,p.,g,8p,8a,8b,8p,1f6,p,a,8p,8b,2c6,2d6,2e6,e,8p,8f,8g,8p,1c6,p,d6,8p,8e6,1f.6,g,8p,8g,e.6,8p,d6,8p,8g,e.6,8p,d6,8p,8g,f.6,8p,e6,8p,8d6,2c6";
//char *song = "TakeOnMe:d=4,o=4,b=160:8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5,8f#5,8e5,8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5";
//char *song = "Entertainer:d=4,o=5,b=140:8d,8d#,8e,c6,8e,c6,8e,2c.6,8c6,8d6,8d#6,8e6,8c6,8d6,e6,8b,d6,2c6,p,8d,8d#,8e,c6,8e,c6,8e,2c.6,8p,8a,8g,8f#,8a,8c6,e6,8d6,8c6,8a,2d6";
//char *song = "Muppets:d=4,o=5,b=250:c6,c6,a,b,8a,b,g,p,c6,c6,a,8b,8a,8p,g.,p,e,e,g,f,8e,f,8c6,8c,8d,e,8e,8e,8p,8e,g,2p,c6,c6,a,b,8a,b,g,p,c6,c6,a,8b,a,g.,p,e,e,g,f,8e,f,8c6,8c,8d,e,8e,d,8d,c";
//char *song = "Xfiles:d=4,o=5,b=125:e,b,a,b,d6,2b.,1p,e,b,a,b,e6,2b.,1p,g6,f#6,e6,d6,e6,2b.,1p,g6,f#6,e6,d6,f#6,2b.,1p,e,b,a,b,d6,2b.,1p,e,b,a,b,e6,2b.,1p,e6,2b.";
//char *song = "Looney:d=4,o=5,b=140:32p,c6,8f6,8e6,8d6,8c6,a.,8c6,8f6,8e6,8d6,8d#6,e.6,8e6,8e6,8c6,8d6,8c6,8e6,8c6,8d6,8a,8c6,8g,8a#,8a,8f";
//char *song = "20thCenFox:d=16,o=5,b=140:b,8p,b,b,2b,p,c6,32p,b,32p,c6,32p,b,32p,c6,32p,b,8p,b,b,b,32p,b,32p,b,32p,b,32p,b,32p,b,32p,b,32p,g#,32p,a,32p,b,8p,b,b,2b,4p,8e,8g#,8b,1c#6,8f#,8a,8c#6,1e6,8a,8c#6,8e6,1e6,8b,8g#,8a,2b";
//char *song = "Bond:d=4,o=5,b=80:32p,16c#6,32d#6,32d#6,16d#6,8d#6,16c#6,16c#6,16c#6,16c#6,32e6,32e6,16e6,8e6,16d#6,16d#6,16d#6,16c#6,32d#6,32d#6,16d#6,8d#6,16c#6,16c#6,16c#6,16c#6,32e6,32e6,16e6,8e6,16d#6,16d6,16c#6,16c#7,c.7,16g#6,16f#6,g#.6";
//char *song = "MASH:d=8,o=5,b=140:4a,4g,f#,g,p,f#,p,g,p,f#,p,2e.,p,f#,e,4f#,e,f#,p,e,p,4d.,p,f#,4e,d,e,p,d,p,e,p,d,p,2c#.,p,d,c#,4d,c#,d,p,e,p,4f#,p,a,p,4b,a,b,p,a,p,b,p,2a.,4p,a,b,a,4b,a,b,p,2a.,a,4f#,a,b,p,d6,p,4e.6,d6,b,p,a,p,2b";
//char *song = "StarWars:d=4,o=5,b=45:32p,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#.6,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#6";
//char *song = "GoodBad:d=4,o=5,b=56:32p,32a#,32d#6,32a#,32d#6,8a#.,16f#.,16g#.,d#,32a#,32d#6,32a#,32d#6,8a#.,16f#.,16g#.,c#6,32a#,32d#6,32a#,32d#6,8a#.,16f#.,32f.,32d#.,c#,32a#,32d#6,32a#,32d#6,8a#.,16g#.,d#";
//char *song = "TopGun:d=4,o=4,b=31:32p,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,16f,d#,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,g#";
//char *song = "A-Team:d=8,o=5,b=125:4d#6,a#,2d#6,16p,g#,4a#,4d#.,p,16g,16a#,d#6,a#,f6,2d#6,16p,c#.6,16c6,16a#,g#.,2a#";
//char *song = "Flinstones:d=4,o=5,b=40:32p,16f6,16a#,16a#6,32g6,16f6,16a#.,16f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c6,d6,16f6,16a#.,16a#6,32g6,16f6,16a#.,32f6,32f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c6,a#,16a6,16d.6,16a#6,32a6,32a6,32g6,32f#6,32a6,8g6,16g6,16c.6,32a6,32a6,32g6,32g6,32f6,32e6,32g6,8f6,16f6,16a#.,16a#6,32g6,16f6,16a#.,16f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c.6,32d6,32d#6,32f6,16a#,16c.6,32d6,32d#6,32f6,16a#6,16c7,8a#.6";
//char *song = "Jeopardy:d=4,o=6,b=125:c,f,c,f5,c,f,2c,c,f,c,f,a.,8g,8f,8e,8d,8c#,c,f,c,f5,c,f,2c,f.,8d,c,a#5,a5,g5,f5,p,d#,g#,d#,g#5,d#,g#,2d#,d#,g#,d#,g#,c.7,8a#,8g#,8g,8f,8e,d#,g#,d#,g#5,d#,g#,2d#,g#.,8f,d#,c#,c,p,a#5,p,g#.5,d#,g#";
//char *song = "Gadget:d=16,o=5,b=50:32d#,32f,32f#,32g#,a#,f#,a,f,g#,f#,32d#,32f,32f#,32g#,a#,d#6,4d6,32d#,32f,32f#,32g#,a#,f#,a,f,g#,f#,8d#";
//char *song = "Smurfs:d=32,o=5,b=200:4c#6,16p,4f#6,p,16c#6,p,8d#6,p,8b,p,4g#,16p,4c#6,p,16a#,p,8f#,p,8a#,p,4g#,4p,g#,p,a#,p,b,p,c6,p,4c#6,16p,4f#6,p,16c#6,p,8d#6,p,8b,p,4g#,16p,4c#6,p,16a#,p,8b,p,8f,p,4f#";
//char *song = "MahnaMahna:d=16,o=6,b=125:c#,c.,b5,8a#.5,8f.,4g#,a#,g.,4d#,8p,c#,c.,b5,8a#.5,8f.,g#.,8a#.,4g,8p,c#,c.,b5,8a#.5,8f.,4g#,f,g.,8d#.,f,g.,8d#.,f,8g,8d#.,f,8g,d#,8c,a#5,8d#.,8d#.,4d#,8d#.";
//char *song = "LeisureSuit:d=16,o=6,b=56:f.5,f#.5,g.5,g#5,32a#5,f5,g#.5,a#.5,32f5,g#5,32a#5,g#5,8c#.,a#5,32c#,a5,a#.5,c#.,32a5,a#5,32c#,d#,8e,c#.,f.,f.,f.,f.,f,32e,d#,8d,a#.5,e,32f,e,32f,c#,d#.,c#";
//har *song = "MissionImp:d=16,o=6,b=95:32d,32d#,32d,32d#,32d,32d#,32d,32d#,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,a#,g,2d,32p,a#,g,2c#,32p,a#,g,2c,a#5,8c,2p,32p,a#5,g5,2f#,32p,a#5,g5,2f,32p,a#5,g5,2e,d#,8d";
//char *song = "SMBUndergr:d=16,o=6,b=100:c,c5,a5,a,a#5,a#,2p,8p,c,c5,a5,a,a#5,a#,2p,8p,f5,f,d5,d,d#5,d#,2p,8p,f5,f,d5,d,d#5,d#,2p,32d#,d,32c#,c,p,d#,p,d,p,g#5,p,g5,p,c#,p,32c,f#,32f,32e,a#,32a,g#,32p,d#,b5,32p,a#5,32p,a5,g#5";
char *song = "smb:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g,";
 void setup(void)
{
  Serial.begin(9600);
  tone1.begin(13);
}

#define isdigit(n) (n >= '0' && n <= '9')

void play_rtttl(char *p)
{
  // Absolutely no error checking in here

  byte default_dur = 4;
  byte default_oct = 6;
  int bpm = 63;
  int num;
  long wholenote;
  long duration;
  byte note;
  byte scale;

  // format: d=N,o=N,b=NNN:
  // find the start (skip name, etc)

  while(*p != ':') p++;    // ignore name
  p++;                     // skip ':'

  // get default duration
  if(*p == 'd')
  {
    p++; p++;              // skip "d="
    num = 0;
    while(isdigit(*p))
    {
      num = (num * 10) + (*p++ - '0');
    }
    if(num > 0) default_dur = num;
    p++;                   // skip comma
  }

  Serial.print("ddur: "); Serial.println(default_dur, 10);

  // get default octave
  if(*p == 'o')
  {
    p++; p++;              // skip "o="
    num = *p++ - '0';
    if(num >= 3 && num <=7) default_oct = num;
    p++;                   // skip comma
  }

  Serial.print("doct: "); Serial.println(default_oct, 10);

  // get BPM
  if(*p == 'b')
  {
    p++; p++;              // skip "b="
    num = 0;
    while(isdigit(*p))
    {
      num = (num * 10) + (*p++ - '0');
    }
    bpm = num;
    p++;                   // skip colon
  }

  Serial.print("bpm: "); Serial.println(bpm, 10);

  // BPM usually expresses the number of quarter notes per minute
  wholenote = (60 * 1000L / bpm) * 4;  // this is the time for whole note (in milliseconds)

  Serial.print("wn: "); Serial.println(wholenote, 10);


  // now begin note loop
  while(*p)
  {
    // first, get note duration, if available
    num = 0;
    while(isdigit(*p))
    {
      num = (num * 10) + (*p++ - '0');
    }
    
    if(num) duration = wholenote / num;
    else duration = wholenote / default_dur;  // we will need to check if we are a dotted note after

    // now get the note
    note = 0;

    switch(*p)
    {
      case 'c':
        note = 1;
        break;
      case 'd':
        note = 3;
        break;
      case 'e':
        note = 5;
        break;
      case 'f':
        note = 6;
        break;
      case 'g':
        note = 8;
        break;
      case 'a':
        note = 10;
        break;
      case 'b':
        note = 12;
        break;
      case 'p':
      default:
        note = 0;
    }
    p++;

    // now, get optional '#' sharp
    if(*p == '#')
    {
      note++;
      p++;
    }

    // now, get optional '.' dotted note
    if(*p == '.')
    {
      duration += duration/2;
      p++;
    }
  
    // now, get scale
    if(isdigit(*p))
    {
      scale = *p - '0';
      p++;
    }
    else
    {
      scale = default_oct;
    }

    scale += OCTAVE_OFFSET;

    if(*p == ',')
      p++;       // skip comma for next note (or we may be at the end)

    // now play the note

    if(note)
    {
      Serial.print("Playing: ");
      Serial.print(scale, 10); Serial.print(' ');
      Serial.print(note, 10); Serial.print(" (");
      Serial.print(notes[(scale - 4) * 12 + note], 10);
      Serial.print(") ");
      Serial.println(duration, 10);
      tone1.play(notes[(scale - 4) * 12 + note]);
      delay(duration);
      tone1.stop();
    }
    else
    {
      Serial.print("Pausing: ");
      Serial.println(duration, 10);
      delay(duration);
    }
  }
}

void loop(void)
{
//I chose pin 2 to read the PIR signal
  if (digitalRead(2) == (LOW)){
      play_rtttl(song);
      delay(5000); // wait 50 seconds for me so it doesn't endlessly loop.
  }
}
Advertisements

Things to do.

So yesterday I got all obsessed with 3d printers. I wanted one soooo bad. So I tried to build 3D CNC (computer controlled cutter) out of lego robotics. I’ve done this before and failed ( this guy has succeeded). But this time around I had more gears and thought I might succeed. But I didn’t. I had really precise X and Y axes. But one side of the X- axis was dragged along by the other and couldn’t be fixed without adding a lot more gears which I don’t have. I might try a different design. Or I guess I better start saving for a $1299 makerbot. Or maybe I should build an eggbot instead.

Speaking of 3D printers, this exclusive interview with bre pettis by make is pretty interesting. Bre is the guy who started Makerbot Industries and is an interesting example of how you can make what you love doing as a hobby a full time job. He recently got $10 million dollars in funding from VCs and has sold a lot of printers so he’s a pretty happy guy. Check it out here: http://blog.makezine.com/archive/2011/10/makes-exclusive-interview-with-bre-pettis-of-makerbot-life-10m-in-funding-and-beyond.html

 

Tomorrow I’m going to Make Hack Void to work on some infrared hacking with my robosapien. These are seriously cool old toy robots that aren’t really all that intelligent and rely on humans to tell them what to do via remote control. If I can decode the infrared protocol that robosapiens use then I can control them using an arduino. I can then use the arduino to pass commands from the internet to the robot. This allows for both phone and computer control wirelessly. Then I want to build a little enclosure and webcam setup that lets anybody drive one of these robots using the internet. Kind of like a robotic version of one of the many RC cars around that anyone can control. I’d have it running for a week and film the results. But first I have to decode the infrared.

On the topic of internet controlled stuff I’m thinking about making my room phone controlled. And the whole google ADK usb host thing doesn’t look like it works with that much stuff yet so I think I’m going to take a different approach. I’d probably go with a browser based control application to allow me to switch on and off lights and power as well as music etc. One of the simpler ideas for doing cool lighting control was getting one of these and hacking what appears to be it’s infrared remote control system. That way I can control high powered RGB lighting without having to mess around with dangerous high voltage. I was also thinking of using something like a power switch tail to turn on and off other devices. And I might get some solenoids so I can have a phone controlled door lock. But if my phone went flat and my charger was in my room I would be a bit stuffed. Maybe I should build something like this instead for security.

When you think about it infrared is not as old fashioned and useless as it sounds. It can be used to control cheap chinese helicopters, humanoid robots, speakers and even DSLR cameras. So it’s actually pretty useful knowing how to use infrared protocols. Hence me wanting to learn more.

I really want to get into some programming to display some arduino data (like my synthesizers levels) visually in a computer application. I was thinking of learning processing as it seems to be a common choice for this sort of stuff. It’s open source and has a lot of cool example projects on it’s website. However, the arduino IDE is based on processing and it’s as slow as a turtle. I think that’s because it’s based on Java.

A while back i wrote for a magazine called aviator about my first flying lesson. I wrote an article because I went to a holiday school thing about how writing for magazines can make you a lot of money. I didn’t get anything for my article. But I keep on reading things in magazines like Make: and Popular Science on stuff that interests me. And there will always be something that I wish they wrote more about or something they didn’t include that’s really cool and would fit right in. I’ve got one week of holidays left so I might write something up on electronics. Maybe.

Here’s a cool project I saw recently

Looks like I’ve got a lot of stuff I can be doing. Better do it.

Bike light.

I’ve got a little 7-segment LED display lying around that I thought I might put to some use. But doing what? Well, yesterday I had a eureka moment as I was riding along with my training squad. I came up with the idea of using the 7-segment display to display messages on the back of my bike like temperature, speed, slogans,etc. You can’t use an LCD to do this because they are blue or green (except for the sparkfun ones) and a light on the back of a bike needs to be red. Why not build something more interesting than the usual flasher or scanner that are sold in bike shops?

I decided that my initial goal was going to be to make the display show the words: CCC, DEV, SQD which is short for Canberra Cycling Club Development Squad. Not that that’s the group I’m in or anything. If I do complete this project (as in temperature, serial message programming etc) I plan to get a PCB done so I can stow the electronics under my saddle and put the display on the seatpost. Maybe even make a kit…..

The project in action

The project in action

One of the first things you may notice about this photo is that the display appears to be powered by a little black chip. Don’t freak out, it’s just an atmega328 chip (the arduino 8 bit core) by itself. Here’s a tutorial if you don’t get it: http://arduino.cc/en/Tutorial/ArduinoToBreadboard . I’m still using an arduino board without the chip for programming and power. I think my FTDI standalone chip is dead. Let’s move on to the display.

 

Getting one of these displays working is not nearly as hard as getting an LCD working. Well at least not in my experience. However they are not that simple. They require 4 transistors and 12 digital logic pins to work. 4 of the pins on the display connect to ground. If, for example, the first ground pin is connected to ground the first number lights up. If the 3rd ground pin is connected the 3rd number lights up. When I say that the number lights up I do not mean that all 7 segments of the number light up, instead I mean that the segments of that number are able to light up. We can do this switching using BC547 transistors. I know it’s confusing. I’m doing my best.

Cool, you say, all I have to do is give power to the parts of the number I want to light up and the number (using the transistor) I want to light up. So how come there’s only 12 pins if there’s 4 numbers with 8 (there’s actually 8 segments if you include the decimal) segments? Because you can only light up all the numbers with the same pattern. So you can only display 4444 not 5672. This is because the number 4 appears on all the numbers no matter what you try and do. That’s why there’s only 12 pins. 8 segments and 4 numbers. This limits you to being able to display numbers like: 3,44,4444,555,22,1 etc. You can turn on and off how many numbers are displayed (1,111,1111) but you can only display the same number (1). If this doesn’t make sense leave a comment.

So how do you display number like 6785? Easy. You pulse the digits too fast for the human eye to see. You turn off all the numbers. Then you turn on one number with one pattern (set of segments like 5, 6, or 3). Then you turn off the number. Then you turn on the next number with a different pattern. And so on. Let’s look at the code for CCC, DEV, SQD.

int time = 0;
int count;
void setup() {
//SEGMENTS
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(0, OUTPUT);
//SEGMENT CONTROL
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);
  pinMode(A4, OUTPUT);

}
void loop(){
  time = 3;

//ccc
if (count<100){
  digitalWrite (A1,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (A1,LOW);

digitalWrite (A2,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (A2,LOW);

digitalWrite (A3,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (A3,LOW);

digitalWrite (A4,HIGH);
delay(time);
digitalWrite (A4,LOW);

}
if (count>100){
  if (count>200){
    goto a;
  }
  //letter D
digitalWrite (A1,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (2, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (2, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (6, LOW);
digitalWrite (A1,LOW);

  //letter E
digitalWrite (A2,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
digitalWrite (7, HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (7, LOW);
digitalWrite (A2,LOW);
 //letter V
 digitalWrite (A3,HIGH);
digitalWrite (1, HIGH);
digitalWrite (2, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
delay(time);
digitalWrite (1, LOW);
digitalWrite (2, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (6, LOW);
digitalWrite (A3,LOW);
}
a:
if (count>200){
  //letter S
digitalWrite (A1,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
digitalWrite (7,HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (4, LOW);
digitalWrite (6, LOW);
digitalWrite (7,LOW);
digitalWrite (A1,LOW);
  //letter Q
 digitalWrite (A2,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (2, HIGH);
digitalWrite (6, HIGH);
digitalWrite (7,HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (2, LOW);
digitalWrite (6, LOW);
digitalWrite (7,LOW);
digitalWrite (A2,LOW); 


//letter D
digitalWrite (A3,HIGH);
digitalWrite (0, HIGH);
digitalWrite (1, HIGH);
digitalWrite (2, HIGH);
digitalWrite (3, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
delay(time);
digitalWrite (0, LOW);
digitalWrite (1, LOW);
digitalWrite (2, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (6, LOW);
digitalWrite (A3,LOW);
}
if (count>300){
count = 0;
}
count++;
}

In this case I am using analog pins A1, A2, A3 and A4 to do the transistor switching. I am using digital pins 0 to 7 to power the segments. It’s very long and tedious. That’s because the arduino has to turn on and off each part of the number matrix individually. I’m working on a shorter more algorithmic version and help would be appreciated from someone who’s done this before. Maybe there’ll be someone at MHV.Then again, it does only weigh in at around 2,000 bytes. But it’s unwieldy.

Anyway, you can see that I have achieved the illusion of lighting up different number combinations by turning on and off parts of the display (using the transistors as switches) really fast. Almost 16.000 MHZ fast. Now I know that doesn’t sound very fast compared to modern computers but it’s more than enough for this. That’s one of the cool things about the arduino. Less is more. Now I’m going to try and write something cleaner and more powerful. But at least I’ve achieved my initial goal. I’ll also do up a fritzing diagram at some point. I know all that sounded pretty confusing so if you don’t understand please leave a comment and I’ll get right back to you.

It’s alive!

Breadboard Arduino

Please behold a photograph of my very first working breadboard arduino.

My first breadboard arduino.

My first breadboard arduino.

It’s shown blinking through some LED’s that came free with my arduino duemilanove from icy labs. What a great freebie! I finally able to make the breadboard arduino because the duemilanove supports bootloading. I also got a uno because I want to investigate its USB HID features. The little red chip on the breadboard is an FTDI USB to serial converter that I’m just using for 5V power from the USB hub on my computer. I can now fully embed arduino projects for around $7. Sweet. I might build a space invader bike light or something now I know this works…

Make, Hack, Void

Last night I went to the “Maker Meetup” of the local hackerspace Make, Hack, Void. It was probably the most friendly club/ group of people I have ever met. I took along my synthesizer project and at least 5 of them all lined up to have a go. I was going to get some help with decoding the infrared of my robosapien but I didn’t get time. There were a few interesting talks on their hackerspace opening times twitter notifier thingy and a glove keyboard device made from shape-lock. Both were really interesting with good questions put forward and answered. It was my first experience of a hackerspace and I definitely want to go again. Thanks so much MHV, I had a great night.

Synthesizer

As I mentioned above the synthesizer was a hit at MHV with a lot of people trying it out. However, it wasn’t really all that audible because I only took a tiny little 8 ohm speaker. Oh well. I’ll probably do up a stripboard design for it (as a lot of people suggested) and make fully soldered version that won’t involve any loose development board hanging off a breadboard.

The synth prototype

After much stuffing around last week I can now tell you that I have built a fully functioning tape player synth prototype.It took about half an hour to build. And it sounds awesome. Really awesome. I’ll upload a proper hacker/maker style video of this working in the next week. I call it a prototype because it has an etherten board for brains which I plan to use for other things and it messy and extremely dodgy.

The back.

So the back has a speaker if you don’t have a big one to plug it into or can’t be bothered lugging one around and two wires for hooking it up to big speakers. There is a usb cable for power and programming.

The guts of the project.

Inside there is a rats nest of wires along with an arduino clone board. The original potentiometers are connected to the etherten’s power, ground and analog inputs. Here’s the extremely small amount of code that powers this project:

int note = 100;
int beat = 50;
int length = 10;
int pin = 9;

void setup() {
  pinMode(pin, OUTPUT);
}

void loop() {
  note= analogRead(0);
  length= analogRead(1);
  beat= analogRead(2);
  tone (pin,note);
  delay(length);
  noTone (pin);
  delay(beat);
   }

Analog pin 0,1 and 2 are hooked up to the potentiometers and read the changing voltages which is then output as sound. This makes the synth sound like not much fun to use but I can assure you it is. The atmega328 chip sometimes stuffs up the readings with interesting blips popping up every now and again. Certain combinations of voltages bring out these blips in full force providing a kind of random tone generator. There are a lot more imperfections allowing for weird sounds to be made using the synth. This is probably the most fun thing to use I have built with electronics. I promise I will upload a video in due course (probably some time this week) as it is a bit hard to convey sound with words and images. This thing is so much fun to use.

Arduino issues.

More Stuff

Here’s some stuff I’m buying tonight. The other stuff has already arrived and works (5x atmega328s and an FTDI).

The real deal Arduino Uno. I decided to stop being cheap and buying ebay stuff and buy the real thing to support the arduino project. I also needed to get an arduino that supports removing the chip as my current freetronics etherten has an SMD atmega328. This limits the hackability of the board as you can not utilise the atmega8u2 on the board other than using it with the SMD chip. http://littlebirdelectronics.com/products/arduino-uno 

The real deal.

The real deal.

But I am still a cheap guy so I’m buying some more parts from my beloved ebay. There are actually red, green and blue LEDs in this kit enabling me to make my own RGB lights and whatever else I can think of with the large amount of parts. http://www.ebay.com.au/itm/Arduino-DIY-Starter-Kit-lcd-Relay-Stepper-Infrared-1602-/160651462842?pt=LH_DefaultDomain_0&hash=item256792c8ba#ht_4278wt_1270 

Everything you need.

Everything you need.

The last thing I’m buying is an ebay arduino duemilanove. Now don’t say I’m being a hypocrite by being all high and mighty about buying the real arduino uno and then buying a fake one. The reason I’m buying a duemilanove from ebay is that the duemilanove isn’t available from genuine retailers like little bird electronics any more. I want to get duemilanove because they have an onboard FTDI and are compatible with the AVR ISP sketch. The Arduino Uno is still quite a cool board as it features HID device support by using an atmega8u2 instead of an FTDI. This means it can show up as a keyboard or mouse or whatever. http://www.ebay.com.au/itm/Arduino-Duemilanove-ATMega328-STOCK-OZ-/260763561062?pt=AU_Components&hash=item3cb6b82c66#ht_603wt_1037

Arduino duemilanove. A more hacker friendly board.

Arduino duemilanove. A more hacker friendly board.

Arduino issues.

Leonardo.

This new board released by the arduino team is obviously a revolution in that it allows for lower costs and simpler design. This was to make it easier for people to design and produce their own arduino compatible products. At least that’s how it seems.The leonardo features an atmega8u2 at the core of it’s design meaning that it only needs one chip as the atmega8u2 has USB support built in. This is to make it easier for people to understand and modify the arduino. However, I don’t think that is true. Here’s why:

  1. The leonardo comes with an SMD chip. That means you can’t remove it and embed it in your own projects.
  2. There’s not much out there about the atmega8u2 as a programmer. Everyone just kind of left it alone in their unos. Everbody knows how to use FTDIs to program. Not atmega8u2s.
  3. The atmega8u2 is not available in a DIP package meaning that it is harder to make your own prototype of dev boards.

So in my opinion the new leonardo is anything but hacker friendly. The chip can’t be embedded and the programming nobody understands but hey, let’s wait and see.

Uno

In the days of the duemilanove everyone could load bootloaders and program standalone chips using the FTDI on the board. With the uno, you can’t program any chips that don’t have the arduino optiboot. No worries, you say, I’ll just bootload the chips using the AVR ISP sketch. The new arduino uno doesn’t support that sketch without some hacks that don’t seem to work. Hmmmmm. You can’t program a chip on the board without using a bootloader that the board can’t load. With the duemilanove you can program and bootload pain-free.

However, the arduino uno does have HID support meaning it can talk to the computer as if it is a mouse, keyboard or anything else that plugs in over USB. This is achieved by using the atmega8u2 to talk to the computer. The leonardo has the same feature.

The uno is a pretty cool board. I just prefer the duemilanove.

Cool. I’ve got some awesome stuff planned for the holidays like building my synth, retro game controllers and other stuff.

FTDI, OHS, BEAM bots and the new Arduinos

New Stuff

FTDI from sparkfun

FTDI from sparkfun. I can now keep arduino projects.

On Sunday night I ordered some new chips and an FTDI. I got 5 atmega328s with the uno bootloader and a sparkfun FTDI. Here’s the process I went through to get this stuff.

  1. Right, I’ve got $50 for my birthday. What am I going to spend it on? Electronics of course.
  2. What electronics? Arduino.
  3. I want to get some chips so I can keep my arduino projects instead of having to take them apart.
  4. Little Bird Electronics has some atmega328s with the arduino uno bootloader on them for $6. Sweet. I’ll get some of those and an FTDI.
  5. But the new bootloader isn’t compatible with the FTDI chip. Damn. I’ll just get blank chips.
  6. But I only have an etherten. Which can’t bootload atmega328s because it is an Arduino Uno clone. See here for more: http://arduino.cc/en/Tutorial/ArduinoISP and have a look at the NOTE: section.
  7. I looked around and it appears you can bootload chips with a uno if you use a resistor to kill the auto reset function. http://electronics.stackexchange.com/questions/10587/how-to-burn-atmega328-chip-via-arduino-uno-as-isp
  8. And you can modify the arduino uno bootloader to accept FTDI. http://code.google.com/p/optiboot/issues/detail?id=28
  9. Sweet. Chips ordered for $50. I’ll do the hack to make the arduino uno able to bootload the atmega328 with the hacked bootloader.

What I’m doing in electronics at school

At school we’re currently building BEAM bots which are basically solar powered small electronic robots. Today I just built a simple 5V solar engine which will power an atmega328 to play the super mario bros theme on a piezo. Awesome environmentally friendly retro gaming robot problem solved. Once I finish that I can do whatever the hell I like. Like my synth.

Make, Hack, Void

There’s this awesome place in Canberra known as Make, Hack, Void. But I’ve never been because I have always been to scared of being too young etc, etc. So I said on my twitter that I was thinking of going as a kind of probe to they might feel about it. And they said they’d love me and my synth to come on Oct 4. Looks like I’ve got a deadline to finish the synth.

Open Source Stuff that’s happened recently

  1. New Arduino boards. There’s not much out there about them but they are pretty cool. And nobody has actually well, you know, used one. But they’re pretty cool and they’ve finally made something low-cost with the release of the leonardo.
  2. OHS. What looked like a really cool meeting where lots of people talked about Arduino and chips instead of crapping on about linux as they usually do at open-source things. I’d go just to get the bag of goodies.
  3. World Maker Faire. A big meeting of all the people who make stuff. It even has it’s own iPhone app. The radio shack tent looked pretty cool. There should be one in Australia.

Why I am not making something in this blog post

Because I’m waiting for chips to work on my synth as an embedded project. I don’t want to start using my etherten and have it all finished only to discover the chips don’t work.

Why does the blog look different?

Because I got bored.

Three bad jokes

Why are pirates called pirates? Because they ARRRRRRRRR!

Why don’t you dress in front of a computer? Because it has windows.

I can’t think of a third. It’s your turn.

That’s about all I can think of for now. I’ll write something when I get the new chips.