Skip to content

Raspberry

Retrieve an ADC device that has been loaded.

Parameters:

NameTypeDescription
nameStringThe name of the ADC device.

Return Type: Adc Device

Returns: The adc_device pointer if found; otherwise, nullptr.

Signatures:

adc_device adc_device_named(const string &name)

Closes an ADC device given its pointer.

Parameters:

NameTypeDescription
adcAdc DeviceThe ADC device to close.

Signatures:

void close_adc(adc_device adc)

Closes an ADC device given its name.

Parameters:

NameTypeDescription
nameStringThe name of the ADC device to close.

Signatures:

void close_adc(const string &name)

Closes all ADC devices that have been opened.

Signatures:

void close_all_adc()

Checks if an ADC device with the given name has been loaded.

Parameters:

NameTypeDescription
nameStringThe name used to identify the ADC device.

Return Type: Boolean

Returns: true if an ADC device with the supplied name exists.

Signatures:

bool has_adc_device(const string &name)

Opens an ADC device with the specified name and type. Defaults to bus 1 and address 0x48.

Parameters:

NameTypeDescription
nameStringThe name of the ADC device to open.
type_of_adcAdc TypeThe type of ADC device (e.g., ADS7830, PCF8591).

Return Type: Adc Device

Returns: A valid adc_device on success, or nullptr on failure.

Signatures:

adc_device open_adc(const string &name, adc_type type_of_adc)

Loads an ADC device on the specified I2C bus at a given address.

Parameters:

NameTypeDescription
nameStringThe name to assign this ADC device.
busIntegerThe I2C bus number.
addressIntegerThe I2C address of the ADC device.
type_of_adcAdc TypeThe type of ADC device (e.g., ADS7830, PCF8591).

Return Type: Adc Device

Returns: A valid adc_device on success, or nullptr on failure.

Signatures:

adc_device open_adc(const string &name, int bus, int address, adc_type type_of_adc)

Reads an 8-bit value from the specified ADC channel on the device.

Parameters:

NameTypeDescription
adcAdc DeviceThe ADC device to read from.
channelAdc PinThe channel number to read (range depends on ADC type).

Return Type: Integer

Returns: The ADC conversion value (0–255), or -1 on error.

Signatures:

int read_adc(adc_device adc, adc_pin channel)

Reads an 8-bit value from the specified ADC channel on the device using its name.

Parameters:

NameTypeDescription
nameStringThe ADC name string to close.
channelAdc PinThe channel number to read (range depends on ADC type).

Return Type: Integer

Returns: The ADC conversion value (0–255), or -1 on error.

Signatures:

int read_adc(const string &name, adc_pin channel)

Converts an ASCII character to a binary value to be used with the Quad 14-segment display module (HT16K33 backpack).

Parameters:

NameTypeDescription
ascii_charCharThe ascii character to be converted to a 16-bit binary value.

Return Type: undefined

Returns: The binary value used to display a character on the 14-segment display.

Signatures:

unsigned short get_alpha_font_14_seg(char ascii_char)

Usage:  {</>}


Converts the specified pin value to an integer, to use in calculations.

Parameters:

NameTypeDescription
valueGpio Pin ValueThe pin to read the value from.

Return Type: Integer

Returns: The pin value as an integer.

Signatures:

int gpio_pin_to_int(gpio_pin_value value)

Checks if the system has GPIO capabilities.

Return Type: Boolean

Returns: true if the system has GPIO capabilities, false otherwise.

Signatures:

bool has_gpio()

This function should be called when you are finished using the GPIO library. It sets all pin modes to INPUT and values to LOW.

Signatures:

void raspi_cleanup()

Usage:  {</>}


This function retrieves the mode of the specified pin.

Parameters:

NameTypeDescription
pinGpio PinThe pin to get the mode for.

Return Type: Gpio Pin Mode

Returns: The mode of the pin.

Signatures:

gpio_pin_mode raspi_get_mode(gpio_pin pin)

This function retrieves the pulse width for the specified pin.

Parameters:

NameTypeDescription
pinGpio PinThe pin to get the pulse width for.

Return Type: Integer

Returns: The pulse width of the pin.

Signatures:

int raspi_get_servo_pulsewidth(gpio_pin pin)

Opens I2C communication on selected address. It will return -1 if not using Raspberry Pi.

Parameters:

NameTypeDescription
busIntegerThe bus of the I2C device.
addressIntegerThe address of the I2C device.

Return Type: Integer

Returns: The handle referencing this particular connection.

Signatures:

int raspi_i2c_open(int bus, int address)

Usage:  {</>}


Writes data to specified I2C connection.

Parameters:

