Hardware Reference
In-Depth Information
Programming the Gertboard is much like the low-level Arduino code. That is, you are writing directly to the
memory-mapped IO and therefore need the careful skill of an assembly programmer. This code might appear banal
like this:
PWMCLK_DIV = 0x5A000000 | (32<<12);
PWMCLK_CNTL = 0x5A000011;
PWM_CONTROL = 0; // i.e. off
PWM0_RANGE = 0x400; // all values between 0 and 1023
PWM0_DATA = 0x100; // write output
This, seemingly natural code (albeit a little heavy on the magic numbers), is all that's necessary to set up the
PWM. However, hiding behind these macros are pointer indirections such as:
#define PWM_CONTROL *pwm
#define PWM_STATUS *(pwm+1)
#define PWM0_RANGE *(pwm+4)
#define PWM1_RANGE *(pwm+8)
#define PWM0_DATA *(pwm+5)
#define PWM1_DATA *(pwm+9)
So all that's necessary is a missed warning about incorrect data types, and you'll be corrupting the subsequent
register and be tracing nonexistent bugs for hours! More information on this board can be found on the Element14
site at http://www.element14.com/community/docs/DOC-51726?ICID=raspi-group .
Naturally, other interfacing boards are available, with Pi-Face from Manchester University, Pi Crust, and
Quick2Wire. More are coming out each month, so a quick web search for “buffer boards” or “expansion boards”
will let you know of the current state of the art.
With the Arduino
The simplest way to connect the Raspberry Pi to the outside world is through an Arduino, as we already have many
years experience with the device. Furthermore, there are many useful shields already available. For most people, this
is a waste of effort because the Arduino is capable of processing most input devices that we care about. However, it
does provide a level of security knowing that if you make an error, it is the (cheaper) Arduino that will blow up, and not
your beloved Raspberry Pi!
USB
Despite the issues mentioned previously about USB on the Raspberry Pi, this is the simplest and safest way to connect
the two machines. You simply plug one into the other!
As far as software goes, the Arduino processes its input and writes data out using the traditional:
Serial.begin(9600);
pinMode(inputSwitchPin, INPUT);
pinState = digitalRead(inputSwitchPin);
Serial.println(pinState ? '1' : '0');
Search WWH ::




Custom Search