Rss

First play with Arduino

So I was in the Markeaton with Mr. Lock and we were talking general techie stuff and, as ever, he was coming out with a load of stuff that’s a bit over my head. We then went to The Raj and it’s all a bit blurry after that. One thing that did vaguely stick, however, was Arduino, an open source platform for electronics prototyping and projects.

We like open source. In software, being able to see the source code provides a great learning opportunity. You can see how and why things work and, if you’re up to it, you can offer contributions to help improve the project. Extending that principle to a hardware platform is new to me and whilst electronics really isn’t my thing, Arduino struck a chord so I thought I’d better have  a play.

First stop was, as ever, google.co.uk which brought up the usual three million pages. Fortunately the first was the main Arduino.cc site, where I picked up some more of the background. I then found a review of starter kits at http://aaroneiche.com/2009/07/16/arduino-starter-rundown-part-2/ and chose this one from oomlout.com which, with postage & VAT, came in at £58.50.

The kit soon arrived, complete with a USB lead and a proper plastic case to hold all the components.

But before that… whilst I was waiting, I did a bit of background and found the great Virtual Breadboard tool, which lets you build devices, write code for them, and simulate their output. It’s not just for Arduino, and it’s well worth a look.

Anyway…

The list of items in this pack is pretty good, in addition to the nice case that the kit comes in, you get:

  • Arduino Uno board
  • 10 x 30 breadboard
  • Pre-drilled perspex piece to hold both boards
  • Selection of standard red & green LEDs, plus one big blue one
  • Mix or large and short jump wires
  • Mix of 10k, 2k2 and 560ohm resistors
  • Various fixings
  • Server
  • Piezo buzzer
  • Three push button switches
  • A small potentiometer (variable resistor)
  • A shift register
  • A relay
  • A tmp36 transitor
  • A small relay
  • Temperature sensor
  • Photocell resistor
  • A 220uF capacitor
  • A small DC motor
  • An adaptor to enable the board to be powered from a 9v battery (normal power is via USB)
  • A booklet containing a decent introduction and some sample projects.

All in all, a pretty good mix. There are several kits like this and I’m not really competent to determine which is best, but this seemed like a good balance of components and having the booklet and the tidy box swung it for me.

So to getting the kit set up. Although I intended to use my MacBook running Ubuntu 10.10 (and this is what I’ll use in future), I ended up using a Vaio VPC-F with 8Gb RAM on Windows 7 AMD64.

The first step was to download the software tools from Arduino.cc. At the time of writing, the current version is 0022. One note here is that the googlecode downloads were horrendously slow. I searched for and found a much faster independent mirror, and you may wish to do the same. I won’t put the one I found here in case it kills someone’s home broadband!

For Windoze, the software is a standard zip file, which you can extract pretty much anywhere you like. I put it in c:program files (x86)arduino-0022, then found the arduino.exe inside and pinned that to the start menu.

I then plugged the board into PC and let it run (and fail) the normal new hardware procedure. Device manager, update driver, and search for c:program files (x86)arduino-0022 sorted this out and the device appeared as COM11. It’s important to know the com port for when you want to actually do an upload. As it’s an emulated serial port, the number allocated could be pretty much anything under Windows. Under Linux it can still be variable but I guess it’s going to be /dev/ttyUSB0 if you only have one USB serial adapter.

So with the board connected and the drivers installed, it was time to plug some components in and write some code. Given I’m new to all of this, I pretty faithfully followed the first example in the book, which you can find at http://www.oomlout.com/a/products/ardx/circ-01.

So now it’s just a case of putting the parts in the right order (in my case, getting the LED the right way round…), typing in the code to the Arduino editor, clicking compile and uploading.

One nice thing here is that you can get maps from the web which show exactly what plugs into which hole on the breadboard. This could be very useful, as sometimes the booklet leaves you guessing, although for this project my common sense didn’t fail me.

The code is simple. Very simple. Although they call it “Sketches”, if you know C or any C-type languages, then you’re going to be at home with this. If you don’t know C, then you’ll learn a few esoteric bits and then you’ll also be at home with this. Please see the link above for proper credits for this sample.

// the physical pin the LED is connected to, end goes via the rail to GND
int ledPin=13;
void setup() {
// configure this digital PIN to send output, not receive input
  pinMode(ledPin,OUTPUT);
}
// the Arduino will constantly run this function
void loop() {
// Essentially turns the pin on, so providing power to the LED
  digitalWrite(ledPin,HIGH);
// Wait a second (1000ms)
  delay(1000);
// Turn the pin (and so the LED) off
  digitalWrite(ledPin,LOW);
// Wait another second
  delay(1000);
}

So the code above should compile (go to the Sketch menu, then choose Verify / Compile) and upload (File menu, Upload to I/O board).

If it doesn’t work by default, you may need to set the correct com port and board type in the Tools menu. All being well, you then get a message that the upload was completed and the board should start doing what you expect.

There’s no rocket science here, and I was lucky in that I only had to swap the LED round (wrong pins in wrong holes) in order to get everything going. I then made code changes to adjust the timings, just to prove it was me controlling the light and not something else, and it all seemed good.

I will say, though, that the software development kit seemed pretty slow. I will try this on another machine in due course, but if a quad-core + hyperthreading machine with 8Gb RAM struggles, then something doesn’t seem right. I’m no fan of java, but even that can’t be this bad. Hopefully it’s just a quirk on this machine – we’ll see.

All in all though, a very simple and successful first project. Even though it was stolen from the booklet, it was still quite satisfying. A nice feature about the guide is that it contains a section on how you can improve the project, e.g.  to vary how frequently the light blinks, use an analogue pin to adjust the power (and so the LED brightness), etc, and I’ll look at that in due course. For now, I’ve just modified the Sketch to use each pin in turn so to prove that the board is working as extended.

I have some things I specifically want to achieve with this unit – I’m currently interested in the house temperature and light levels (I have something else doing power consumption recording, but that may yet be included), and the kit I’ve bought should cover those things off. I’m pretty pleased with the purchase – I don’t think it’ll be another one of those things that I look at for a day and then put in a cupboard – and I’m looking forward to learning a bit more about what I can achieve with this kit.

There seems to be a pretty active Arduino community, too, so I’m expecting to get the benefit of their enthusiasm and experience.

Leave a Reply

%d bloggers like this: