Zero 2W has 2 micro USB ports. One for power only, and another for USB dual-role port.
/boot/firmware/config.txt:
[all]
enable_uart=1
make_keyboard.sh works on Raspberry Pi Zero 2W, as well. But, you have to set the microUSB port as “otg” or “peripherial” mode in /boot/firmware/config.txt.
[all]
dtoverlay=dwc2
GPIO pins can be accessed by
/sys/class/gpio
cd /sys/class/gpio
echo $((512+26)) > export
cd gpio538
echo out > direction
echo 1 > value
echo 0 > value
and to reset the pin,
cd /sys/class/gpio
echo 538 > unexport
gpioget, gpioset
gpioget -c0 26
gpioset -c0 26=on
gpioset -c0 26=off
Zero 2W has 2 PWM channels:
| pwm | pin | gpio | func | mode |
|---|---|---|---|---|
| PWM0 | PIN32 | GPIO12 | 4 | Alt0 |
| PWM1 | PIN33 | GPIO13 | 4 | Alt0 |
There are many ways to produce PWM from Zero 2W.
-t option of gpioset:
gpioset -t1,1 -c0 26=on — turn on 1ms, turn off 1ms, and repeat. About 500Hz with 50% duty cycle, but not accurate.dtoverlay=pwm-gpio,gpio=16 — Accessing software PWM is the same as hardware PWM.
cd /sys/class/pwm/pwmchip0
echo 0 > export # --> pwm0
cd pwm0
echo $((2*1000*1000)) > period # 2ms = 500Hz
echo $((1*1000*1000)) > duty_cycle # 1ms = 50%
echo 1 > enable
dtoverlay=pwm,pin=12,func=4 — will enable only PWM0.
echo 0 > /sys/class/pwm/pwmchip0/export # --> pwm0
dtoverlay=pwm,pin=13,func=4 — will enable only PWM1.
echo 1 > /sys/class/pwm/pwmchip0/export # --> pwm1
dtoverlay=pwm-2chan,pin=12,func=4,pin2=13,func2=4
echo 0 > /sys/class/pwm/pwmchip0/export # --> pwm0
echo 1 > /sys/class/pwm/pwmchip0/export # --> pwm1
pinctrl set 12,13 a0 # --> a0 = Alt0