NameTypeDescription
handleIntegerThe reference for a specific I2C connection.
dataIntegerThe data to send.

Signatures:

void raspi_i2c_write(int handle, int data)

Usage:  {</>}


Writes 8-bit (1 byte) or 16-bit (2 bytes) data to specified I2C connection.

Parameters:

NameTypeDescription
handleIntegerThe reference for a specific I2C connection.
regIntegerThe register to send the data to
dataIntegerThe data to send.
bytesIntegerThe number of bytes to be transferred.

Signatures:

void raspi_i2c_write(int handle, int reg, int data, int bytes)

Usage:  {</>}


This function initializes the GPIO library for use. It should be called before any other GPIO functions.

Signatures:

void raspi_init()

Usage:  {</>}


This function reads the value from the specified pin.

Parameters:

NameTypeDescription
pinGpio PinThe pin to read the value from.

Return Type: Gpio Pin Value

Returns: The value read from the pin.

Signatures:

gpio_pin_value raspi_read(gpio_pin pin)

Usage:  {</>}


This function sets the mode of the specified pin to the specified mode.

Parameters:

NameTypeDescription
pinGpio PinThe pin to set the mode for.
modeGpio Pin ModeThe mode to set for the pin.

Signatures:

void raspi_set_mode(gpio_pin pin, gpio_pin_mode mode)

Usage:  {</>}


This function sets the pull-up/down mode for the specified pin.

Parameters:

NameTypeDescription
pinGpio PinThe pin to set the pull up/down mode for.
pudPull Up DownThe pull up/down mode to set for the pin.

Signatures:

void raspi_set_pull_up_down(gpio_pin pin, pull_up_down pud)

Usage:  {</>}


This function sets the PWM duty cycle for the specified pin.

Parameters:

NameTypeDescription
pinGpio PinThe pin to set the PWM duty cycle for.
dutycycleIntegerThe PWM duty cycle to set for the pin.

Signatures:

void raspi_set_pwm_dutycycle(gpio_pin pin, int dutycycle)

Usage:  {</>}


This function sets the PWM frequency for the specified pin.

Parameters:

NameTypeDescription
pinGpio PinThe pin to set the PWM frequency for.
frequencyIntegerThe PWM frequency to set for the pin.

Signatures:

void raspi_set_pwm_frequency(gpio_pin pin, int frequency)

Usage:  {</>}


This function sets the PWM range for the specified pin. Valid values for the range are 25 - 40000

Parameters:

NameTypeDescription
pinGpio PinThe pin to set the PWM range for.
rangeIntegerThe PWM range to set for the pin.

Signatures:

void raspi_set_pwm_range(gpio_pin pin, int range)

Usage:  {</>}


This function sets the pulse width for the specified pin.

Parameters:

NameTypeDescription
pinGpio PinThe pin to set the pulse width for.
pulsewidthIntegerThe pulse width to set for the pin.

Signatures:

void raspi_set_servo_pulsewidth(gpio_pin pin, int pulsewidth)

This function closes SPI communication on a particular channel.

Parameters:

NameTypeDescription
handleIntegerA reference to the specific SPI connection to close.

Return Type: Integer

Returns: A value indicating success or failure.

Signatures:

int raspi_spi_close(int handle)

This function opens SPI communication on a particular channel. It will return -1 if not using Raspberry Pi.

Parameters:

NameTypeDescription
channelIntegerThe SPI channel to use.
speedIntegerThe speed of data transfer (in baud).
spi_flagsIntegerOptional flags for the SPI modes and settings.

Return Type: Integer

Returns: The handle referencing this particular connection.

Signatures:

int raspi_spi_open(int channel, int speed, int spi_flags)

This function transfers data through SPI, it sends data from sendBuf and receives it into recvBuf.

Parameters:

NameTypeDescription
handleIntegerThe reference for a specific SPI connection.
sendStringThe data to send.
countIntegerThe number of bytes to be transferred.
bytes_transferedIntegerThe number of bytes transferred (output)

Return Type: String

Returns: The data returned from the spi transfer

Signatures:

string raspi_spi_transfer(int handle, const string &send, int count, int &bytes_transfered)

This function writes the specified value to the specified pin.

Parameters:

NameTypeDescription
pinGpio PinThe pin to write the value to.
valueGpio Pin ValueThe value to write to the pin.

Signatures:

void raspi_write(gpio_pin pin, gpio_pin_value value)

Usage:  {</>}


This function closes the connection to the remote Raspberry Pi and releases any resources associated with it.

Parameters:

NameTypeDescription
piConnectionThe connection object to the remote Raspberry Pi.

Return Type: Boolean

Returns: true if the cleanup was successful, false otherwise.

Signatures:

