Wednesday, August 13, 2014

Raspberry Pi FTP Server

That's a nicely sized server if you ask me
For a while now I've been trying to set up a FTP Server using an Arduino Uno with an ethernet shield, and it's just not up to the job. An FTP server is a website that people can upload and download files to, effectively serving as a network drive that is accessed through a web browser.  I've found that the Arduino is capped at hosting http pages with the ethernet shield and an SD card, and I need something more to be able to use web services like php and java.  Earlier this week I was lucky enough to get my hands on a Rasbperry Pi model B+, and decided that it would be perfect for the job.

As a Mac user, interfacing with linux devices is relatively easy for me. Apple's Terminal application (Applications/Utilities/Terminal) is able to communicate via ssh with the Raspberry Pi and allows me to program it through the command line in what is referred to as a "headless" mode. In other words, I can program the Pi without access to an external monitor, keyboard, or mouse.  For those of you who are interested, I installed the Raspbian OS on my Raspberry Pi's SD card so that I could run headless from the first boot.

In order to get my Raspberry Pi set up as a FTP Server, I first installed Apache and PHP 5 through the command line.  I then installed phpFileManager onto the Raspberry Pi, and viola! I now have the ability to upload and save files to the SD card on my Raspberry Pi through any web browser, whether on my phone, laptop or computer.

Code/commands for creating your own FTP server after the break!

Saturday, August 2, 2014

Music Controlled LED Strip (Arduino Code)

I swear this wasn't filmed with a potato, I have awful bandwidth. 
Song credit: The Yeah Yeah Yeah's - Heads Will Roll

I finally got a chance to clean up some of the test code I wrote for my LED strip controller, which can be found here.  With this code and my LED strip controller circuit, you can use an Arduino to control a 5050 LED strip so that it changes colors in response to music.  I have it set to pulse and fade through a combination of red and blue hues in response to changes in volume.

I sought to create my lighting effects solely through code, and simply attached my audio signal straight to analog pin 3 on my Arduino Uno. I'm able to sense my signal through the use of the analogRead() command.  The audio signal that I feed my Arduino changes in analog value based on a couple of factors.  The Arduino sees this signal as a voltage source, and reads it as a value between 0 and 1024.  Changing the volume of the input source and also variations in the rhythm and beat of the music cause this voltage value to fluctuate. For example, when I'm listening to house music and the bass drops, the volume rises and the voltage of the signal will rise up sharply.  I can detect this rise, and change the color of my LED strip based on it.

My code is as follows:

#define REDPIN 5    //define what PWM pins are connected to the LED strip
#define GREENPIN 3
#define BLUEPIN 6

int b = 100;        //define the variables that will be used to control red, green, and blue.  
int r = 0;          //these values don't matter too much
int g = 0;

