Category Archives: GPIO

GPIO circuit board

The first thing I’ trying is General Purpose Input Output, or GPIO. For these purposes, I have created a circuit board which I can attach to my Beaglebone Black. It consists of a green LED and a 220 ohm resistor (as per the Derek Molloy book). Because Beaglebone Black cannot safely drive an LED from the control pins, a MOSFET (a BS270) was added to the circuit board, and to protect the MOSFET gate from static, a 1 Mega-ohm resistor was connected between ground and the gate. (Actually, the gate appears to be reasonably resistant to static charge, anyway).

Circuit Layout

Circuit Layout

The circuit was tested using a breadboard, and then soldered onto a piece of stripboard. All of the components were of the traditional through-hole type. A label was printed out and put onto the front of the header block. I used UHU glue, which was a bad choice – PrittStick or similar works better and is less sticky.

DSC00091

Front of circuit board – header labelled (left to right) 7 – SYS_5V ; 1 – GND; CONTROL

DSC00080

Rear of circuit board

The board was connected as follows:

  • 5V to P9-7 5VS
  • GND to P9-1 GND
  • Control to P9-23 GPIO 1-17

The control drivers are provided in the Linux operating system as a collection of files. By writing to and reading from those files the control pin status is changed. You write to a file by using ‘echo’ and read from a file using ‘cat’. So, to operate the board certain steps must be followed:

  • Export GPIO 1-17
  • Set direction to output
  • Set value to one or zero

The Beaglebone Black has four groups of GPIO pins, numbered 0 through 3. Each group has 32 pins, numbered 0 through 31. The internal GPIO number is the GPIO group multiplied by 32, plus the pin number. Here, the internal GPIO number is 1 x 32 + 17, or 49. First, we export the pin.

cd /sys/class/gpio

echo 49 > export

cd /sys/class/gpio/gpio49

The two files (properties) that we are interested in are ‘direction’ and ‘value’. We set the direction to be ‘out’ and the value to ‘one’ – switching the MOSFET gate to high, and the LED on.

echo out  > direction

echo 1 > value

This then switches the LED on, and takes your eye out as a consequence – the LED is very bright!

LED board, control pin low

LED board, control pin low

LED board, control pin high

LED board, control pin high