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!