> For the complete documentation index, see [llms.txt](https://auvidea.gitbook.io/r20.1-r21-r22-software-setup-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://auvidea.gitbook.io/r20.1-r21-r22-software-setup-guide/guide/r-group-software-setup-guide.md).

# R- Group Software Setup Guide

Setup guide for the R product group: R20.1, R21, R22,...

## Flashing to SD-Card

Before using the Rxx you will need to prepare a micro SD card for the Raspberry Pi Zero. Start by flashing your micro SD using any flashing tool like the '[Raspberry Pi Imager](https://www.raspberrypi.com/software/)' (available for Linux, Windows and macOS) and select any 32-bit OS – e.g. "Raspberry Pi OS (Legacy) Lite" from 2023-12-05.

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/KAuyCoGMi653Hk0S1mG1/image.png" alt=""><figcaption></figcaption></figure>

### Pre-boot Configuration

After your flashing tool is done writing the RPi OS, the config file in the micro SD card's "`bootfs`" (or "`boot`" in older releases) partition needs to be edited before putting it into the RPi Zero – this step is important because otherwise the Pi (depending on the chosen OS version) may not be able to boot. Navigate into the "`bootfs`" partition, open "`config.txt`" and append the following in a new line:

```bash
gpio=21=op,dl
```

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/AM8P3yQd1LdkTLHB2I2i/image.png" alt=""><figcaption></figcaption></figure>

Now you can put the micro SD card into the Pi Zero and power on the R21.

## Enable I2C

Several resources on the carrier board are linked to the Cam I²C, which is hidden by default.

```bash
sudo raspi-config
```

`3 Interface Options` → `I5 I2C` → Press Tab, select and to reboot

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/oFZHVJTQ9uXW4iu2femZ/image.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/RgyDnkaN2IONxXmovQPv/image.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/ziyWFbt5RhoayRIKD03R/image.png" alt=""><figcaption></figcaption></figure>

## Accessing carrier board EEPROM

Write protection is activated by default. To deactivate it temporarily, short the pins located 1 CM above the Pi Zero's SD card slot during the writing process.

`i2c-tools` are used in this example to read and write data to the EEPROM. This library can be installed with the following commands:&#x20;

```bash
sudo apt update
sudo apt install i2c-tools
```

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/sqlAk6sxiUwtqv1daf63/image.png" alt=""><figcaption></figcaption></figure>

Read or writing to an I²C device is performed with   `i2cset` , `i2cget`or `i2ctransfer` on the device address `0x50` and I²C bus  `1`

More Information about I²C can be found in our [I2C - Guide](https://auvidea.gitbook.io/i2c/)

```bash
sudo i2cdetect -y -r 1
```

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/A1NLilZqHiK8iBpp7xKU/image.png" alt=""><figcaption><p>I²C device list on bus 1</p></figcaption></figure>

```bash
sudo i2cdump -y 1 0x50
```

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/FQ9GLlFhFrk0ZXjchsVm/image.png" alt=""><figcaption><p>Contents of EEPROM using i2cdump</p></figcaption></figure>

```bash
sudo i2ctransfer -y 1 w5@0x50 0x00 0x54 0x45 0x53 0x54
sudo i2cdump -y 1 0x50
```

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/Y22Aec48Xc3Zw7Z7eFtS/image.png" alt=""><figcaption><p>Example write to EEPROM and dump of changed content</p></figcaption></figure>

The following example tries to overwrite the written data in the previous step without the write protect pin shorted.

```bash
sudo i2ctransfer -y 1 w5@0x50 0x00 0xff 0xff 0xff 0xff
sudo i2cdump -y 1 0x50
```

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/RYtYiec8nGpOIhJztiUM/image.png" alt=""><figcaption><p>Write with write protect enabled</p></figcaption></figure>

## GPIO Functions

### Command cheat sheet

```bash
echo [GPIO_NR] > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio[GPIO_NR]/direction
echo [0/1] > /sys/class/gpio/gpio[GPIO_NR]/value
```

A more detailed description on how to use GPIO's are described in our [GPIO - Guide](https://auvidea.gitbook.io/gpio/)

<table><thead><tr><th width="118.33333333333331">Functjion</th><th width="176">Default state</th><th>Description</th></tr></thead><tbody><tr><td>RGB LED</td><td>Low</td><td>GPIO19 = R, GPIO13 = G, GPIO26 = B; high active</td></tr><tr><td>USB Hub</td><td>High</td><td>GPIO16; high active</td></tr><tr><td>M.2 LTE</td><td>High</td><td>GPIO17; high active</td></tr><tr><td>M.2 SSD</td><td>High</td><td>GPIO21; ;disabled by previous modification in "/boot/config.txt"</td></tr></tbody></table>

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/rewEE4VQ2PTjK6Jjhyt4/image.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/gOCcUhkEWSakHh25sg1L/image.png" alt=""><figcaption></figcaption></figure>

### Enable/Disable M.2 SSD

```bash
echo 21 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio21/direction
echo 1 > /sys/class/gpio/gpio21/value # Set GPIO to 1 -> Enable SSD Slot
```

After the enable signal is activated, the USB to PCIe converter is detected as a `JMicron Technology Corp.` device when using the `lsusb` command.

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/gHNHM87cVre0DKnwDuro/image.png" alt=""><figcaption><p>lsusb output before and after enable signal</p></figcaption></figure>

When using `lsblk` the connected SSD should be identifiable as an `sdx` device. In the following example visible as `/dev/sda`.

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/6GlCzhAXJGQVoabqQt9N/image.png" alt=""><figcaption><p>lsblk output &#x26; example mount</p></figcaption></figure>

### Enabling/Disable M.2 LTE module

```bash
echo 17 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio17/direction
echo 1 > /sys/class/gpio/gpio17/value # Set GPIO to 1 -> Enable M.2 LTE Slot
```

After the enable signal is activated, the LTE Module used in the following example is detected as `Sierra Wireless Inc.` device when using the `lsusb` command.

<figure><img src="https://content.gitbook.com/content/9srEmqRp7iqMWC9eJEyg/blobs/PDsFXUvr9qbo3TUYNNOW/image.png" alt=""><figcaption><p>lsusb output for M.2 LTE Module</p></figcaption></figure>
