I have recently started using an Arduino Deumilanove. It is an open source hardware  platform with a microprocessor, a number of digital and analog inputs, some digital outputs and a USB connection.

My five year-old, Aurora, and I put together the obligatory Blink sample yesterday and are due for some more ‘nventing tomorrow morning. This evening, in preparation, I put together a more useful example. Not one but two LEDs!!

I wanted to have the PC send messages (in this example a byte) to the prototyping board and have a visible result. Eventually I chose to have a red and a green LED as the output and the microprocessor ‘listen’ for an ‘R’, ‘G’ or ‘O’ on the USB port. (O being to turn off all lights.) I can see my self using something for indicating status of the build or test results.

The eventual solution requires sending the byte message from the PC to the Arduino. Here, I will use PowerShell to ‘new up’ a System.IO.Ports.SerialPort and WriteLine the commands from the shell.

 

Here is my sketch:

int redPin = 13;   
int greenPin = 7;   

void setup() {

  // set all the other pins you’re using as outputs:
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  //the usb connection
  Serial.begin(9600);
}

void loop() {

if (Serial.available())
{
   int c = Serial.read();
   switch (c)
   {
     case ‘R’:
       digitalWrite(redPin, HIGH);       //Light Red
       break;
     case ‘G’:
       digitalWrite(greenPin, HIGH);     //Light Green
       break;
     case ‘O’:
       digitalWrite(greenPin, LOW);      //Lights out
       digitalWrite(redPin, LOW);
       break;
   }
}

}

After hooking the Arduino up, I keyed the following into PowerShell.

$s = New-Object System.IO.Ports.SerialPort
$s.PortName = "COM4"
$s.BaudRate = "9600"
$s.Parity = "None"
$s.WriteLine('R')

The green light came on and my inner geek roared!