Noe’s Juke Box | Introduction

Time has gone by since my first post about the sound box… I already wrote a couple of articles about the button pad here, here and here. I finaly came up with something. I did build an autonomous sound box which can act as a piano or act like an MP3 player.

It is based on an Arduino Mega, a Sparkfun’s 4×4 button pad and its associated PCB, anamplified Adafruit’s Music Maker, and a Sparkfun’s MMA8452 triple axis accelerometer breakout board.

There are 3 modes which are demonstrated in the following videos

Player mode

In this mode, you first select a “bank” and then a file to play. Sound / music files are stored and the SD card inserted in the Adafruit’s Music Maker. File is read from the SD and played by the VS1053.

 

Piano Mode

Here, I use the MIDI mode of the VS1053. You first select a “bank”. Each bank has a specific set of sounds mapped to pad buttons.

 

Tilt Mode

This mode is quite simple for now : the light is moving using Sparkfun’s MMA8452 triple axis accelerometer data.

 

What’s next

In following posts, I will go into details of the Sound Box, hardware and software, how to assemble everything…

There is plenty of stuff that could be done : voice or music recorder using microphone input on the music maker, piano record mode, more advanced tilt game, “simon says” game…

WiDo first impressions

I received my WiDos ! Three of them. They were out of stock so I had to wait a few more days after order but they eventually arrived through DHL delivery after one week of patience. I had to pay french taxes in addition the product price. Fair enough : I was warned !WiDo unboxed

The WiDo is an Arduino Leonardo compatible board including a Wifi chip and an SD card reader. It should be noted that some on the pins are used by either the wifi or the SD card : pins D4, D5, D7 and D10 are not available. Also, the wifi chip is using SPI top communicate with the microcontroller.

The Jorjin WG1300 seems to be based on the TI CC3000 chip. So it work with the Adafruit CC3000 library. There is also a WiDo fork for the library but it seems there is no change to the library itself. Only examples are updated (changing IRQ pin from 3 to 7) or created (Xively…)

I stuck to the the Adafruit original. I just loaded the buildtest example, changed IRQ pin, set my Wifi SID and WPA password… and it worked like a charm !

The only problem I have with one on the board is the mis-alignment of some headers.WiDo mis aligned headersIt is not preventing the board to work but you can’t use shields as they won’t fit. I may try to re-solder the header.

So, at around 25€, the WiDo is a great replacement for an Arduino + Wifi shield which costs around 70€ ! And it works just like the Adafruit CC3000 Wifi shield.

The next step is to port the Wifridge on WiDo.

By the way, official documentation is here.

 

 

Sparkfun’s 4×4 Button & LED Matrix – Part 3 – Playing with the pad

In previous posts, we saw how to assemble the pad and how to connect it to an arduino MEGA and use a very simple program to switch led on and of using the keypad. Now, this is getting a bit more complex as we will :

  • detect simultaneous key press (up to 10)
  • use key status (PRESSED, HOLD, RELEASED and IDLE) to do stuff
  • lights up multiple leds with different colors

What the program will do

On startup, it will lights up every led in red, green, blue and white successively. It is just a test to verify that the 3 RGB pins of all leds are properly wired to the arduino.

Then, it will lights up all leds at once with random colors.

Then, when using a key :

  • If the led off
    • When key is pressed, led will be switched on with a random color
    • if the key is not held long enough, the led will be switched off when the key is released
    • if the key is held long enough, when it is released, led will stay on
  • If the led is on
    • When key is pressed, led color will change
    • if the key is not held long enough, the led will be switched off when the key is released
    • if the key is held long enough, when it is released, led will stay on with the new color

Not really usefull… but it should show how all this works and get you started the the pad !

Detecting multiple key press

No magic here : I simply used Keypad library from Arduino’s playground. I used the MultiKey example provided with the library to get my code working.

How to get all leds switched on with different colors

4×4 led matrix (more specifically Sparkfun’s 4×4 led matrix) requires :

  • 3 x 4 PMW pins that is 3 pins per row of 4 leds (against 3×16=48 PWM pins if each led was to be controlled individually)
  • 4 ground pins (against 16 pins…)

(See here for some details on RGB leds and have a look here for PWM pins.)

Let say PWM pins are rows and GND pins are columns

4x4 button pad sample with pins

If you want to make the B2 led red, then you just set D5 to 255 and D32 to LOW.

4x4 button pad sample 1 red

But, although requiring much less pins, matrix have some drawbacks :  what if you want to ligh up B2 and C3 and also B2 to be red and D2 to be green ? All at the same time ?

4x4 button pad sample 3 red green blue

All 4 leds in a row share the very same 3 “colors” pins and all leds in a column share the very same ground. It is not directly possible to have 2 differents colors for 2 leds on the same row. And it is not possible to switch on only 2 leds which are not on the same columns.

