Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Getting Ready

Final Features used

Make sure you familiarize yourself with these Final features. We use them in the Pi examples:

  • Stacks, and basic stack operations
  • Objects
  • Compound Object syntax
  • DynamicObject
  • Paren object constructors
  • TypedObject

For more advanced controller designs, it is helpful to be familiar with these features:

  • Events and the EventLoop
  • EventTimer and EventTicker for creating time-based events in your controller
  • EventEscFn for ease of stopping a controller, or selecting options

Enabling Peripherals On Your Pi

Some of the breakout functions of the Pi are not enbled by default in the Pi OS. The pins themselves are available, but the following needs to be done to enable I2C, SPI, and PWM. You make these changes in /boot/firmware/config.txt. BE CAREFUL!

I2C and SPI

Make sure you enable i2c and spi (uncomment.) Only uncomment i2s if you are going to use an I2S audio dongle or hat. If you do, set i2s.reserved true at the top of your Final files, so reset doesn’t clobber it.

The following only enable i2c1 and spi0 (the header defaults).

dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on

To enable other numbered i2c or spi ports that Final Pi supports, add lines like these to config.txt.

# I2C -- only include ones you use
dtoverlay=i2c2-pi5
dtoverlay=i2c3-pi5

## SPI -- only include ones you use
dtoverlay=spi1-pi5
dtoverlay=spi5-pi

UARTs

Each UartPeriph that you use must be enabled individually, and conversely, you should not enable the ones whose pins or periphs you plan to use otherwise.

During testing of our UartPeriphs, we connected 0 and 2 together, and enabled them thus. Follow the same numbering for the other supported uarts.

# Final Pi HAL: header UART loopback pair (uart0 GPIO14/15, uart2 GPIO4/5).
dtoverlay=uart0-pi5
dtoverlay=uart2-pi5

PWM

Again, don’t enable any of these if you aren’t using PWM. External PWM dongles are available, if the Pi is too finnicky…

# Final Pi HAL: header PWM on BCM 12/13 (pwm0/pwm1). dtoverlay=pwm-2chan,pin=12,pin2=13,func=4,func2=4

Pi Prototyping Hardware

You should already have a breakout cable and a T-header for a breadboard. You can get this from CanaKit or on Amazon. Several of the examples use the following:

  • a red and a green LED (don’t use blue or white, they require too much drive voltage)
  • 2x 220 or 330 ohm resistors for the LEDs
  • 2 breadboard compatible push buttons.

We also have an example of using:

  • a 9250 9-dof accelerometer/gyro/compass
  • an SSD1306-class OLED display
  • a JD79661 AdaFruit 4-color e-ink display

Conventions Used

We talk exclusively about GPIO pins, not header pins. GPIO is the conceptual pin number, from 0 to 27. These are mapped in kind of haphazard way to the 40-pin header on the Pi. Most Pi boards come with a card showing how the GPIO pins map to the header pins. To avoid any confusion, we never reference the header pins. So just make sure if you follow any of our examples, that you are using the GPIO pin, not the header pin number.