Sunday, May 29, 2011

Controlling The RGB LED


Now that we've covered a simple method for reading the line level audio signal, we can talk a bit about the other side of things; the LED. These things are very bright and look great if you put something around them like a cylinder of paper to diffuse the light.
RGB LEDs have four pins; 3 for each colour, and one for ground. I calculated the resistor values here based on the 5V PWM pin voltage, the forward current of each colour, and the forward voltage of each colour. That is, the resistor values for each colour are approximately equal to (5V - forward voltage of colour)/forward current. We need to include current limiting resistors because the forward current of each colour (approximately 20mA) is less than the maximum rated current of the PWM pins (40 mA), which would otherwise flow and likely burn out the LEDs in the absence of any resistance. I have included the basic schematic below.

The code below will simply switch between each colour. Note that 0 corresponds to LED off, and 255 corresponds to the maximum brightness for the PWM signal - something we will be including in the actual algorithm to control brightness with signal level and colour with each beat.

//Simple code toggles colour of LED at maximum brightness

const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;

int thisPin = redPin;
int other1 = greenPin;
int other2 = bluePin;

void setup() {

pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(greenPin, OUTPUT);

}

void loop() {


analogWrite(thisPin,255); //maximum brightness
analogWrite(other1,0); //turn off
analogWrite(other2,0); //turn off

//switches colour every second
switch (thisPin) {
case redPin:
thisPin = bluePin;
other1 = redPin;
other2 = greenPin;
break;
case bluePin:
thisPin = greenPin;
other1 = redPin;
other2 = bluePin;
break;
case greenPin:
thisPin = redPin;
other1 = greenPin;
other2 = bluePin;

}

delay(1000);

}

Sunday, May 15, 2011

Reading Sound Level


I have included a very simple circuit below along with the required code to read in line level audio. No special considerations were given to the sampling rate or anti-aliasing filters; these things are not required for this project as was found experimentally.
For this circuit a simple voltage divider is formed with a blocking capacitor (using something other than 100uF is fine - feel free to experiment) to maintain that DC bias at analog pin A0. This is to ensure that the negative portion of the line level audio does not clip. A DC offset in code is used to compensate for any differences in the voltage divider resistor values due to inherent tolerances, and the signal is then mapped to the -256:256 range (convenient for the algorithm, as you will see). Values are sent to the serial monitor to allow you to make sure that things are working.

Regarding the 3.5mm jacks, the diagram shows only one. Typically there is one pin that is GND, and two other pins that are the left and right channels of stereo audio. For our purposes you can simply tie the left and right channel together. For a line out signal, connect the corresponding pins of the second 3.5mm jack to the first 3.5mm jack. It's just that simple!

Note that you will need to ensure that the volume is high enough at the input to get some real values. Don't expect to see any clipping. Experiment! Every input source will be a little bit different.

//Simple read of line-level audio, write to serial monitor
//Uses simple voltage divider input circuit with blocking capacitor
//Basic approach doesn't consider using anti-aliasing filter

//or sampling rate

const int audioPin = A0;
int x=0;
int sensorValue = 0;
int offset = 0; //choose offset based on the reading you get
//in the serial monitor when there is no input signal
//this value may be nonzero if resistors aren't exactly
//equivalent in voltage divider circuit; simpler software

//hack than to use a potentiometer

void setup() {

Serial.begin(9600);

}

void loop() {

sensorValue = analogRead(audioPin);
x = (sensorValue - 512)/2; //maps 0:1024 to -256:256
x = x - offset; //subtract offset so we see zero for no input

Serial.println(x);
delay(1);

}

Monday, May 2, 2011

The Arduino


