Skip to content

Hardware Abstraction

Phil Schatzmann edited this page Oct 3, 2025 · 16 revisions

Overview

We are using wrapper classes to provide a flexible, configurable functionality for

In addition we provide the following initialization classes / objects to set up some consistent szenarios accross these objects:

Impact of Compile Options

If you compile with -DUSE_PI then RPI.begin() is called automatically which will set the SPI, I2C and GPIO to use Linux API provided by the Raspberry PI.

If you compile with -DUSE_REMOTE then Remote.begin() is called automatically which will set the SPI, I2C and GPIO to use communication via UDP.

If you omit any of the above, we just use a dummy implementation where you can call all available methods on the objects but w/o any impact.

Assigning Individual Functionality

This setup provides you with a lot of flexibility, since you can call this functionality in the sketch as well: e.g. calling Remote.begin() in the sketch switches the SPI, I2C and GPIO to using Serial communication via UDP even when compiled with -USE_RPI. In addition you can configure SPI, I2C or GPIO individually:

RPI.begin(false); // initialize RPI w/o updating GPIO, SPI and I2C
Remote.begin(false); // initialize Remote  w/o updating GPIO, SPI and I2C
GPIO.setGPIO(RPI.getGPIO()); // use Raspberry PI API for GPIO
SPI.setSPI(Remote.getSPI()); // Exchange SPI via UDP
I2C.setI2C(nullptr); // Dummy I2C where functions calls don't have any impact

Remote API with Custom Stream

The remote API uses UDP by default, but you can use any Stream class provided by Arduino.

E.g. the following

Remote.begin(Serial); // initialize Remote for GPIO, SPI and I2C

will using Serial to communicate state changes.

Clone this wiki locally