Glitch and the LED Sneakers – Hello World

So now it’s time to plug things together and start programming.

The Arduino development environment is super simple to work with. The tools are written in Java so they’re cross-platform. If you’re running Ubuntu then installation is simply a matter of visiting the Software Centre, typing in ‘Arduino’ and clicking the install button for the Arduino IDE program that pops up. If you’re on Windows or Mac then it’s not much more complicated than that either – download the software from the Arduino website and install.

Then plug one end of the programming cable into your Lilypad (be sure to get it the right way round – the board is marked B and G for the Black and Green wires in the cable) and the other end into your computer. At this point your computer discovers a new serial port provided by the USB cable – again if you’re running Ubuntu it just works but if you’re running Windows to Mac there’s help here to guide you through installing the necessary device drivers.

Run the Arduino IDE and go to Tools->Board to select the correct board that you’re programming. In my case it’s the “Lilypad Arduino w/ATmega328”. Then click on Tools->SerialPort to check that your system’s detected and selected the correct serial port.

Now you’re ready to go! The IDE contains over a hundred simple program examples to get you started with whatever piece of code functionality or add-on hardware you’re trying to use. The Arduino equivalent of Hello World is called Blink and we can use it now to test out our Lilypad and workflow. The Lilypad contains an LED already mounted to the board so we can run the Blink program (File->Examples->Basics->Blink) without having to attach any extra hardware.

/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH); // set the LED on
  delay(1000); // wait for a second
  digitalWrite(13, LOW); // set the LED off
  delay(1000); // wait for a second
}

Arduino code is written in C so if you’ve got any programming experience it isn’t going to take long to pick up. The program that you write gets compiled on your computer and then transferred to the Arduino where it’s run by a boot loader program. The boot loader program expects to find two functions in your code:

  • setup() is called once when the program starts up. Use this for initializing variables and setting the mode (input or output) of the various I/O pins
  • loop() is called repeatedly. Depending on your task and your personal programming style you can keep control within loop() or you can let the program flow fall out the bottom and have the boot loader call you again.

The example Blink program flashes the Lilypad’s on-boad LED: one second on, one second off and repeat until you unplug it.

Comments are closed to reduce the spam. If you'd like to add something, please use the contact form to let me know and I'll reopen comments for you. Thanks