Jump to content

Rasberry Pi: Difference between revisions

From Smithnet Wiki
 
(88 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Device ==
== Device ==


* [https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-3-model-b Rasberry Pi 3B]
* [https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-3-model-b Rasberry Pi 3B] ("Rev 1.2")


== Windows IOT ==
cat /proc/device-tree/model


* [https://devblogs.microsoft.com/premier-developer/getting-started-with-windows-10-iot-core-raspberry-pi-3b/ Blog]
Hardware info:
* AV Connector:
** 1 (tip): L Audio
** 2: R Audio
** 3: Ground
** Sleeve: Composite Video.
* [https://www.raspberrypi.com/documentation/computers/raspberry-pi.html Boards]
* [https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#gpio GPIO Header]
** 3.3 V on data lines only
** Pin numbers differ from chip/programmatic pin numbers
** 3.3 V power lines: 150-200 mA max
** 5 V power lines: from the main PSU input (reserve 1 A for Pi itself)
** Data lines: 15 mA max per pin, 50 mA total from all pins


== Rasberry Pi OS ==
== Rasbery Pi OS ==


* ?
See [https://www.raspberrypi.com/documentation/computers/config_txt.html  /boot/firmware/config.txt].
 
Command line configuration program:
raspi-config
 
eg to enable I2C interface.
 
Upgrade:
apt update
apt list --upgradeable
apt upgrade -y
 
=== Apache Web Server ===
 
apt install apache2 -y
 
* Configuration: /etc/apache2
* Serve from: /var/www/html
 
=== Composite Video ===
 
Will default to NTSC; in /boot/firmware/cmdline.txt, add this to the end for PAL 50i:
video=Composite-1:720x576@50ie
 
Alternatives include:
* NTSC: 720x480@60ie
* PAL60: 720x480@60ie
 
This will show the Pi desktop. Stop it to allow direct access to the framebuffer /dev/fb0:
systemctl stop lightdm
 
See also:
raspi-config
 
* 1 System Options -> S5 Boot / Auto Login -> B1 Console
 
Can explicitly set the standard:
video=Composite-1:720x576@50ie,tv_mode=PAL
 
Alternatives:
* PAL / PAL-M / PAL-N
* NTSC / NTSC-J (Japan) / NTSC-443
* SECAM
 
To avoid overscan on TVs, add padding:
video=Composite-1:720x576@50ie,margin_left=48,margin_right=48,margin_top=12,margin_bottom=12
 
=== Go Development ===
 
Because of limited RAM, best to cross compile on a more powerful system:
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build myprog.go
 
Or install ARMv6 release:
wget https://go.dev/dl/go1.26.3.linux-armv6l.tar.gz
tar -C /usr/local -xzf go1.26.3.linux-armv6l.tar.gz
 
Set environment variables:
PATH=$PATH:/usr/local/go/bin
GOPATH=$HOME/go
 
=== GPIO Development ===
 
Raspberry Pi OS use the newer gpiod subsystem (which interacts with /dev/gpiochip0).
 
In C++:
apt install libgpiod-dev gpiod -y
g++ -O3 prog.cpp -o prog -lgpiodcxx
 
See [https://libgpiod.readthedocs.io/en/master/ documentation].
 
In Python, use:
apt install python3-dev -y
 
for python gpiod bindings. See [https://pypi.org/project/gpiod/ documentation].
 
Or the abstraction:
apt install python3-gpiozero -y
 
In Go, use: periph.io
 
=== I2C Development ===
 
Check devices:
i2cdetect -y 1
 
Get a byte (BME280/BMP280 chip ID register 0xD0):
i2cget -y 1 0x76 0xD0
 
This returns 0x60 for BME280, 0x58 for BMP280)
 
In C++:
apt install libi2c-dev
g++ i2c_prog.cpp -o i2c_prog -li2c
 
=== Mail ===
 
MUA:
apt install bsd-mailx
apt install mutt
 
Mount mail directory from server:
mailhost:/var/spool/mail    /var/mail    nfs    rw,nofail,noatime,_netdev,soft    0    0
 
Or use automounter (see other section). Note: UID/GID must match.
 
Exim is the default MTA:
dpkg-reconfigure exim4-config
update-exim4.conf
systemctl restart exim4
 
Monitor logs:
tail -f /var/log/exim4/mainlog
 
=== NFS Automounter ===
 
apt install autofs nfs-common -y
 
To allow remove mounts to be accessed under /net/<server>/<export>, edit /etc/auto.master and enable the host map:
/net    -hosts --timeout=60
 
systemctl enable autofs
systemctl restart autofs
 
To mount remote mail directory:
 
Create the new /etc/auto.master.d/mail.autofs file:
/-    /etc/auto.direct    --timeout=60
 
Create the /etc/auto.direct file:
/var/mail    -fstype=nfs,rw,soft,tcp,rsize=8192,wsize=8192    mailhost:/var/spool/mail
 
systemctl restart autofs
 
=== NTP Client ===
 
apt install systemd-timesyncd -y
 
Edit /etc/systemd/timesyncd.conf and set NTP parameter
systemctl restart systemd-timesyncd
timedatectl status
timedatectl timesync-status
 
=== Service ===
 
Create a service file /etc/systemd/system/temp-logger.service:
[Unit]
Description=CPU Temperature Logger to HTML
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/temp_logger.sh
# Run as root or www-data depending on who owns your /var/www/html directory
User=root
 
Create a systemd timer /etc/systemd/system/temp-logger.timer:
[Unit]
Description=Run Pi Temperature Logger every 5 minutes
[Timer]
# Run 5 minutes after boot-up
OnBootSec=5min
# Run every 5 minutes relative to when the timer was started
OnUnitActiveSec=5min
# Ensures precision alignment to the clock wall if desired (optional)
AccuracySec=1s
[Install]
WantedBy=timers.target
 
Reload systemd,
systemctl daemon-reload
systemctl enable --now temp-logger.timer
 
=== SSH ===
 
Copy key (and generate ~/.ssh) from client tp pi:
ssh-copy-id [email protected]
 
=== Stress ===
 
apt install stress-ng
 
Run memory test:
stress-ng --vm 1 --vm-bytes 750M --timeout 120 --vm-keep --vm-method rand-sum
 
CPU test:
stress-ng --cpu 4 --cpu-method matrixprod --timeout 300
 
=== Swap ===
free -m
swapon --show
 
To see current zram configuration:
zramctl
zramctl --output-all /dev/zram0
 
Configure hybrid configuration, overruding default /etc/rpi/swap.conf in /etc/rpi/swap.conf.d/hybrid-swap.conf:
[Main]
Mechanism=zram+file
[Zram]
FixedSizeMiB=512
[File]
FixedSizeMiB=1024
 
Ensure systemd component is enabled and reboot:
systemctl enable var-swap.swap
 
There is no need to recreate/resize the /var/swap physical file, which is done at boot time if necessary. In this mode, file system swap will not be visible with swapon; instead it is owned by the zram kernel driver. Zram blocks are pushed to/from file as needed.
 
=== Temperature ===
 
echo "scale=2; $(cat /sys/class/thermal/thermal_zone0/temp) / 1000" | bc
 
CPU Core throttling above 80 C.
 
=== Wifi ===
 
Turn off wifi:
nmcli radio wifi off

Latest revision as of 17:45, 17 June 2026

Device

cat /proc/device-tree/model

Hardware info:

  • AV Connector:
    • 1 (tip): L Audio
    • 2: R Audio
    • 3: Ground
    • Sleeve: Composite Video.
  • Boards
  • GPIO Header
    • 3.3 V on data lines only
    • Pin numbers differ from chip/programmatic pin numbers
    • 3.3 V power lines: 150-200 mA max
    • 5 V power lines: from the main PSU input (reserve 1 A for Pi itself)
    • Data lines: 15 mA max per pin, 50 mA total from all pins

Rasbery Pi OS

See /boot/firmware/config.txt.

Command line configuration program:

raspi-config

eg to enable I2C interface.

Upgrade:

apt update
apt list --upgradeable
apt upgrade -y

Apache Web Server

apt install apache2 -y
  • Configuration: /etc/apache2
  • Serve from: /var/www/html

Composite Video

Will default to NTSC; in /boot/firmware/cmdline.txt, add this to the end for PAL 50i:

video=Composite-1:720x576@50ie

Alternatives include:

* NTSC: 720x480@60ie
* PAL60: 720x480@60ie

This will show the Pi desktop. Stop it to allow direct access to the framebuffer /dev/fb0:

systemctl stop lightdm

See also:

raspi-config
  • 1 System Options -> S5 Boot / Auto Login -> B1 Console

Can explicitly set the standard:

video=Composite-1:720x576@50ie,tv_mode=PAL

Alternatives:

  • PAL / PAL-M / PAL-N
  • NTSC / NTSC-J (Japan) / NTSC-443
  • SECAM

To avoid overscan on TVs, add padding:

video=Composite-1:720x576@50ie,margin_left=48,margin_right=48,margin_top=12,margin_bottom=12

Go Development

Because of limited RAM, best to cross compile on a more powerful system:

CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build myprog.go

Or install ARMv6 release:

wget https://go.dev/dl/go1.26.3.linux-armv6l.tar.gz
tar -C /usr/local -xzf go1.26.3.linux-armv6l.tar.gz

Set environment variables:

PATH=$PATH:/usr/local/go/bin
GOPATH=$HOME/go

GPIO Development

Raspberry Pi OS use the newer gpiod subsystem (which interacts with /dev/gpiochip0).

In C++:

apt install libgpiod-dev gpiod -y
g++ -O3 prog.cpp -o prog -lgpiodcxx

See documentation.

In Python, use:

apt install python3-dev -y

for python gpiod bindings. See documentation.

Or the abstraction:

apt install python3-gpiozero -y

In Go, use: periph.io

I2C Development

Check devices:

i2cdetect -y 1

Get a byte (BME280/BMP280 chip ID register 0xD0):

i2cget -y 1 0x76 0xD0

This returns 0x60 for BME280, 0x58 for BMP280)

In C++:

apt install libi2c-dev
g++ i2c_prog.cpp -o i2c_prog -li2c

Mail

MUA:

apt install bsd-mailx
apt install mutt

Mount mail directory from server:

mailhost:/var/spool/mail    /var/mail    nfs    rw,nofail,noatime,_netdev,soft    0    0

Or use automounter (see other section). Note: UID/GID must match.

Exim is the default MTA:

dpkg-reconfigure exim4-config
update-exim4.conf
systemctl restart exim4

Monitor logs:

tail -f /var/log/exim4/mainlog

NFS Automounter

apt install autofs nfs-common -y

To allow remove mounts to be accessed under /net/<server>/<export>, edit /etc/auto.master and enable the host map:

/net    -hosts --timeout=60
systemctl enable autofs
systemctl restart autofs

To mount remote mail directory:

Create the new /etc/auto.master.d/mail.autofs file:

/-    /etc/auto.direct    --timeout=60

Create the /etc/auto.direct file:

/var/mail    -fstype=nfs,rw,soft,tcp,rsize=8192,wsize=8192    mailhost:/var/spool/mail
systemctl restart autofs

NTP Client

apt install systemd-timesyncd -y

Edit /etc/systemd/timesyncd.conf and set NTP parameter

systemctl restart systemd-timesyncd
timedatectl status
timedatectl timesync-status

Service

Create a service file /etc/systemd/system/temp-logger.service:

[Unit]
Description=CPU Temperature Logger to HTML
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/temp_logger.sh
# Run as root or www-data depending on who owns your /var/www/html directory
User=root

Create a systemd timer /etc/systemd/system/temp-logger.timer:

[Unit]
Description=Run Pi Temperature Logger every 5 minutes

[Timer]
# Run 5 minutes after boot-up
OnBootSec=5min
# Run every 5 minutes relative to when the timer was started
OnUnitActiveSec=5min
# Ensures precision alignment to the clock wall if desired (optional)
AccuracySec=1s

[Install]
WantedBy=timers.target

Reload systemd,

systemctl daemon-reload
systemctl enable --now temp-logger.timer

SSH

Copy key (and generate ~/.ssh) from client tp pi:

ssh-copy-id [email protected]

Stress

apt install stress-ng

Run memory test:

stress-ng --vm 1 --vm-bytes 750M --timeout 120 --vm-keep --vm-method rand-sum

CPU test:

stress-ng --cpu 4 --cpu-method matrixprod --timeout 300

Swap

free -m
swapon --show

To see current zram configuration:

zramctl 
zramctl --output-all /dev/zram0

Configure hybrid configuration, overruding default /etc/rpi/swap.conf in /etc/rpi/swap.conf.d/hybrid-swap.conf:

[Main]
Mechanism=zram+file

[Zram]
FixedSizeMiB=512

[File]
FixedSizeMiB=1024

Ensure systemd component is enabled and reboot:

systemctl enable var-swap.swap

There is no need to recreate/resize the /var/swap physical file, which is done at boot time if necessary. In this mode, file system swap will not be visible with swapon; instead it is owned by the zram kernel driver. Zram blocks are pushed to/from file as needed.

Temperature

echo "scale=2; $(cat /sys/class/thermal/thermal_zone0/temp) / 1000" | bc

CPU Core throttling above 80 C.

Wifi

Turn off wifi:

nmcli radio wifi off