void setup() {
  pinMode(REDPIN, OUTPUT);   //set the three PWM pins for output
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  
  pinMode(A3, INPUT);  //set Analog pin 3 up for the audio signal
}
void loop() {
  
   analogWrite(BLUEPIN, b);  //change the color of the LED strip based on the values of r, g, and b.
   analogWrite(REDPIN, r);
   analogWrite(GREENPIN, g);
    
  //using just my ipod, the max signal I get into A3 is 400 or so.  If I had a signal that could reach 5v...
  //... the input values I would get would range between 0 and 1024
  
 if (analogRead(3)>325){ //if the signal from my ipod is greater in value than 325
   r=255; //strobe white
   b=255; 
   g=255;
   }
 else {                     //otherwise...
   if (analogRead(3)>200) { //if the signal is greater than 200
    r=(r+100); //increase the red and blue hues of the strip
    b=(b+50);
    }
   
   else { //if the signal from the ipod is below 200
     if (r>0 & b>0){ //and the values of red and blue are greater than 0
     r=(r-25); //decrease each slowly (this creates a fading effect after each beat)
     b=(b-10);
     }
     else { //if the values of red and blue fall below 0
     r=0; //set them all equal to 0
     b=0; //this is necessary to prevent each color from cycling through its min->max brightness
     g=0;
     }
        }
      }

Sunday, July 20, 2014

Arduino LED Strip Controller Build

This weekend, I decided I wanted to take an RGB LED strip controller that I'd been working on and make it a little more permanent. I took everything off of my breadboard and added it to a proto shield that I had, and I'm pretty happy with the results.  I plan on bringing it back to school with me in the fall and using it to control lights in my room.

a basic outline of what I used for a circuit
I'm controlling a 5050 LED strip with my circuit. This type of strip contains red, blue, and green LEDs in each of its modules, so I'm able to change its colors by varying how much each LED is turned on.  The strip is controlled through four pins; a positive rail and a ground for each color.  I've made it so that I can control the colors of the strip using pulse-width modulation from three digital PWM pins on an Arduino Uno. 

The three n-channel transistors shown in the circuit act as switches that I control through the Arduino, allowing me to turn the red, green, and blue LEDs in the strip on or off.  When I send a high signal to the base of one of the transistors, I allow for current to flow through its other two pins, effectively turning on one color in the LED strip. On the power supply side of things, the 5 volt regulator and capacitors allow me to create a smooth 5 volt signal from the 12 volt power supply that came with my strip.  This way I can run both the Arduino and the strip with the same supply.

Since my Arduino is 8-bit, I'm able to vary each color by 256 increments of brightness.  In order to produce colors other than red, green, and blue, I turn on each of the three colors at different values between 0 and 255. So in other words, I can produce a lot of colors. In order to clear things up a bit, here's an example of how this would work. Say I want to produce white light. In order to do so, I would set the values for my red, green, and blue outputs all equal.  For a dim light I would set them to low values, such as 50. For maximum brightness, I'd set them all equal to 255. It's that simple.  

using PWM to control color!

So far I've been using example code from Adafruit to control my strip, but I'm in the process of writing my own code that will allow the strip's colors and brightness to be controlled by music.  This is why there's an audio adapter in my schematic.

I'll be doing another writeup on my code for music synchronization sometime in the near future, so stay tuned! 

  

Wednesday, July 16, 2014

Installing Ubuntu On An Old Desktop (Fail)

For the past week or so, I've been trying to install Ubuntu on an old desktop that I got from the dump.  For those who are interested- it's a Dell Optiplex GX620 with a 3.0 GHZ Intel Pentium CPU, 2.0GB RAM, and 160GB SATA Hard Drive. It's been a bit of a process.

Attempting to install Ubuntu on my desktop, shown cracked open on the right
I decided to try download a 32-bit version of Ubuntu desktop install it using a DVD, but I ran into several problems along the way. One message that I consistently get while running the installer is "the ext4 file system creation in partition #1 of SCSI3 (0,0,0) (sda) failed." For one reason or another, Ubuntu's installer just does not want to partition my hard drive for me. I've tried setting it up manually several times so that I have set partitions for my /root and /home directories as well as swap space, but to no avail.

When I do manage to get past having the installer format the drive and the "Install" window appears with a loading bar, it will either freeze or crash midway through. Score!


Tuesday, July 8, 2014

Audio Amplifier Power Supply Circuit


As you've probably gathered from my previous posts, I'm working on building myself a high-power audio amplifier.  I've found that both the two books I own and the internet share a common method of documenting amplifier builds. This method showcases the circuitry that revolves around the amplification, and often glosses over building a power supply for said circuitry. I mean, go figure right?  What I've wanted for a while now, not just with this project, is a reliable method for building an amplifier power supply.  In the past, I've looked at schematics for audio amplifiers and realized how they function for the most part, and then felt stuck when I saw rails for power. After spending some time reading and searching the internet, I've come to a few conclusions, and feel that I have a few new tools at my disposal.

When it comes to building a power supply, the first thing you need to do is find out what supply voltages the amplifier circuit can run off of, as well as what you want your max output power (in watts) to be.  In my case, I'm using solid state amplifier IC's that require positive and negative voltage sources, as well as a ground connection. So along with providing the right amount of output power, I'll also need a supply that can put out both a positive and negative voltage. You'll be able to perform all of the necessary calculations to build your power supply by knowing the required values of these voltage sources.

For example, say I want to build a stereo amplifier that can put out 60 watts RMS per channel running off of a supply voltage of +/- 20-45 volts.  In order to calculate what I need for a power supply, I'll first use the equations Power = Amps * Volts [P=IV] and Volts = Amps * Resistance [V=IR] to get P = (V^2) / R, or V = sqrt(RP) to calculate the RMS voltage I'll need from my supply. Using my desired output of 60 watts through 8 ohms:
           
 V = sqrt(60*8) = sqrt(480) = 22 volts.     (1)

I then convert this value from RMS voltage to standard voltage by multiplying it by sqrt(2), or 1.414.

1.414 * 22 = 31.1 volts = 31 volts.     (2)

Next, I need to account for any drops in voltage that will occur from my power supply circuit.  This includes the approximate values of a 5 volt power supply droop if running at full power, a 2 volt drop from the amplifier circuit itself, and a 1 volt drop from the power supply circuit's rectifier, bringing the total drop to 8 volts. I also need to convert my voltage back to an RMS value. 

(31 volts + 8 Volts) * 1/sqrt(2) = 39 volts * .707 = 28 volts RMS.     (3)

This is the number I've been looking for! In order to provide the output power that I want, I'll need a transformer with +/- 28 volt dual secondary rails.  In order to buy the correct transformer, I also need to know its VA rating.  This is simply volts*amps, and should be specified with the transformer's specs.  Using ohm's law and our voltage value from (1) and Ohm's law, we can calculate that:

22 volts / 8 Ohms = 2.75 Amps.     (4)

We then need to increase this value by 20% to account for approximate losses, and then double our answer because we'll be powering two channels at 60 watts each.

2.75 Amps * 1.2 * 2 channels = 6.6 Amps.     (5)

Next, we multiply this number by the voltage value that we obtained through (3) in order to get the desired VA rating of our supply.  In case 4 ohm speakers are used with the amplifier, this rating should be doubled.

6.6 Amps * 28 Volts = 184.8 VA * 2 = 370 VA.     (4)

You now have the power requirements for your transformer! 370VA, with +/- 30V dual secondaries.  I'd recommend getting a toroidal transformer in order to keep electromagnetic noise to a minimum.

In order to complete your calculations for making a power supply circuit, you'll need to figure out what values you want to use for your reserve capacitors (CR). You can do so using the rule of thumb of 1000 microfarads per 10-15 watts output. In the case of my above example, I'd use capacitors rated for (120 watts / 15 watts/microfarad) * 1000 = 8000 microfarads at minimum.

As a side note, based on my schematic, CE is used to reduce external noise, and the four CS capacitors are used to reduce noise from bridge rectifier BR. Both the CE and CS capacitors are ceramic.

Wednesday, July 2, 2014

Boombox Circuit- Spontaneous Build of the Day

Today when I got home from work I decided I wanted to build myself a little boombox. I've been looking at small Bluetooth speakers and "boomboxes", if you will, for a while now. I did some scavenging through my parts drawer, and stumbled upon an old Toshiba TA7230P IC. I looked up its datasheet and decided it would be perfect for my needs. The TA7230P is designed to power a small set of speakers with minimal external components. If I remember correctly, I got it out of a junked radio several years ago. 

The example circuit from the datasheet (pictured at the top) is what I ended up building. All that I needed other than the chip was several capacitors and a pair of speakers, all of which I already had available to me. I decided that I would go with point-to-point soldering to put it all together; both as an experiment for testing my soldering skills and as a way of keeping noise to a minimum. My end result is what you see below. 

I was really impressed with the sound of the circuit, especially considering every single part I used was scavenged from old boards. The sound quality was cleaner than I had expected, and there was little to no detectable distortion at reasonably loud volumes. Overall, I powered the circuit off of 6 volts, which is on the low end of the possible 5.5-20 volts that the IC can run on. I used the circuit to power a small pair of 4 ohm, 3 watt speakers. My next steps are to find a good case for it all, and to interface the circuit with my Bluetooth audio adapter. I'll be saving that for another day though. 

Saturday, June 21, 2014

LM3886 Amplifier Design


I've been meaning to build my own amplifier for a while now. My old tube amp is on its last leg and I need something that can withstand a little more damage to bring back to school with me in the fall.  Based on an example circuit from the Audio IC Users' Handbook and my interest in gain clone-type amplifiers, I decided to design myself an amplifier board based on the LM3886 IC.

The schematic I used is similar to the main example of the datasheet, with a little more added circuitry. Unfortunately, I won't be able to post a picture of the schematic due to copyright. The board that I designed functions as a one channel 68w amplifier, running off of +/- 28V.  In my finished amp, I'll be using two of this board [one for each channel] , as well as a power supply circuit board and a transformer.

I started off with searching Digikey for all the components I plan on using. I'm using all through-hole components in order to keep the board as simple as possible.  After finding all the parts I needed to produce two circuit boards, I began to focus on the board design itself.  I used the dimensions of the parts I ordered to design a small circuit board that holds just the amplifier IC and the components needed to run it.  I wanted the board to be as small as possible in order to minimize noise from circuit board traces, as well as to keep the PCB costs down.

My end result was what you see above. Note that IC1 is not labeled for the LM3886 because I used a different IC with the same footprint to design the board rather than creating a custom component.   Designing the board was quite the learning process, it was my first time using EAGLE to create a circuit board, as well as my first time ordering custom circuit boards.  I'm happy with the end result.

As a side note, I found that seed studio will produce custom PCB's for a very low cost, and ended up ordering 5 copies of my board for 9.99 - not bad at all! If you'd like a copy of the EAGLE schematic/board files I created I'd be happy to email them to you.

Sunday, June 15, 2014

BeagleBone Bluetooth Networking

You're looking a VNC and internet connection to my BeagleBone, all over Bluetooth of course!
So I've been spending a large amount of time messing around with a BeagleBone Black (BBB) lately.  I've experimented with wifi dongles, VNC, Ethernet over USB, and Bluetooth.  I started out programming the BBB from my Mac, and then ended up switching over to a Windows computer.  However, when it came time to set up a Bluetooth connection, I gave up and installed Ubuntu on my Windows computer.  After all, why would you want to program a linux development platform using anything other than linux?

Anyhow, it took me a long time to set up a proper Bluetooth connection.  I ended up creating an IP network connection over Bluetooth, allowing me to SSH and VNC into the bone wirelessly.  Cool stuff!  After a bit of thought, I realized that if I already established an IP connection to the BeagleBone, why not forward it internet through the same address! After a bit more experimentation with programming, I ended up with a BeagleBone that was both remotely accessible and connected to the internet using nothing but Bluetooth.  Below I detail the commands I used to do so, I couldn't find a specific guide for doing all of this on the web so I figured I'd make a tutorial.

First, connect your BeagleBone to the internet and run the following commands.  **These only need to be ran the first time you set up your Bluetooth connection** 

opkg install bridge-utils
opkg install bluez
nano ./test_nap

Next, paste this code into ./test_nap.  Press ^x followed by y to exit and save the file.  In order to make it executable, enter the command chmod +x ./test_nap

The following commands must then be run every time the BBB is rebooted in order to establish remote accessibility and internet over Bluetooth.

On the BeagleBone:

brctl addbr pan0
ifconfig pan0 192.168.99.1 up
./test_nap pan0 &
(press the enter key)

route add default gw 192.168.99.2

Now log out of your connection to the BeagleBone and type this command into your computer's command line:

hcitool scan

Choose the MAC address that corresponds to your BeagleBone based on the results of the hcitool scan command. In my case this is 00:02:72:AB:84:5B

sudo pand -n -c 00:02:72:AB:84:5B

sudo ifconfig bnep0 192.168.99.2

sudo su

iptables --table nat --append POSTROUTING --out-interface wlan0 -j MASQUERADE

iptables --append FORWARD --in-interface bnep0 -j ACCEPT

echo 1 > /proc/sys/net/ipv4/ip_forward

That's it! Pull out your USB cable connection to the BeagleBone and try to connect to it remotely using ssh root@192.168.99.1, then use something along the lines of ping 8.8.8.8 to verify that you're connected to the internet.


The entire process, along with verification that it worked




Saturday, June 14, 2014

Why I Made A Blog

Hi, I'm Georges.  I'm a soon to be sophomore studying Electrical and Computer Engineering. I tend to keep myself busy, I'm pretty involved on my campus and I recently began working full time.  I started this blog to keep myself focused on what I love; technology and electronics.  I plan on using Coffee and Circuits as a way to share my projects and ideas with the world, as well as a medium for keeping track of my work.  I hope to create my own tech startup one day, and I consider this blog as one of my first steps in that direction. I welcome reader participation, I'd love to get some feedback on my posts.  Enjoy!