Skip to main content

40-pin LS connector

GPIO

RUBIK Pi 3 is compatible with WiringRP (based on the high-performance GPIO programming library WiringPi). It is recommended to use WiringRP for controlling and programming General-Purpose Inputs/Outputs (GPIOs). For more details about WiringRP, visit https://github.com/rubikpi-ai/WiringRP.

Pinout

The figure below shows the default functions of the RUBIK Pi 3 40-pin LS connector, most of which are compatible with the default functions of the 40-pin connector of open-source development boards.

The following table lists all the functions of the 40-pin LS connector, where the default ones are bolded in blue.

Use GPIOs

On RUBIK Pi 3, you can use shell commands or programming languages to control the General-Purpose Input/Output (GPIO).

Perform the following steps on your RUBIK Pi 3 to control GPIOs.

note

The following commands require the root privilege:

  • Use the sudo su command to switch to the root user.
  • Using WiringRP commands:

    Before using the WiringRP commands, install the WiringRP as follows:

  1. Add the RUBIK Pi public personal package archive (PPA) to your RUBIK Pi 3 Ubuntu software sources.

    REPO_ENTRY="deb http://apt.thundercomm.com/rubik-pi-3/noble ppa main"
    if ! grep -q "^[^#]*$REPO_ENTRY" /etc/apt/sources.list; then
    sudo sed -i '$a deb http://apt.thundercomm.com/rubik-pi-3/noble ppa main' /etc/apt/sources.list
    fi
    sudo apt update
  2. Run the following command to install WiringRP.

    sudo apt install wiringrp

    Use the following commands to operate GPIOs after installation:

  • View the GPIO status

    gpio readall

  • Set the GPIO mode

    gpio mode 15 in             # Set pin 15 to input mode
    gpio pins # Check the mode
    gpio mode 15 out # Set pin 15 to output mode
    gpio pins # Check the mode
  • Set the pin level

    gpio write 15 1             # Set pin 15 to high level
    gpio read 15 # Check the pin level
    gpio write 15 0 # Set pin 15 to low level
    gpio read 15 # Check the pin level
  • Operate nodes under /sys/class/gpio:

    The table below shows the GPIO subsystem numbering.

    1. Go to the /sys/class/gpio directory:

      cd /sys/class/gpio
    2. Export the GPIO to be controlled. For example, pin 13 GPIO_24:

      echo 571 > export
    3. Go to the gpio571 directory to set GPIO attributes:

      cd gpio571
      ls

    • direction:
      • input: in
      • output: out
    • value:
      • Low level: 0
      • High level: 1
    • edge (interrupt edge):
      • Rising edge trigger: rising

      • Falling edge trigger: falling

      • Both-edge trigger: both

      • Disabling interrupts: none

    1. For example, set pin 13 to output a high level:
    echo out > direction
    echo 1 > value
    1. Cancel the export of pin 13 to user space:
    cd ..
    echo 571 > unexport

I2C

Inter-Integrated circuit (I2C) is a bidirectional 2-wire bus for an efficient inter‑IC control bus developed by Philips in the 1980s. Every device on the bus has its own unique address (registered with the I2C general body headed by Philips). The I2C core supports multicontroller mode, 10‑bit target addressing, and 10‑bit extendable addressing. For more information on I2C, see https://www.i2c-bus.org/fileadmin/ftp/i2c_bus_specification_1995.pdf.

RUBIK Pi 3 is compatible with WiringRP (based on the high-performance GPIO programming library WiringPi). It is recommended to use WiringRP for controlling and programming I2C. For more details about WiringRP, visit https://github.com/rubikpi-ai/WiringRP.

Pinout

The figure below shows the default functions of the RUBIK Pi 3 40-pin LS connector, most of which are compatible with the default functions of the 40-pin connector of open-source development boards.

note

Pin 3 and pin 5 are set to I2C1 by default.

The following table lists all functions of the 40-pin LS connector, where the default ones are bolded in blue.

Use I2C

On RUBIK Pi 3, you can use shell commands or programming languages to control the I2C bus.

Perform the following steps on RUBIK Pi 3 to control the I2C bus. To install the WiringRP library on your RUBIK Pi 3, follow these steps:

  1. Add the RUBIK Pi public personal package archive (PPA) to your RUBIK Pi 3 Ubuntu software sources.
REPO_ENTRY="deb http://apt.thundercomm.com/rubik-pi-3/noble ppa main"
if ! grep -q "^[^#]*$REPO_ENTRY" /etc/apt/sources.list; then
sudo sed -i '$a deb http://apt.thundercomm.com/rubik-pi-3/noble ppa main' /etc/apt/sources.list
fi
sudo apt update
  1. To install the WiringRP library on the RUBIK Pi 3, follow these steps:
sudo apt install wiringrp
  • Use the WiringRP related command:

    ./gpio -x ads1115:100:10 aread 100     #Read the analog signal value of the ADS1115 device via the I2C bus.
  • Use the i2cdetect tool

    • View devices connected to the I2C1 interface:

      i2cdetect -a -y -r 1
    • Read all registers of the device whose address is 0x38:

      i2cdump -f -y 1 0x38
    • Write 0xaa to register 0x01 of the device whose address is 0x38:

      i2cset -f -y 1 0x38 0x01 0xaa
    • Read the value at register 0x01 of the device whose address is 0x38:

      i2cget -f -y 1 0x38 0x01
note

If commands like i2cdetect are not available, run apt install i2c-tools to install the i2c-tools package.

SPI

Serial Peripheral Interface (SPI) is a synchronous serial data link that operates in full-duplex mode. SPI is also known as a 4-wire serial bus.

RUBIK Pi 3 is compatible with WiringRP (based on the high-performance GPIO programming library WiringPi). It is recommended to use WiringRP for controlling and programming SPI. For more details about WiringRP, visit https://github.com/rubikpi-ai/WiringRP.

Pinout

The figure below shows the default functions of the RUBIK Pi 3 40-pin LS connector, most of which are compatible with the default functions of the 40-pin connector of open-source development boards.

note

Pins 19, 21, 23, and 24 are set to SPI by default.

The following table lists all functions of the 40-pin LS connector, where the default ones are bolded in blue.

Use SPI

The WiringRP library provides a set of API functions that enable control with minimal logic.

To install WiringRP on your RUBIK Pi 3, follow these steps:

  1. Add the RUBIK Pi public personal package archive (PPA) to your RUBIK Pi 3 Ubuntu software sources.
REPO_ENTRY="deb http://apt.thundercomm.com/rubik-pi-3/noble ppa main"
if ! grep -q "^[^#]*$REPO_ENTRY" /etc/apt/sources.list; then
sudo sed -i '$a deb http://apt.thundercomm.com/rubik-pi-3/noble ppa main' /etc/apt/sources.list
fi
sudo apt update
  1. Run the following command to install WiringRP.
sudo apt install wiringrp

The following code snippet uses the SPI bus to send and receive data.

#include <wiringPi.h>
#include <wiringPiSPI.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int fd;
unsigned char send_data[64] = "hello world!";
unsigned char read_data[64];

if(wiringPiSetup() == -1)
exit(1);

fd = wiringPiSPISetup(0, 1000000);
if(fd < 0)
exit(2);

printf("\rtx_buffer: \n %s\n ", send_data);
// Send and receive data
if(wiringPiSPIDataRW(0, send_data, sizeof(send_data)) < 0)
exit(3);
printf("\rtx_buffer: \n %s\n ", send_data);


return 0;
}

Compile programs

Compile on RUBIK Pi 3

gcc spi.c -o spi -lwiringPi
note

If the gcc command is not available, run apt install gcc to install the gcc compiler.

Short pin 19 and pin 21 with a Dupont wire to test the SPI bus communication, as shown in the following figure:

warning

Pay attention to the pin order. Do not short the power and ground pins, as this may cause damage to the board.

Run the following command:

./spi

The execution result is as follows:

UART

RUBIK Pi 3 is compatible with WiringRP (based on the high-performance GPIO programming library WiringPi). It is recommended to use WiringRP for controlling and programming UART. For more details about WiringRP, visit https://github.com/rubikpi-ai/WiringRP.

Pinout

The figure below shows the default functions of the RUBIK Pi 3 40-pin LS connector, most of which are compatible with the default functions of the 40-pin connector of open-source development boards.

note

Pins 8 and 10 have been set to UART by default. The device node is /dev/ttyHS2.

The following table lists all functions of the 40-pin LS connector, where the default ones are bolded in blue.

Use UART

Run the following commands on RUBIK Pi 3 to control UART communication.

Use the stty tool to configure UART. Run the following commands to set both the input rate and output rate of UART to 115200 and disable the echo.

stty -F /dev/ttyHS2 ispeed 115200 ospeed 115200
stty -F /dev/ttyHS2 -echo

Enable two terminals on RUBIK Pi 3, short pin 8 and pin 10 with a Dupont wire, and run the following commands. The content sent by the transmitter will be displayed on the receiver.

warning

Pay attention to the pin order. Do not short the power and ground pins, as this may cause damage to the board.

echo "hello world!" > /dev/ttyHS2  # Transmitter
cat /dev/ttyHS2 # Receiver