One way is to switch all leds on and off successively. Or better (more efficient),

  1. set colors on all the rows for the 1st column
  2. switch column on
  3. wait “leds on” for a little while (else leds will look quite dimmed)
  4. switch column off
  5. go to the next column (back to 1)

4x4 button pad sample 4 process

I noticed that waiting for 4ms was giving some fickering. I needed 3ms or less to get a “flicker free” display.  I finally get down to 300μs “led on” period. This is sufficient to get the maximum brightness and definitively get rid of flickering.

Here is a small video showing the same led pattern as above, starting with a 500ms period down to 2ms.

PWM trick

I did connect the leds a bit differently than in the previous article. That is, I swapped  pins
4 & 13 respectively with pin 44 & 45. Why didn’t I used pin 4 & 13 and 44 & 45 instead ?

Because I needed to increase PWM frequency to make the matrix works. To do this, you need to change timers config. Pins 4 and 13 use timer 0. But… as timer 0 is used by Arduino’s core timing functions, you don’t want to mess with it. Do you ?

But why the heck did I want to change PWM frequency ! Because it too “slow” by default. On an Arduino MEGA, default frequencies are :

  • 976.56 Hz for pin 4 & 13
  • 490.20 Hz for all other PWM pins

As stated above, I won’t be using pins 4 & 13. So frequency fo pins I use is a bit less that 500 Hz, that is, a period is a bit higher that 2ms. This is veeeeeeeery loooong… waaaaaay too long because I wait for 300μs and can only “wait” up for 3ms max anyway (not to get flickering). So, even for 3ms, that is around 1 and a half PWM period. This is not enough to get a stable color.

So I increased PWM frequency to the maximum, i.e. 31372.55 Hz. That makes a PWM period of ~32μs which is much smaller of even the smallest 300μs “led on” period.

More on PWM :

  • http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM
  • http://playground.arduino.cc/Main/TimerPWMCheatsheet
  • http://playground.arduino.cc/Code/PwmFrequency
  • http://letsmakerobots.com/node/40136
  • http://letsmakerobots.com/content/arduino-101-timers-and-interrupts

And now the code

I finally built up my very first library based on some OO code. It is to be used with an Arduino Mega and the Sparkfun’s 4×4 button pad.

As this is my first library, it may (does) require improvements… I know. But I hope it will at least get you started !

All the code is here on GitHub.

Sparkfun’s 4×4 Button & LED Matrix – Part 2 – Connecting to an Arduino Mega

I described, in a previous post, how to assemble a 4×4 Sparkun’s button and led matrix. Let see how to connect it.

Because of the (quite) large number of leds and button, I will be using an Arduino MEGA. That will allow to drive RGB leds and button without any additionnal  component. Well… almost : we’ll still need

  • 12 150Ω resistor for the RGB leds
  • a few jumper wires
  • 3 small breadboards
  • an Arduino MEGA of course

RGB led and Arduino

RGB LED detailsAn RGB led is actually… 3 leds : 1 Red, 1 Green and 1 Blue (thus RGB). They all share a common cathode and have 3 anodes, 1 per color.

Choosing the voltage applied to each color allows to choose the brightness of each color, allowing, in turn, to display a broad range of colors.

An Arduino does not have analog outputs. Only digital ones. So we’ll use digital output to “simulate”  analog ones using a technique called PWM. For more details on PWM see here.

Wiring the button & led matrix

Without the matrix, we would need 3×16=48 PWM pins… that’s a lot. With the matrix, we only have 4 rows, each row being connected to 4 leds. This implies some limitations but we now only need 3×4=12 PWM pins and Arduino MEGA 2560 has… 15 of it. Phew…

In addition of connecting the anodes to PWM pins, we also need to connect the cathodes to  simples digital pins. We only need 4 of them because we have 4 columns, each column being populated with 4 leds sharing the GND.

And then, we’ll need 4 digital pins for button GND (cols) and 4 more for signal (rows)

button pad connection

You’ll find an interresting article about about keyboard matrix here.

And put it in a box !

I used the box in which my netatmo thermostat was provided : a nice cube with the perfect size ! I’ve done a bit of cut in the box and the spacers and here is the final result :

In the box closedIn the box opened

 A simple test program

We’we wired evrything up, we can start programming the gizmo and see what it can do. You will find a test program here.

As you see, it is quite simple : at startup, it senquentially lights up all leds then, on each button press, it light up the corresponding led, changing color each time.

It is just for testing. I’ll work on some more interresting programs and post them !

Sparkfun’s 4×4 Button & LED Matrix – Part 1 – Soldering

Introduction

There are quite a few project out there using Sparkfun’s Button Pad 4×4 – LED Compatible and associated Button Pad 4×4 – Breakout PCB. But most of the time there are either using monochrome leds and a shift register to drive the leds or just using a 2×2 matrix. So I decided to write my own build guide with RGB leds and an Arduino MEGA.

This is the first part of this building guide. In this part, I’ll list parts I used and show how I soldered everything together. In next part, I will describe connection of the pad to an Arduino MEGA and all necessary code to test it and make some fun things.

