aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 9072edd4a3cfa0da2ea052e86ee2773ff6a69759 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# HsMouse
Experimental control software for robotics, tested on Raspberry Pi 5.

## System Configuration:
To configure the system, the files in the `sysconf` directory must be
installed:

1. Copy the UDEV `*.rule` files into `/etc/udev/rules.d`
2. Copy `config.txt` to `/boot`
3. Reboot the Raspberry Pi for the changes to take effect

## Low Power Consumption When Powered Off:
By default, the Raspberry Pi 5 keeps the SoC powered on (in a shutdown state)
even after the system is shut down. As a result, it continues to consume
1.2-1.6W of power, even with nothing plugged in except for power. For more
details, see:
[Reducing Raspberry Pi 5's Power Consumption](https://www.jeffgeerling.com/blog/2023/reducing-raspberry-pi-5s-power-consumption-140x)

This can be easily fixed by editing the EEPROM configuration with the
following command:
```console
user@alarm$ sudo rpi-eeprom-config -e
```
Ensure that `POWER_OFF_ON_HALT=1` is set, while leaving the other variables
unchanged:
```config
[all]
BOOT_UART=[...]
POWER_OFF_ON_HALT=1
BOOT_ORDER=[...]
```

To run `rpi-eeprom-config` on Arch Linux, you’ll need to install the
`rpi5-eeprom` package from the `PKGBUILDs` repository. Run the following
commands to do so:
```console
user@alarm$ git clone https://github.com/archlinuxarm/PKGBUILDs
user@alarm$ cd PKGBUILDs/alarm/rpi-eeprom
user@alarm$ makepkg -s
user@alarm$ sudo pacman -U rpi5-eeprom-*.pkg.tar.xz
```

## GPIO and PWM Access Without Root:
To enable GPIO and PWM access without root privileges on the Raspberry Pi 5,
follow these steps:

1. Create two new user groups: `gpiod` and `pwm`
2. Add your user to both groups
3. The UDEV rules installed previously will grant the `gpiod` and `pwm` user
   groups permission to access the respective subsystems.

This configuration ensures that GPIO and PWM operations can be performed
without needing root access.

## Libcamera Setup
The upstream libcamera package in Arch Linux ARM (as of August 2025) has
compatibility issues with the Raspberry Pi kernel, preventing detection of
official camera modules. Until this is resolved upstream, you'll need to build
the Raspberry Pi Foundation's supported version:
```console
user@alarm$ sudo pacman -S boost cmake gcc git libdrm libexif libjpeg libpng libtiff meson pkgconf python-jinja python-ply python-yaml
user@alarm$ git clone https://github.com/raspberrypi/libcamera
user@alarm$ cd libcamera
user@alarm$ meson setup build -Dprefix=/usr
user@alarm$ ninja -C build
user@alarm$ sudo ninja -C build install
```

References:

- [RPi Kernel Issue #6983](https://github.com/raspberrypi/linux/issues/6983)
- [Libcamera Installation Guide](https://blog.jirkabalhar.cz/2024/02/raspberry-camera-on-archlinux-arm-in-2024/)

## I2C Setup:
The provided `config.txt` exposes `/dev/i2c-0` on GPIO pins 0 (SDA) and 1 (SCL).
Ensure your user has I2C permissions:
```console
user@alarm$ sudo usermod ${USER} -aG i2c
```

Verify the interface works. Expected output (no devices yet):
```console
user@alarm$ sudo i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
```

## Battery Monitoring with INA226
This repository includes INA226 voltage/current sensing via I2C.
For battery-powered operation:

### Hardware Connections
1. Battery terminals: V+/V- on INA226
2. Load current path (Pi + motor controllers): I+/I- on INA226
3. I2C lines: SDA/SCL (GPIO 0/1)
4. 3V3 power and GND

The INA226 should appear at address `0x40`:
```console
user@alarm$ sudo i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
```

## Build Instructions:
1. Install [`stack`](https://docs.haskellstack.org/en/stable/). It’s
   recommended to use [`ghcup`](https://www.haskell.org/ghcup/) for
   installation.
2. Run `make` to compile the libraries and executables

> Note: You may need to install system dependencies on your host first (e.g.,
> `libgpiod`, `libcamera`, etc.)