Playing with an Arduino
09 Feb 2015 - Nic Ho Chee
Many moons ago, a young technologist would have perhaps seen the odd sci-fi movie, stared in wonder at a robot of some kind and pondered, "how can I make that?" A short conversation with an elder later, they might have found themselves entrusted with a copy of the Maplin's catalogue, marvelled at the future hinted at on the cover and leafed through it to be assailed by myriad arcane serial numbers to byzantine artefacts whose purpose could only be guessed. If that young person were very lucky they would have someone to show them at least the first steps on a path towards creating an electronic automaton. The vast majority would however have none of this, as shown by the dearth of Engineers Britain is creating, electronic or otherwise. Fast forward twenty or so years, and the conversation becomes:
Here is an Arduino, contained in this box is everything that you need to know to start creating electronics which could help you understand the world.
Recently I was gifted one of these beauties, the Arduino starter kit. The kit contains a small programmable micro-controller, with breakout pins which allow you to read and write either digital or analogue values. The analogue pins support a range of effectively 10-bits, with a number of digital pins all of which support simple on/off for +5V/0V and a smaller subset of these which have an 8-bit range. These can be used to control electronics, and the kit contains most of the parts needed to complete a few Heathkit style projects as an introduction to the device.
The Arduino has a compact IDE which can be used to write small programs in C++, with access to library extensions that appear to belong to the language Processing. These programs/sketches are then cross compiled into assembly for the ATmega328 micro controller at the heart of the Arduino which supports code up to 32KB in size. The sketches can be transferred to the device via USB from a Mac, Windows or Linux box.
The project book which comes with the Arduino, slowly introduces new users to the device features, ranging from simply turning Light Emitting Diodes on or off, to reading the output of Potentiometers and controlling motors with transistors. My favourite sketch shows how to write text to a small two row LCD. The code shown below can be used with the project pin layout to enable scrolling using the LCD.
The first section includes the LiquidCrystal header and initialises an LCD object which we can use to send signals to the LCD. The Arduino ships with a set of libraries which allow the user to abstract some of the core functionality, and the LiquidCrystal header can be found amongst these.
The code below contains a simple C++ class which allows the device to print some text and move it to the left a single character on each call to print().
A simple Arduino progam has two main sections, the setup() method contains initialisation code which is run once at the beginning of a program. The loop() method is run continually after the program is initialised. In this setup method, the LCD has been initialised to support sixteen columns and two rows. The two lines are then printed to the LCD.
The Arduino loop method is then called continually whilst the program is running. As soon as the loop method completes, it will be scheduled to run immediately. In the case shown below it simply clears the LCD, prints text and waits for a quarter of a second.
After a short time tinkering with the device I'm impressed by how quickly I could prototype electronic circuits, and will probably use this in the future as a digital/analogue I/O controller for a synthesiser or joystick project. I'd strongly recommend this to kids as it introduces electronics in a set of simple easy to understand chunks.