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;
     }
        }
      }