Physical computing Physical computing

various buses, Ethernet and USB. Development Why should free software be chained to keyboard, mouse and screen? In the fi rst of a boards with stuff like fl ash and 2.6.10 on board Standing between are readily available, with core CPUs such as compelling and practical two-parter Martin Howse examines open tools which allow for PowerPC abounding, but most GNU/ DIY SoC work takes place within the burgeoning embedding computation deep within the environment. hardware and software FPGA scene under the hardcore LGPLed LEON2 design of European Space Agency fame. FPGAs, and between software with the conceptual emphasis on programming in the fi eld very much to the fore, are a tough call to explain satisfactorily without some degree and coder, interface of low level knowledge of logic, processors and the like. FPGAs represent reconfi gurable computing at is a ripe area for the hardware level with vast arrays of gates reprogrammable through well defi ned interface further investigation with a conventional PC by way of a high level language such as VHDL or Verilog. VHDL, which stands for VHSIC Hardware Description Language, where VHSIC is yet another acronym CHEW ON THIS Though coaxing GNU/Linux, through tweaking hardware and porting code, to run on a rapidly growing range of small devices is defi nitely a possibility for physical computing - and poses its own rewards - what we’re more concerned with here is freeing ourselves from the further tethers of an OS which can penetrate tentacle-like downwards Let’s Get into hardware. Indeed, with OS defi ned primarily as both reliable and standard interface and manager of resources, in our world of open, environmentally embedded hardware it’s a tough call to decide exactly what needs managing and how to go about this awesome task. That said, it’s perfectly feasible, given some awareness of how a full-blown OS may condition our device, to run with uClinux, a port to small and MMU (Memory Management Unit) defi cient systems. Early test prototype shows three ap0201 modules connected including main computational board, charging circuitry and The advantages here include ease of porting for already coded apps microphone pre-amp or those that lend themselves to a high level language, and hassle- free hardware support if you’re looking to interface to a full-blown for Very High Speed Integrated Circuit, is Von Neumann style architecture, or to other machines by way of high favoured in Europe, and such described code is level protocols or, say, a wireless interface. It’s an approach with a then synthesised and uploaded to the FPGA Physical good deal of overhead both power-wise and conceptually but it rather than being used to fabricate costly silicon. works for a good many more conventional projects. On the hardware With the correct software in place, a decent side, and of course well supported by the GNU/Linux toolchain, sized FPGA could function as well defi ned DSP comprising GNU binutils, compiler set (GCC) and debugger, and one moment, offering up a bank of fi lters, or pushing forward the uCsimm approach of a good few years back, the SoC after another upload. It’s most defi nitely soft Gumstix Basix platform is very much de rigueur in such embedding hardware and several scientists have thrown hysical computing is all about freedom Gate Array) led designs. And though embedding is commonly circles. As the name would suggest Gumstix are the size of a stick of genetic algorithms (GA) into the mix to grow Pfrom a highly restrictive desktop bound used to refer to any specialised system which is embedded within gum, lightweight and offer comparatively low power consumption circuits which exhibit extraordinary properties. modus operandi in favour of new ways an often hidden purpose built device, for example an internal stats. Performance under the Intel XScale is good, and a 2.6.10 kernel To demonstrate the sheer versatility of FPGAs, of approaching code and computation. missile guidance system, it’s possible to extend the defi nition to boots from fl ash to interface to optional Bluetooth, CF or RS232. hobbyists have even succeeded in fi tting the Whether it’s about examining imaginative talk about embedding in a wider sense and to use such systems, Gumstix are perfect for a wearables project which needs to interface innards of a range of old-school arcade games, modes of input and output, conditioning fresh perhaps within an artistic context, to refer to notions of to a PDA or wireless enabled desktop. Indeed, the author fi rst including Pacman, into a single and CPU-sized responses in the user, investigating wearable environmental computing under which factors other than tightly encountered them in use within this context at the Piet Zwart Xilinx Virtex chip. In the case of our friend processing or, at an other extreme, embedding bound I/O enter the computational equation. Institute in Rotterdam, where media students were constructing an LEON2, which is commonly implemented on the sensor rich machines in extreme environments, Embedded systems are all about embedding; laying down within audio narrative weaving jacket based on the platform. popular, but now discontinued Xess XSV-800 getting physical is tightly bound with a free a wider context which involves the physical. And within these development board based around a Virtex FPGA, software model. terms, the notion of an interface is well untied from casual modes SOC IT TO ME GNU/Linux has been ported to run on the Within a domain which stresses black boxing of thought. Indeed, standing between hardware and software and Development under a familiar OS and GNU toolchain is one way to SPARC-based core, with further SoC components of software by the device in question, using between software and user or coder, interface is a ripe area for go for projects which adhere to more conventional conceptual thrown in by an active community of hackers. free software in this environment is essentially further investigation - especially under the exposure of the overlap architectures, or which can leverage additional memory and code to FPGAs are a tricky matter, with key all about visibility; devices which are otherwise of both hard and soft enacted by reconfi gurable computing. add virtual machine layers, but physical computing afi cionados have documentation, particularly with reference to totally opaque in relation to underlying tech Although, as we’ll see, we can readily interface a good many more radical choices in reserve, which play well to low cost development on a GNU/Linux platform, become open and hackable, schematics are and the like to a range of sensors, ranging from basic ADCs and varying degrees with a GNU development platform. Next down the hard to fi nd. Issues ensnared with physical exposed to further development, interfaces are DACs for audio capture and response, through to less apparent hierarchy in terms of complexity and overhead we fi nd the SoC, or computing are well exposed by these complex laid wide open and even processor designs can analogue data collectors such as accelerometers and magnetic fi eld System-on-Chip, processors which are very much in favour currently devices which will receive full illumination in the be readily implemented without encumbrances sensors, physical computing is more about running wild with a at the industrial end of the spectrum. next instalment. under extreme FPGA (Field Programmable close knit of code and interface. As the name implies, it’s all on board; CPU, RAM controllers, SoC processors, whilst usually employed in A modular design helps in debugging embedded devices with both hardware and software tested in easy stages in easy tested and software hardware with both in debugging embedded devices helps A modular design

30 LinuxUser & Developer LinuxUser & Developer 31 Physical computing

embedded devices which need to interface to regular I/O including large banks of RAM, run close in complexity terms to good old microcontrollers which make up the mainstay of free range physical computing. They’re tough little fellows which can take a lot of maltreatment and suffer well under extreme environments, making them an ideal resource for rough and ready DIY work. It’s important to differentiate microprocessors, or CPUs, from their larger brothers which pack in processor (simply without the micro), memory, and often some degree of I/O within a small enough IC (Integrated Circuit). Such I/O can include serial communications support by way of a UART, multiple ADCs to play well with the analogue world, PWM which can enable motor and minimal audio, protocols such as I2C and the like and even USB support. The amount of additional circuitry required varies according to chip and required functionality, but it is possible to run Self-suffi cient Other manufacturers in the fi eld include Texas Instruments and Dallas with a microcontroller-based system simply with ap0201 devices pack Semiconductor, who do seem to be drawing some applause for their the addition of a suitable power supply. in PIC16F877 low-powered MAXQ line. microcontroller, 32 Though it’s equally possible to develop for a range of micros on a TAKE YOUR PIC KB NVRAM and free software platform, we’ve chosen to concentrate development on There are plenty of options out there on the suffi cient solar a few PICs, which offer well documented resources and are upheld by micro front, with the two major players boiling charging circuitry to a strong DIY subculture which shares a vast range of application down to Microchip, pushing the funky PIC keep them running documentation. PICs as concept and as acronym date back to the late range, and Atmel, with the rather more sober for a good few hours 70s, when the phrase Peripheral Interface Controller was bandied but equally Harvard architecture based AVRs. after sundown around to refer to an intelligent I/O controller. Of course they can do a lot more now, but in a good many peripheral design instances it’s well worth breaking out a low Desert devices cost PIC at the beck and Fusing extreme computing with esoteric land art, and at the same time providing a good example of the call of a PC app for, say, multiple meanings attached to the term embedding and making a concrete case for environmental code, the ap0201 project refers to solar powered computational devices designed and manufactured by radical artistic sophisticated motor group ap (Martin Howse and Jonathan Kemp). Three such devices, which each embed a virtual machine control, analogue data running code generated directly from environmental data, in this instance noise, within both the wider acquisition or environment and a local Radio Frequency (RF) network, were installed in the Mojave desert in April 2004 with multiplexing. One the assistance of CLUI (Center For Land Use Interpretation). example here would be Located within an extreme and remote environment, with only GPS co-ordinates to identify location for the author’s own use of any intrigued visitor, the PIC16F877-based devices were built to last, with an envisaged minimum lifespan of three years. And within such an extended time frame, each device was designed to squeeze as much such a design to control processing into 24 hours and, if sleep was necessary, to maintain state. In this instance voltage regulated solar the motors of six record panels were employed to charge four NiMH batteries which could thus power the PIC and peripherals during decks and interface with low light or at night. Charging circuitry, based around the excellent TEA1102 from Philips, interfaced with the both a video switcher and microcontroller so that if voltage dropped, state would be saved to the 32 KB NVRAM which itself has a built- laser driven display, all in in battery to retain data for up to ten years, irrespective of external power. All collected code, which runs on real-time and all at the top of the VM, is also stored in the NVRAM. Ap0201 provides a good example of a real world PIC-based project both in terms of interfacing and coding behest of high level requirements and a development cycle encompassing hardware design, prototyping, and a lengthy code and software communicating debug cycle sifting out hardware faults from software errors. A modular approach was adopted for both with PIC by way of design and prototype implementation which made for easier debugging of hardware and software. Code and parallel port and code hardware modules could thus be tested independently to isolate faults. For example the RF transmit/receive words. modules were tested with very simple LED fl ashing PIC code. Later true Manchester encoding was Another less complex implemented and again tested in isolation. example from a different In similar fashion, reading and writing to NVRAM, by way of logic which equally well allowed for writing data to the 16 digit LCD screen, was implemented as modular code. Other modules hanging off the project involved simple computational mainboard include microphone pre-amp, and charging module. A serial interface, use of a PIC within a implemented by way of Maxim’s MAX3221 chip, proved absolutely essential during development, allowing slider and knob based for both easy uploading of code thanks to the LINWLOAD package and Wloader bootloader, and for hassle- controller for audio work. free debugging. VM stats were logged constantly to the serial port of an attached laptop in the fi eld. Again the parallel port Programming-wise, sections of code such as memory and LCD access which were seriously hardware was the interface of intensive, involving plenty of toggling of logic lines, were coded in assembly but it proved far easier to port ap02 code to compile under the CCS compiler. SDCC would currently provide a more satisfying free choice and the PIC software solution. With serial comms and VM available, ap0201 points towards a vast range of intriguing collapsed data to suit a 4 applications deploying an interpreted control language within the PIC itself. bit wide input regimen. Within a similar domain,

32 LinuxUser & Developer Physical computing Physical computing

The main ap0201 WHAT’S GNU GOT TO DO WITH IT? would be to upload hex assembled from simple board shows bulky Running wild in the embedded fi eld with a manufacturer or code, for example fl ashing an LED hanging from battery backed-up interpreter defi ned instruction set is one thing, but, aside from a one of the PIC’s digital ports. GPUTILS includes NVRAM on the left, suitable development model for PIC code, what’s GNU got to do with gpasm, the GNU PIC assembler, and the linking and large PIC16F877 anything? And how can we quickly and effi ciently develop for such a combining functionalities of gplink, gplib together bottom right and platform whilst shying away from commercial development kits and with a range of disassemblers and other useful assorted logic softwares? command line tools. At its most basic, before Until recently, GNU PIC tools have suffered from a lack of exposure, or getting bogged down in directives and relocatable at least some degree of denigration in comparison to closed source code, gpasm quite simply converts our assembly counterparts which, under the gloss of the commercial, can well appear source fi le of human readable instructions into hex. as of more industry strength. And though a central repository for a range The resulting fi le can then be written to the PIC by of GNU tools does exist, it’s somewhat less than complete and lacks the way of PICprg and friends. Alternatively, those used total breadth of other PIC sites which embrace know how, code and Prior to unpacking and embedding, after one to a more integrated approach will relish the month debugging and rigorous testing ap0201 the MIDIbox hardware platform is an open tools under all platforms. In the face of tackling a trinity of hefty learning devices are ready for deployment recently developed PIKdev IDE which backs up sourced project which offers a range of PIC- curves which involves tackling hardware data sheets, learning instruction editing and project management functionalities with based MIDI hardware projects for implementing sets and GNU tools, it’s little wonder that newbies turn to limited the good old GPUTILS, cpik PIC18 C compiler and a knob boxes and synthesisers galore. Such a solutions such as the Parallax BASIC Stamp or to well specifi ed IDEs. It programming engine to deliver the goods to the project is a good start for those new to both PICs has to be said that proprietary solutions imply containing and in the fi eld SPEAKING THE RIGHT LANGUAGE hardware. and interfacing to the humble PC. Moreover, key of knowledge such an approach can win out over the heavily Free software which actually gets your code onto the PIC is one thing, but With correct hardware attached it’s as simple as developer Thorsten Klose’s MIDIbox Operating decentralised. Peer reviewed and daily updated community resources are it’s very unlikely, though of course possible, that you’ll be programming that. Or at least it should be. The (MIOS) seriously lowers the entry level the only answer; open sourced Pd has won out over centralised Max/ the chip in raw hexadecimal, the internal base 16 code of the PIC. How we embrace of hardware and software is tough to prise for coders new to the PIC and can be used for MSP on these very terms. talk to the PIC is an important choice which raises all sorts of issues relating open for the purposes of debugging and what can control-led real-time MIDI and non-MIDI based In the fi rst instance, reducing choice is a good thing. After newbies to programming language and practise. Indeed, many artists and novice go wrong will go wrong. Although it’s far more applications. With schematics for sample projects have the hang of basic tools which get the job done, other avenues can embedders choose to work with a costly pre-programmed PIC, the satisfying to make use of serial debug facilities a la online, and rich API documentation, MIOS be sniffed out and new methodologies explored. Thus, the necessary Parallax BASIC Stamp 2, simply because it can readily be programmed in printf, or LED-led morse code style message makes for a complete and free development and established GNU toolkit will be outlined here with reference to a few simple PBASIC language by way of an on board interpreter. Another exchanges, simulation by way of , the environment which can well be compared to DIY programmers and a limited range of PIC micros. After all, if you’re approach would be to simply compile code written in C or a custom GPUTILS compatible simulator which throws in other initiatives of note such as the Smart-Its interested in building your own machines, why go all IKEA with the language such as JAL into according to the specifi c advanced components such as LCD screens and project, which is all about embedding programmer hardware? A vast array of DIY programmers exist within a instruction set of the chip and then burn this to fl ash using the GNU tools LEDs, can prove very useful if something is seriously computation within the big bad world, or the rich family tree of freely documented modifi cations well worthy of study above. A free software toolkit could thus be specifi ed comprising compiler, wrong and it can certainly help narrow down Art Interface Device (AID) platform. by any genealogist. At the head of the tree we fi nd David Tait’s assembler, if we choose that route, and choice of programmer. problems to software or often fl aky hardware. Of Aside from a perhaps secondary role as programmer, and, a particularly minimal favourite, the NOPPP, or no Within any workfl ow it’s worth working mentally through the steps course, certain laws dictate that the last place we interface, tough old PICs make great parts PIC programmer, which nevertheless does fall foul of any trade which lead to hex hitting the PIC; a series of steps which includes all look will prove most revealing but it’s tough to embedders, and Microchip offer a vast range descriptions act. Both of these originally, and under most variants, hang important acquaintance with PIC instruction set by way of Microchip’s second guess that magic spot. of processors to suit most needs, from tiny off the parallel port and can be coaxed into attacking a range of devices, excellent data sheets. The choice surface mount eight pin affairs, as used by folk with small 16F628 (pin compatible with the now obsoleted 16F84) and of whether to work within high at the University of Massachusetts to 40 pin 16F877 workhorse as the hot favourites. Indeed, the choice of a level language or assembly, or to Key Links implement a match head sized Web server, mix and match both (see Desert Gumstix through to 40 pin DIP mounting monsters Devices) can only really be www.gumstix.org such as the trusty old 16F877 which packs in a attempted after such an exercise, Microchip PIC In our world of open, environmentally www.microchip.com fair amount of ADC functionality. New on the and it must be said that the MIDIbox block is the dsPIC line of chips which, as the register and data juggling which www.ucapps.de name implies, throws DSP functionality into an embedded hardware it’s a tough call to raw PIC coding is prone to does Smart-Its www.smart-its.org already rich mix. Architecture-wise nearly all offer its own rewards and insights AID PICs usable for DIY embedding pack in varying decide exactly what needs managing into computational process. aid.interaccess.org/drupal amounts of fl ash-based program memory, Larger projects, which the Match head sized web server and how to go about this awesome task www-ccs.cs.umass.edu/~shri/iPic.html which allows for in-circuit re-programming, increased code size of newer PICs NOPPP plain old RAM, EEPROM for non-volatile encourage, may well cry out for www.covingtoninnovations.com/noppp NOPPP Linux software storage of state and the like, and a variety of I/ suitable PIC will well condition which DIY programmer variant to kick off structured C programming, patearl.net/projects/pic O subsystems. UARTs are both handy to have with. The 16F877, which packs eight 10-bit ADCs, decent-sized memory, perhaps mixed with assembly PICprg on board and thankfully commonplace, a reasonable 20 MHz clock-speed and a suffi cient number of timers and routines which can attack bit- www.brianlane.com/software/picprg Broccoli18 enabling easy serial communications between interrupts into a low-power, medium sized package, has long been the bound I/O. Yet, until relatively recently PIC programmers on a GNU/Linux Gpsim currently home.earthlink.net/~davesullins/software/pic18f.html devices such as a PC and the micro itself. For DIY embedder’s chip of choice. Both Tait and NOPPP exhibit variants platform had little choice but to put up with assembly or bed down with a presents some Oddysey www.desert.cx/odyssey truly standard RS-232C interfacing PICs must which can burn code into the 877 under GNU programming tools such commercial compiler such as c2c or CCS PCHL compiler. Thankfully SDCC, seriously powerful Picp be beefed up with the a simple chip which as PICprg and specifi c NOPPP Linux software. the Small Device C Compiler, which now targets a good range of functionalities and home.pacbell.net/theposts/picmicro takes care of ugly voltage level issues. Coders Over the last year a brand new PIC, the PIC18F452, which is pin microcontrollers, including our favourite PIC models, as well as other tiny it’s well worth piping SDCC sdcc.sourceforge.net used to the world of the digital do well to shy compatible with the 877, has pipped the older model to the post with devices, has snowballed since the early days. SDCC, which offers full ANSI code through just to GPUTILS away from the analogue realm and thankfully more fl ash, more RAM, new instructions and a faster clock speed at more C and a range of optimisations and also includes a simulator and check for basic .sourceforge.net ubiquitous chips such as the MAX3221 or or less the same low price point. Both PICprg and NOPPP related debugger, is well documented online as to its use, and will readily generate mistakes before Gpsim sourceforge.net/projects/gpsim MAX3222 take care of all issues with few hardware and software may need to be modifi ed to work with this chip, PIC friendly Hex code. Example code is available for study, but it’s worth committing to fl ash PIKdev additional components. When coupled with but two projects, Brocolli18 and Odyssey, exist which can make light stressing that commercial compilers, attacking a specifi c range of pikdev.free.fr the use of a reasonably high level language work of such modifi cations. For those who value sheer fl exibility over a microcontrollers, are able to provide simpler library routines for I/O. Desert devices www.1010.co.uk/devices.html such as C, by way of a decent compiler, serial DIY approach, Microchip’s very own Picstart Plus pre-built programmer, To do anything useful under SDCC, the full GPUTILS suite of GNU PIC Wloader abilities make for easy debugging of devices compatible with a vast array of microcontrollers is readily accessible by tools will have to be installed, and it’s also very useful to have these on www.voti.nl/wloader/index_1.html LINWLOAD in the fi eld. way of the free software Picp or GUI Gpicp interface. hand for testing purposes. Having built a programmer, the next step www.ise.pw.edu.pl/~wzab/linwload/linwload.html

34 LinuxUser & Developer LinuxUser & Developer 35