The first step with any new hardware is the 'hello world' of electronics - blinking an LED. This is very easy with CircuitPython and Coral. We'll extend the example to also show how to wire up a button/switch.

Coral boards don't have any way to set the pullup/pulldown resistors, so you'll need to use external resistors instead of built-in pullups, whenever it makes sense!

Coral Dev Board Pinout

Note that the GPIO pins on the Coral roughly correspond to the Raspberry Pi GPIO

Similarities:

  • 5V, 3.3V and GND pins are all in the same locations
  • Main I2C port is on pins #3 and #5
  • Main SPI port is on pins #19, 21, 23, 24 and 26
  • Main UART port is on pins #8 and #10 note that this is shared with the console so you will conflict with the built in serial console unless you disable the console on these pins
  • I2S is available on same pins as Raspberry Pi

Differences:

  • There's a UART3 on pins #7 and #11 but these don't seem to be available (/dev/ttymxc2 does not exist) so these pins cannot be used for GPIO
  • I2S is enabled by default so you cannot use pins #12, 35, 38, 40 for GPIO
  • PWM is enabled on pins #15, #32 and #33 so these pins cannot be used for GPIO but you can use them to create PWM outputs
  • The secondary I2C port is available for you to use (pins #27 and #28)
  • Raspberry Pi GPIO #22 is known as GPIO_P13
  • Raspberry Pi GPIO #23 is known as GPIO_P16 (output only)
  • Raspberry Pi GPIO #24 is known as GPIO_P18
  • Raspberry Pi GPIO #25 is known as GPIO_P22
  • Raspberry Pi GPIO #5 is known as GPIO_P29
  • Raspberry Pi GPIO #6 is known as GPIO_P31
  • Raspberry Pi GPIO #16 is known as GPIO_P36
  • Raspberry Pi GPIO #26 is known as GPIO_P37 (output only)

Parts Used

Any old LED will work just fine as long as its not an IR LED (you can't see those) and a 470 to 2.2K resistor

Single large LED lit up blue
Need some big indicators? We are big fans of these huge diffused blue LEDs. They are really bright so they can be seen in daytime, and from any angle. They go easily into a breadboard...
$9.95
In Stock
Angled shot of 25 Through-Hole Resistors - 470 ohm 5% 1/4W.
ΩMG! You're not going to be able to resist these handy resistor packs! Well, axially, they do all of the resisting for you!This is a 25 Pack of...
$0.75
In Stock

Some tactile buttons or switches

Angled shot of 10 12mm square tactile switch buttons.
Medium-sized clicky momentary switches are standard input "buttons" on electronic projects. These work best in a PCB but
$2.50
In Stock

We recommend using a breadboard and some female-male wires.

Angled shot of Premium Female/Male 'Extension' Jumper Wires - 40 x 6 (150mm)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of...
$3.95
In Stock

You can use a Cobbler to make this a little easier, the pins will be labeled according to Raspberry Pi names so just check the Coral names!

Angled shot of Assembled Pi T-Cobbler Plus next to GPIO ribbon cable
This is the assembled version of the Pi T-Cobbler Plus.  It only works with the Raspberry Pi Model Zero, A+, B+, Pi 2, Pi 3 & Pi 4! (Any Pi with 2x20...
$7.95
In Stock

Wiring

Connect the Coral Ground pin to the blue ground rail on the breadboard.

  • Connect one side of the tactile switch to Coral GPIO_P13
  • Connect a ~10K pull up resistor from GPIO_P13 to 3.3V
  • Connect the other side of the tactile switch to the ground rail
  • Connect the longer/positive pin of the LED to Coral GPIO_P16
  • Connect the shorter/negative pin of the LED to a 470ohm  to 2.2K resistor, the other side of the resistor goes to ground rail

There's no Coral Fritzing object, so we sub'd a Raspberry Pi in

Double-check you have the right wires connected to the right location, it can be tough to keep track of pins as there are forty of them!

No additional libraries are needed so we can go straight on to the example code

However, we recommend running a pip3 update!

pip3 install --upgrade adafruit_blinka

Blinky Time!

The finish line is right up ahead, lets start with an example that blinks the LED on and off once a second (half a second on, half a second off):

import time
import board
import digitalio

print("hello blinky!")

led = digitalio.DigitalInOut(board.GPIO_P16)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True
    time.sleep(0.5)
    led.value = False
    time.sleep(0.5)

Verify the LED is blinking. If not, check that it's wired to GPIO #16, the resistor is installed correctly, and you have a Ground wire to the Coral.

Type Control-C to quit

Button It Up

Now that you have the LED working, lets add code so the LED turns on whenever the button is pressed

import time
import board
import digitalio

print("press the button!")

led = digitalio.DigitalInOut(board.GPIO_P16)
led.direction = digitalio.Direction.OUTPUT

button = digitalio.DigitalInOut(board.GPIO_P13)
button.direction = digitalio.Direction.INPUT
# use an external pullup since we don't have internal PU's
#button.pull = digitalio.Pull.UP

while True:
    led.value = not button.value # light when button is pressed!

Press the button - see that the LED lights up!

Type Control-C to quit

This guide was first published on May 12, 2019. It was last updated on Mar 28, 2024.

This page (Digital I/O) was last updated on Mar 08, 2024.

Text editor powered by tinymce.