Arduino is an open-source single-board microcontroller, descendant of the open-source Wiring platform, designed to make the process of using electronics in multidisciplinary projects more accessible. The hardware consists of a simple open hardware design for the Arduino board with an Atmel AVR processor and on-board I/O support. The software consists of a standard programming language compiler and the boot loader that runs on the board.
Arduino hardware is programmed using a Wiring-based language (syntax + libraries), similar to C++ with some simplifications and modifications, and a Processing-based IDE.Currently shipping versions can be purchased pre-assembled; hardware design information is available for those who would like to assemble an Arduino by hand. Additionally, variations of the Italian-made Arduino—with varying levels of compatibility—have been released by third parties.The Arduino project received an honorary mention in the Digital Communities category at the 2006 Prix Ars Electronica.The name is an Italian masculine first name, meaning "strong friend". The English pronunciation is "Hardwin", a namesake of Arduino of Ivrea.

Wikipedia


Microcontrollers can be thought of as very small, simple and inexpensive computers-on-a-chip, found in everything from microwaves to robots. They have memory, digital and analog I/O pins, and can execute the instructions that you program them with

The platform. I have included a few pictures of the Arduino UNO Board below. The Arduino is an open source microcontroller platform that was initially developed in Italy, based on the Atmel AVR microprocessor. It's simple to connect to your computer to power and program over USB. There are essentially a number of pins that one can access including analog inputs (for ADC), PWM output pins for driving motors, servos, or in our case LEDs, power pins, communication pins, and digital I/O pins for reading and writing high or low voltages. The intent of this blog is not to duplicate all of this information, so I would direct you here for . Our focus will be on making the thing work for our music visualizer.

Friday, April 29, 2011

Music Visualization


Music visualization, a feature found in electronic music visualizers and media player software, generates animated imagery based on a piece of music. The imagery is usually generated and rendered in real time and synchronized with the music as it is played.

Visualization techniques range from simple ones (e.g., a simulation of an oscilloscope display) to elaborate ones, which often include a plurality of composited effects. The changes in the music's loudness andfrequency spectrum are among the properties used as input to the visualization.


History

The first electronic music visualizer was the Atari Video Music introduced by Atari Inc. in 1976, and designed by the initiator of the home version of Pong, Robert Brown. The idea was to create a visual exploration that could be implemented into a Hi-Fi stereo system.

Music and audio players were available on early home computers, Sound to Light Generator (1985, Infinite Software) used the ZX Spectrum's cassette player for example.[1] The 1984 movie Electric Dreams prominently made use of one, although as a pre-generated effect, rather than calculated in real-time. One of the first modern music visualization programs was the open-source, multi-platformCthugha (1994). Subsequently, computer music visualisation became widespread in the mid to late 1990s as applications such as Winamp (1997), Audion (1999), and SoundJam (2000). By 1999, there were several dozen freeware non-trivial music visualizers in distribution.

In particular, MilkDrop by Ryan Geiss, G-Force by Andy O'Meara, and Advanced Visualization Studio (AVS) by Nullsoft became popular music visualizations. AVS is part of Winamp and has been recently open-sourced, and G-Force was licensed for use in iTunes[2] and Windows Media Center[citation needed] and is presently the flagship product for Andy O'Meara's software startup company,SoundSpectrum. More recently NoiseCradle has made it possible to incorporate videos and live webcam feeds into music visualizations. The real distinction between music visualization programs such as Geiss' MilkDrop and other forms of music visualization such as music videos or a laser lighting display is the visualization programs' ability to create different visualizations for each song every time the program is run.


Wikipedia

First Post

I've always loved listening to music. An interest in audio, electronics, engineering, and signal processing came later. Sometimes inspiration strikes, and so this blog is an impulsive move on that inspiration.

The first series of postings will focus on how to design a beat tracking device that will control an RGB LED to provide interesting sequences of light and colour - essentially a music visualizer. The idea is not new, but the implementation here is original. I encourage you to give it a try. Everyone needs to start somewhere. I hope this will be of some interest, and fun. Other projects and variations will follow.

Note that unlike many other visualizers that rely on some computer-based code like Processing to work, this one is stand alone. All code is executed on the device itself.

We will start our journey with the Arduino , a well known, very well documented open source microcontroller. This is a very flexible and inexpensive development platform to start with (about $50 for the board. you just supply the USB cable, and the parts you want to control).