bool remote_raspi_cleanup(connection pi)

This function retrieves the mode of a specific pin on a remote Raspberry Pi.

Parameters:

NameTypeDescription
piConnectionThe connection object to the remote Raspberry Pi.
pinGpio PinThe pin to get the mode for.

Return Type: Gpio Pin Mode

Returns: The mode of the pin.

Signatures:

gpio_pin_mode remote_raspi_get_mode(connection pi, gpio_pin pin)

This function initialises a connection to a remote Raspberry Pi using the specified name, host, and port.

Parameters:

NameTypeDescription
nameStringThe name of the connection.
hostStringThe host address of the Raspberry Pi.
portunsigned shortThe port to use for the connection.

Return Type: Connection

Returns: The connection object used to communicate with the remote Raspberry Pi.

Signatures:

connection remote_raspi_init(const string &name, const string &host, unsigned short port)

This function reads the value from a specific pin on a remote Raspberry Pi.

Parameters:

NameTypeDescription
piConnectionThe connection object to the remote Raspberry Pi.
pinGpio PinThe pin to read the value from.

Return Type: Gpio Pin Value

Returns: The value read from the pin.

Signatures:

gpio_pin_value remote_raspi_read(connection pi, gpio_pin pin)

This function sets the mode of a specific pin on a remote Raspberry Pi.

Parameters:

NameTypeDescription
piConnectionThe connection object to the remote Raspberry Pi.
pinGpio PinThe pin to set the mode for.
modeGpio Pin ModeThe mode to set for the pin.

Signatures:

void remote_raspi_set_mode(connection pi, gpio_pin pin, gpio_pin_mode mode)

This function sets the pull-up/down mode of a specific pin on a remote Raspberry Pi.

Parameters:

NameTypeDescription
piConnectionThe connection object to the remote Raspberry Pi.
pinGpio PinThe pin to set the pull up/down mode for.
pudPull Up DownThe pull up/down mode to set for the pin.

Signatures:

void remote_raspi_set_pull_up_down(connection pi, gpio_pin pin, pull_up_down pud)

This function sets the PWM duty cycle for a specific pin on a remote Raspberry Pi.

Parameters:

NameTypeDescription
piConnectionThe connection object to the remote Raspberry Pi.
pinGpio PinThe pin to set the PWM duty cycle for.
dutycycleIntegerThe PWM duty cycle to set for the pin.

Signatures:

void remote_raspi_set_pwm_dutycycle(connection pi, gpio_pin pin, int dutycycle)

This function sets the PWM frequency for a specific pin on a remote Raspberry Pi.

Parameters:

NameTypeDescription
piConnectionThe connection object to the remote Raspberry Pi.
pinGpio PinThe pin to set the PWM frequency for.
frequencyIntegerThe PWM frequency to set for the pin.

Signatures:

void remote_raspi_set_pwm_frequency(connection pi, gpio_pin pin, int frequency)

This function sets the PWM range for a specific pin on a remote Raspberry Pi. Valid values for the range are 25 - 40000

Parameters:

NameTypeDescription
piConnectionThe connection object to the remote Raspberry Pi.
pinGpio PinThe pin to set the PWM range for.
rangeIntegerThe PWM range to set for the pin.

Signatures:

void remote_raspi_set_pwm_range(connection pi, gpio_pin pin, int range)

This function writes a specified value to a specific pin on a remote Raspberry Pi.

Parameters:

NameTypeDescription
piConnectionThe connection object to the remote Raspberry Pi.
pinGpio PinThe pin to write the value to.
valueGpio Pin ValueThe value to write to the pin.

Signatures:

void remote_raspi_write(connection pi, gpio_pin pin, gpio_pin_value value)

Closes all opened motor devices.

Signatures:

void close_all_motors()

Closes and frees a motor device by name.

Parameters:

NameTypeDescription
nameStringName of the motor device.

Signatures:

void close_motor(const string &name)

Closes and frees resources for a motor device.

Parameters:

NameTypeDescription
devMotor DeviceThe motor device handle.

Signatures:

void close_motor(motor_device dev)

Free the resources associated with a motor device.

Parameters:

NameTypeDescription
devMotor DeviceThe motor device to be destroyed.

Signatures:

void free_motor_device(motor_device dev)

Checks if a motor device with the given name is already opened.

Parameters:

NameTypeDescription
nameStringIdentifier for the motor driver.

Return Type: Boolean

Returns: true if open, false otherwise.

Signatures:

bool has_motor_device(const string &name)

Retrieves an existing motor device handle by name.

Parameters:

NameTypeDescription
nameStringIdentifier for the motor driver.

Return Type: Motor Device

Returns: motor_device pointer or nullptr.

Signatures:

motor_device motor_named(const string &name)

Opens a motor device with the specified parameters.

Parameters:

NameTypeDescription
nameStringIdentifier for the motor driver.
typeMotor Driver TypeType of motor driver (e.g., L298N).
in1_pinGpio PinGPIO pin for IN1.
in2_pinGpio PinGPIO pin for IN2.
en_pinGpio PinGPIO pin for ENA.

Return Type: Motor Device

Returns: A valid motor_device on success, or nullptr on failure.

Signatures:

motor_device open_motor(const string &name, motor_driver_type type, gpio_pin in1_pin, gpio_pin in2_pin, gpio_pin en_pin)

Sets the motor rotation direction.

Parameters:

NameTypeDescription
devMotor DeviceThe motor device handle.
dirMotor DirectionDesired rotation direction.

Signatures:

void set_motor_direction(motor_device dev, motor_direction dir)

Sets the PWM speed of the motor (0-1).

Parameters:

NameTypeDescription
devMotor DeviceThe motor device handle.
speedDoubleDuty cycle speed (0..1).

Signatures:

void set_motor_speed(motor_device dev, double speed)

Stops the motor immediately (brake).

Parameters:

NameTypeDescription
devMotor DeviceThe motor device handle.

Signatures:

void stop_motor(motor_device dev)

Close all servos.

Signatures:

void close_all_servos()

Closes a servo device given its name.

Parameters:

NameTypeDescription
nameStringThe name of the servo device to close.

Signatures:

void close_servo(const string &name)

Close one servo (by handle) or by name. Closes a servo device given its pointer.

Parameters:

NameTypeDescription
devServo DeviceThe servo device to close.

Signatures:

void close_servo(servo_device dev)

Returns true if a servo with this name is already open.

Parameters:

NameTypeDescription
nameStringYour identifier for this servo.

Return Type: Boolean

Returns: true if the servo is open, false otherwise.

Signatures:

bool has_servo_device(const string &name)

Open (and initialize) a servo on the given board pin.

Parameters:

NameTypeDescription
nameStringYour identifier for this servo.
control_pinGpio PinBoard‐numbered GPIO pin for the servo signal line.

Return Type: Servo Device

Returns: A valid servo_device, or nullptr on failure.

Signatures:

servo_device open_servo(const string &name, gpio_pin control_pin)

Look up an already‐opened servo by name.

Parameters:

NameTypeDescription
nameStringYour identifier for this servo.

Return Type: Servo Device

Returns: A valid servo_device, or nullptr if not found.

Signatures:

servo_device servo_named(const string &name)

Convenience: map an angle (0…180°) into the 500…2500 µs range. This is a linear mapping, so it may not be accurate for all servos.

Parameters:

NameTypeDescription
devServo DeviceThe servo device to control.
angle_degreesDoubleThe angle in degrees (0…180).

Signatures:

void set_servo_angle(servo_device dev, double angle_degrees)

Stop sending pulses (servo will hold last position or drift). This is a convenience function that sets the pulse width to 0.

Parameters:

NameTypeDescription
devServo DeviceThe servo device to control.

Signatures:

void stop_servo(servo_device dev)

The Adc Device type is used to refer to ADC (Analog-to-Digital Converter) devices that can be managed by the SplashKit ADC code, such as ADS7830. ADC devices are:

ADC devices allow you to interface with external analog sensors or inputs, converting their signals into digital values for processing in your application.


The Motor Device type is used to refer to motor driver devices that can be managed by the SplashKit motor driver code. Motor devices are:

Motor devices allow you to control DC motors or similar devices using GPIO pins and PWM signals, enabling precise control over speed and direction.

Use Close Motor or Close All Motors to release resources associated with motor devices when they are no longer needed.


The Servo Device type is used to refer to servo driver devices that can be managed by the SplashKit servo driver code. Servo devices are: Opaque handle for a single‐pin servo device. Servo devices are:

  • checked with Has Servo Device to see if a servo is already opened,

  • accessed using Servo Named to retrieve an existing servo device by name,

  • opened using Open Servo with specific parameters such as a unique name and the GPIO pin for the servo signal line,

  • controlled using set_servo_pulsewidth to send raw pulse-width signals or Set Servo Angle to map an angle (0–180°) into the pulse-width range,

  • stopped using Stop Servo to halt signal pulses while holding the last position or allowing the servo to drift,

  • and must be released using Close Servo (to release a specific servo device by handle or name) or Close All Servos (to release all opened servo devices).

Servo devices allow you to control hobby servos or similar devices using GPIO pins and PWM signals, enabling precise control over position and movement.

Use Close Servo or Close All Servos to release resources associated with servo devices when they are no longer needed.