Starting a VU (Volume Unit) Meter

To keep myself busy at university, I decided to start on a big project. Well big for me anyway.
The end goad being a a VU (Volume Unit) meter, aka a sound level, that can be used either in-line with an audio cable, or used with a microphone.

I am to try to go through this project in a number of research stages, and main 3 test stages.
For the research I want to start with a Light Level Meter. This will just help me to refresh my arduino programming skills, and also just set myself up for when I get hold of a microphone.

Next I will take the same circuit and apply it to audio, using a microphone and using a line-in. In terms of analysing the audio I will first try using a simple analogRead, just the same as the Light Level Meter. I will also look into using FFT (fast Fourier transform) which is used to transform raw audio into a frequency spectrum, which in turn can be outputted to LED displays. This route could end up being very complicated so I will approach that with caution.

The next stage is to research multiplexing and charlieplexing LED’s. This is because I would like the end product to have a LED matrix display,  thus enabling me to potentially display a spectrum of frequency bands. However for the testing I will move back to the Light Level Meter and try to display that data on the LED display.

In terms of the test stages, I will be doing all initial research on breadboards, if all goes to well I will move onto designing an arduino shield, the hope is that this will also work as a Lol (Lots of Lights) Shield. Finally I want to take this to an end product, on its own PCB.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

So enough talking, time to refresh on the very basics.

The Light Level Meter.

This is a very simple circuit, but then that was not the purpose of it.
Each LED was connected to a pin on the arduino, and the central pin of a variable potentiometer is connected to an analogue in pin. I connected an LDR (Light Dependant Resistor) between the variable pot and 5v. The other pin of the variable pot is pulled down to 0v.

Light Level Vs Resistance over a LDR

As the light level decreases, the resistance over the LDR increases, combining this in a basic potential divider circuit means that as it gets darker, the value read in at the analogue pin of the arduino gets higher. This allows me to adjust the LED’s appropriately and also use the variable pot to calibrate the display.

The circuit seen below is the circuit used, with a 330 Ohm resistor in series with every LED as a current limiting resistor.

Light Meter Fritzing Circuit
To program the arduino I used the standard arduino IDE, available from arduino.cc, and I programmed the arduino with the below sketch.

// LED Light Level Meter

int led[10] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12};  // Array of pin numbers for                  the LED’s
int adjust = 5; // Adjustment Pot
int Light, i;

void setup()
{
for (i=0;i<10; i++) // A for loop which goes from 0 to 9, setting
pinMode(led[i], OUTPUT); // each value in the array as an output
Serial.begin(9600); // Turning on the serial output to troubleshoot
}

void loop()
{
Light = analogRead(adjust); // Reading the analogue value of the LDR
Serial.println(Light); // sending the value to the computer for troubleshooting
Light = Light / 100; //reducing the value down to between 0 and 10
Serial.println(Light); // sending the value to the computer again

if (Light == 0) // checking that all LED’s are off if there is no light
{
for(i = 0; i < 10; i++)
{
digitalWrite(led[i], LOW);
}
}

else
{
for(i = 0; i < Light; i++) // Turns on all LED’s between 0 and the light level
{
digitalWrite(led[i], HIGH);
}

for(i = i; i < 10; i++) // turn off the leds above the light level
{
digitalWrite(led[i], LOW);
}
}
delay(100);

}

Advertisements

Raspbery Jam & SDR

Inspired by a talk on Software Defined Radio (SDR) during a TinkerSoc night, and motivated by the rocketing number of hits the society’s website after their blog post about SDR was featured on Hack-A-Day. I decided to try it out for myself!

SDR works due to the RTL2832 chipset which has a very wide frequency receiver range. This chipset is used in a lot of the USB TV tuners out there, however not all of them. A list has been compiled on the Osmocom.org website where they also have a huge amount of information about SDR.

Having brought myself a USB TV Tuner off Amazon for £14 and free shipping it is clear that this is a really inexpensive way to get into amateur radio.

P1000558

The USB Tuner arrived at my house at university on the day of the fifth Raspberry Pi Jam, it seemed like an ideal opportunity to combine the two interests.

Having learnt a little bit about the different programs available during the talk at TinkerSoc, I decided to use rt-_tcp a lightweight piece of software that has the RTL (Realtek) drivers.

RTL-tcp is a sub program of RTL-sdr which is a command line interface program for controlling the TV tuner. By using RTL-tcp you are setting up a server which you can then connect to and stream the data from the Raspberry Pi to your computer. The benefit of this is that your antenna can be high up outside in the cold, meanwhile you are inside, nice and cosy.

Arriving at the Raspberry Jam I immediately set myself up with a my RPi connected to all the peripherals like the monitor and keyboard, as well as connecting it to my laptop over an Ethernet cable and I bridged the LAN to my wireless connection in order to install the software.

I was fortunate that two gents were very kind as to start helping me, teaching me my way around the command line and explaining the function of programs like aptitude and git.

Referencing a guide on hamradioscience.com I started to set up my RPi with all the software I needed.

To start with I checked that all dependencies were installed. There are programs that RTL-SDR and -TCP will need in order to work correctly. To check and/or install these dependencies I had to use the sudo apt-get install function and then install git, cmake, libusb-1.0-0.dev and build-essential.

sudo apt-get install git 
sudo apt-get install cmake
sudo apt-get install libusb-1.0-0.dev
sudo apt-get install build-essential

The next step was to download RTL-sdr and install the drivers.

git clone git://git.osmocom.org/rtl-sdr.git
cd rtl-sdr/
mkdir build
cd build
cmake ../
make
sudo make install
sudo ldconfig

The final step is to copy the rules file (rtl-sdr.rules) which can be found at /home/pi/rtl-sdr and this file should be copied into etc/udev/rules.d .

P1000557

Once the rules are in place you need to plug in the TV tuner and then you are ready to test that everything is working correctly by using the command rtl_test -t.

rtl_test

If everything is working all right, as it is in the picture above, then it is time to start the server and then set up your listening station.

To start the server type rtl_tcp -a followed by the ip address of your Pi. The ip address can be found by typing ifconfig into the command line, the ip address is the set of 4 numbers in the eth0 section. next to the lable “inet addr”.

SDR Sharp is a program written in C# that claims to be high performance with design in mind. It is also the program I decided to use with rtl-tcp.

To set SDR Sharp up with the raspberry pi, RTL-SDR / TCP must be selected from the drop down list, and then click configure.

sdrsharp1

The Raspberry Pi’s ip address should be entered into the host cell, and in the Port cell is the default value that doesn’t need to be changed. Volume can be adjusted using the RF Gain slider if you want a more permanent higher volume.

sdrsharp2When you have finished configuring, just press play. If all has gone well, then you will see the waterfall of data start to fall down the screen and hopefully hear something.  In all likely hood you won’t hear anything straight away, so you will want to change the frequency, you can do this by clicking on the top or bottom of the numbers representing the frequency at the top pf the screen, or by clicking along the activity bar.

Happy listening.

————– UPDATE ————–

April 2014

So after not using SDR for over a year I have set up my Pi to listen to the airwaves again. This was sparked by a comment below asking for help.
I followed my own walk-through and encountered the same issues as Ryan had encountered.

I managed to resolve these by adding “blacklist dvb_usb_rtl28xxu” to the file
/etc/modprobe.d/raspi-blacklist.conf by entering

sudo nano /etc/modprobe.d/raspi-blacklist.conf 

and entering the extra line at the bottom.

After rebooting everything worked well.