The parts

You’ll need :

That’ll be it for the soldering. But in the next parts, I will also be using

  • 1 Arduino Mega
  • 12 150Ω resistors
  • a few jumper wires
  • one big breadboard (or 3 small ones)

I bought my parts mainly from 2 french retaillers in or near Paris : Lextronic as they are a Sparkfun’s reseller and Saint-Quentin Radio for basic electronic pars (such as resistors, diodes, cable…) But you can find almost everything at Sparkfun’s or your prefered shop !

The soldering

Lets have a look at the PCB first. On the “bottom” side, we will solder the 1N4148 diodes and the BERG connectors. On the “top” side, where the botton pad will rest, we will solder the RGB leds.

4x4 Button Pad Breakout PCB Bottom

Bottom side : where diodes and connectors go

4x4 Button Pad Breakout PCB Top

Top side : where RGB leds and rubber buttons pad (below) goes4x4 Button pad

1N4148 diodes : the easy part

Not much to say really… Just bend the legs, insert the 16 diodes required in the proper holes and solder. Just one thing to take care of : the orientation on the diode !

1N4148

Then, solder the diodes on the top side, taking care of not putting to much solder as you will need to trim the legs as close as possible from the PCB (I used a specific plier / cutter like this one) so it won’t get in the way of the rubber buttons pad.

RGB leds

Not much more complex. But leds I used have legs a bit closer from one another that the holes are. So you need to bend the legs before trying to insert them. If you don’t, you won’t be able to push them enough.

RGB LED RGB leds on PCB

Then solder the legs of the leds !

The BERG connectors

Again, one tricky part is that you need to keep soldering on the top side as “flat” as possible, else, rubber pad won’t lay down properly on the PCB.

What I did is “trim” the BERG connector BEFORE soldering so it flush with the PCB. Doing it after is much more difficult and you may (will) damage the solder joint.  Whan soldering, make sure you heat the BERG pins with the iron so that you build a solid solder joint.

        BERG trimmed

BERG soldered flat

Cabling

Ok, now we need some wires to connect the PCB to an arduino. I used a 4 wire ribbon cable. On one side, I just tin-plated the wires so that they can be easily used with a solderless breadboard. On the other side, I used the female BERG connectors.

berg femake berg female and cap berg female and wire

Connecteur BERG et Cable

 And in the end…

… we get a fully assembled button pad !

button pad assembled connector sidebutton pad assembled led side

 

Building a sound based toy

I have been a bit busy lately at work so I did not work a lot on my different projects. But after a discussion with my sister who was complaining about  the fact that there was no “good” music based toy for her 18 months old child, I was wondering what I could do about it.

Wandering around, I discovered a few things like a “wall Piano” based on a PICAXE-08M2 microcontroller and an ultrasonic Range Finder (see here). But nothing really nice and fun for a very young child. I finally discovered a very very nice project : monome. Ok… a bit complex for a child and surely to expensive ! Looking for some monome clone, I finally stumbled upon Sugarcube Midi Controller. Small enough, nice illuminated buttons, some fun features using accellerometers…

But… it is a midi controller, meaning that it does not play music by itself but controls a midi player like a PC. So I need to make it more autonomous. So my next project is there : build an easy to use & fun sound box, based on Amanda Ghassaei‘s Sugarcube project with specific features like RGB leds, embedded MP3 player and MIDI player, and make it fun for a child !

Still thinking about it…

Getting XBee to work with Arduino SoftSerial

But… what is XBee…

Yes… you’re right, first things first. XBees are small wireless modules which implement, depending on the model, several RF protocols, the “major” one being ZigBee (thus the name !) You can find details here on Digi’s website.

XBee & Uno

Take care, there are several modules. I’ll be using XBee ZB Series 2 modules. You’ll find an XBee RF modules comparison here. As there are quite a few sites describing XBees , I won’t get into details in this post but rather refer to Sparkfun’s XBee buying guide which is covering XBee, ZigBee and Bumblebee 🙂

XBee & SoftwareSerial

Using XBee module with an Arduino is quite well documented… but examples often use the hardware UART making it not simple to program or debug because the UART is shared by the Arduino IDE and XBee chip.

So I thought I use SofwareSerial instead just as I did for one of my Wifridge version.

I used an XBee breakout board from www.droids.it I bought from Lextronic. It is handy as you can use it with 2.52mm pitch headers (XBee won’t fit directly into a breadboard !) and it has 2 operation LEDs.

Connection is quite straightforward :

  • 3.3V on Vin
  • GND on… GND
  • Tx on pin 7
  • Rx on pin 8

Rx and Tx pins can easily be changed in the program anyway.

Then, upload an AT firmware onto XBee module, upload this program onto the Arduino… and you should get something like that on your Serial Monitor into Arduino IDE :

You now have an XBee module talking to an Arduino using Software Serial port, leaving the hardware one for debugging and programming !