Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e5b8899488 | |||
| f79b9985db | |||
| 8963441a4f | |||
| 6009a5eff8 | |||
| 18d01e181f | |||
| 3358169ad8 | |||
| 8dac7f3656 | |||
| 8586a25547 | |||
| aa83f5c957 | |||
| b43d1d6798 | |||
| 2c1bba5a51 |
@@ -13,6 +13,7 @@ Scripts and documentation for setting up a Raspberry Pi (Zero W 1 or 2) for use
|
|||||||
- [Starting on Raspberry Pi Zero](https://reykjavik.instructure.com/courses/6589/pages/starting-on-raspberry-pi-zero-w)
|
- [Starting on Raspberry Pi Zero](https://reykjavik.instructure.com/courses/6589/pages/starting-on-raspberry-pi-zero-w)
|
||||||
|
|
||||||
## References and Links
|
## References and Links
|
||||||
|
- [Sparkfun GPIO pinout](https://cdn.sparkfun.com/assets/learn_tutorials/6/7/6/PiZero_1.pdf)
|
||||||
- [Guide to creating ssh keys](https://pimylifeup.com/raspberry-pi-ssh-keys/) Of note, this guide is a little dated as it suggests using RSA keys and many people are moving toward EDCSA keys.
|
- [Guide to creating ssh keys](https://pimylifeup.com/raspberry-pi-ssh-keys/) Of note, this guide is a little dated as it suggests using RSA keys and many people are moving toward EDCSA keys.
|
||||||
- [Raspberry Pi Connect](https://connect.raspberrypi.com)
|
- [Raspberry Pi Connect](https://connect.raspberrypi.com)
|
||||||
- [Setting up Raspberry Pi Connect](https://www.raspberrypi.com/documentation/services/connect.html)
|
- [Setting up Raspberry Pi Connect](https://www.raspberrypi.com/documentation/services/connect.html)
|
||||||
|
|||||||
+4
-6
@@ -12,19 +12,17 @@ fi
|
|||||||
|
|
||||||
# Is the dwc2 overlay installed? Nothing will work if it isn't.
|
# Is the dwc2 overlay installed? Nothing will work if it isn't.
|
||||||
if lsmod | grep -q "dwc2"; then
|
if lsmod | grep -q "dwc2"; then
|
||||||
echo "DWC2 module loaded, setting up OTG gadget serial and ethernet" | logger -t $0 -p info
|
systemd-cat -t gadget.sh -p info echo "DWC2 module loaded, setting up OTG gadget serial and ethernet"
|
||||||
echo "DWC2 module loaded"
|
|
||||||
else
|
else
|
||||||
echo "DWC2 module missing. Aborting OTG setup." | logger -t $0 -p info
|
systemd-cat -t gadget.sh -p warning echo "DWC2 module missing. Aborting OTG setup."
|
||||||
echo "DWC2 module missing"
|
|
||||||
systemctl disable serial-getty@ttyGS0.service
|
systemctl disable serial-getty@ttyGS0.service
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
modprobe libcomposite
|
sudo modprobe libcomposite
|
||||||
cd /sys/kernel/config/usb_gadget
|
cd /sys/kernel/config/usb_gadget
|
||||||
if [ -d "MyGadget" ]; then
|
if [ -d "MyGadget" ]; then
|
||||||
echo "MyGadget already exists. Aborting OTG setup." | logger -t $0 -p info
|
systemd-cat -t gadget.sh -p warning echo "MyGadget already exists. Aborting OTG setup."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -44,3 +44,12 @@ We don't have many monitors and keyboards in V207 for students to use, so we wil
|
|||||||

|

|
||||||
1. The process is complete! Now you can [connect to your pi](connect.md)
|
1. The process is complete! Now you can [connect to your pi](connect.md)
|
||||||

|

|
||||||
|
1. Take the SD card and put it into your pi.
|
||||||
|
1. When you first boot it, it can take 10 minutes to finish configuring itself. Usually when the LED stops blinking for at least 30 seconds, it is done.
|
||||||
|
|
||||||
|
## Connecting using Raspberry Pi Connect
|
||||||
|
1. Login to https://connect.raspberrypi.com if you haven't already
|
||||||
|
1. Look at the list of devices, find the one you want, and click on "Connect"
|
||||||
|

|
||||||
|
1. A remote shell window will pop up
|
||||||
|

|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# The Intertial Measurement Unit
|
||||||
|
|
||||||
|
As of 2025, we started using an AliExpress version of https://wolles-elektronikkiste.de/en/icm-20948-9-axis-sensor-part-i
|
||||||
|
|
||||||
|
This has an unmarked jumper on the back. Joe believes that it shorts the VDDIO and VDD pins in order to allow it to be used with 1.8V devices.
|
||||||
|
|
||||||
|
Marcel has tested that the pads connect to both of those pins.
|
||||||
|
|
||||||
|
The IMU runs on 1.8V, but our Pi has GPIO voltages of 3.3V. Marcel reports that students in 2025 had no problem using it as long as AD0 and NCS were connected to VDD.
|
||||||
|
According to the specification, the maximum pin voltage is VDDIO+0.5, which would put it at 2.3, a whole volt below 3.3. On his board, he connected the pins to 3.3V though a 10K resistor to protect it from overcurrent.
|
||||||
|
|
||||||
|
For I2C at least, it appears that we are saved by the fact that it is open-drain. Each device communicates to the master by pulling lines low, which should work with both voltages.
|
||||||
|
|
||||||
Executable
+19
@@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# From https://raspberry.tips/en/raspberrypi-tutorials/raspberry-pi-gpio-python
|
||||||
|
import lgpio
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Open GPIO chip (0 = /dev/gpiochip0, on Pi 5 gpiochip4 also possible)
|
||||||
|
h = lgpio.gpiochip_open(0)
|
||||||
|
|
||||||
|
try:
|
||||||
|
lgpio.gpio_claim_output(h, 18) # GPIO18 (pin 12) as output (MOTA1)
|
||||||
|
|
||||||
|
for _ in range(5):
|
||||||
|
lgpio.gpio_write(h, 18, 1) # HIGH
|
||||||
|
time.sleep(0.5)
|
||||||
|
lgpio.gpio_write(h, 18, 0) # LOW
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
finally:
|
||||||
|
lgpio.gpiochip_close(h) # Always close!
|
||||||
Executable
+34
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# This test assumes you are trying to control a motor through a DRV8833 motor
|
||||||
|
# controller chip. This general approach should work for other motors as well.
|
||||||
|
import lgpio
|
||||||
|
import time
|
||||||
|
|
||||||
|
# pin assignments
|
||||||
|
gpio_pwm = 18 #MOTA1
|
||||||
|
gpio_reverse = 16 #MOTA2
|
||||||
|
gpio_notsleep = 24 #MSLEEP
|
||||||
|
# parameters
|
||||||
|
pwm_freq = 1000
|
||||||
|
|
||||||
|
|
||||||
|
h = lgpio.gpiochip_open(0)
|
||||||
|
try:
|
||||||
|
lgpio.gpio_claim_output(h, gpio_reverse)
|
||||||
|
lgpio.gpio_claim_output(h, gpio_notsleep)
|
||||||
|
lgpio.gpio_write(h, gpio_reverse, 0) # low on reverse pin to turn off h-bridge MOTA2
|
||||||
|
lgpio.gpio_write(h, gpio_notsleep, 1) # high on /sleep to enable both h-bridges
|
||||||
|
|
||||||
|
while True:
|
||||||
|
for pwm_level in range(0,100):
|
||||||
|
lgpio.tx_pwm(h, gpio_pwm, pwm_freq, pwm_level)
|
||||||
|
pwm_level += 10
|
||||||
|
time.sleep(0.05)
|
||||||
|
for pwm_level in range(100,0,-1):
|
||||||
|
lgpio.tx_pwm(h, gpio_pwm, pwm_freq, pwm_level)
|
||||||
|
pwm_level += 10
|
||||||
|
time.sleep(0.05)
|
||||||
|
|
||||||
|
finally:
|
||||||
|
lgpio.gpio_write(h, gpio_notsleep, 1) # high on /sleep to disable
|
||||||
|
lgpio.gpiochip_close(h) # Always close!
|
||||||
Executable
+25
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# From https://raspberry.tips/en/raspberrypi-tutorials/raspberry-pi-gpio-python
|
||||||
|
import lgpio
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Open GPIO chip (0 = /dev/gpiochip0, on Pi 5 gpiochip4 also possible)
|
||||||
|
h = lgpio.gpiochip_open(0)
|
||||||
|
# Hardware PWM on GPIO18 (pin 12) must be PWM-capable
|
||||||
|
pwm_pin = 18
|
||||||
|
pwm_freq = 1000
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
for pwm_level in range(0,100):
|
||||||
|
lgpio.tx_pwm(h, pwm_pin, pwm_freq, pwm_level)
|
||||||
|
pwm_level += 10
|
||||||
|
time.sleep(0.05)
|
||||||
|
for pwm_level in range(100,0,-1):
|
||||||
|
lgpio.tx_pwm(h, pwm_pin, pwm_freq, pwm_level)
|
||||||
|
pwm_level += 10
|
||||||
|
time.sleep(0.05)
|
||||||
|
|
||||||
|
|
||||||
|
finally:
|
||||||
|
lgpio.tx_pwm(h, pwm_pin, 0, 0) # Stop PWM
|
||||||
|
lgpio.gpiochip_close(h) # Always close!
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
# Getting the PWM working
|
||||||
|
|
||||||
|
The Raspberry Pi zero (1 and 2) have 2 PWM peripherals, allowing you to pulse pins without the CPU doing any additional work. This is particuarly useful for controlling motor speeds when connected to a motor driver/H-bridge chip.
|
||||||
|
|
||||||
|
|
||||||
|
# References
|
||||||
|
- [Raspberry Pi Official Overlays information (github)](https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README)
|
||||||
|
- Line 4235 starts the description of the "pwm" overlay configuration
|
||||||
|
- [Adding Basic Audio Ouput to Raspberry Pi Zero](https://learn.adafruit.com/adding-basic-audio-ouput-to-raspberry-pi-zero/pi-zero-pwm-audio)
|
||||||
|
|
||||||
|
# Important Points
|
||||||
|
1. The `gpio` program is no longer available. It has been replaced with `pinctrl` which works a little differently.
|
||||||
|
|
||||||
|
# Discussion
|
||||||
|
|
||||||
|
My raspberry pi zero W 2 wasn't working reliably with the PWM.
|
||||||
|
|
||||||
|
The `gpio` command has been depricated and is now replaced by the `pinctrl` commend. Running it did not list any PWM0 on any of the pins, which was concerning.
|
||||||
|
|
||||||
|
[This forum post](https://forums.raspberrypi.com/viewtopic.php?t=388352) indicated the need for a `pwm-2chan` device tree overlay to get it to show up. After adding `dtoverlay=pwm-2chan` to the `config.txt`:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ pinctrl
|
||||||
|
0: ip -- | hi // ID_SDA/GPIO0 = input
|
||||||
|
1: ip -- | hi // ID_SCL/GPIO1 = input
|
||||||
|
2: a0 -- | hi // GPIO2 = SDA1
|
||||||
|
3: a0 -- | hi // GPIO3 = SCL1
|
||||||
|
4: op -- -- | hi // GPIO4 = output
|
||||||
|
5: ip -- | hi // GPIO5 = input
|
||||||
|
6: ip -- | hi // GPIO6 = input
|
||||||
|
7: op -- -- | hi // GPIO7 = output
|
||||||
|
8: op -- -- | hi // GPIO8 = output
|
||||||
|
9: a0 -- | lo // GPIO9 = SPI0_MISO
|
||||||
|
10: a0 -- | lo // GPIO10 = SPI0_MOSI
|
||||||
|
11: a0 -- | lo // GPIO11 = SPI0_SCLK
|
||||||
|
12: ip -- | lo // GPIO12 = input
|
||||||
|
13: ip -- | lo // GPIO13 = input
|
||||||
|
14: ip -- | lo // GPIO14 = input
|
||||||
|
15: ip -- | hi // GPIO15 = input
|
||||||
|
16: ip -- | lo // GPIO16 = input
|
||||||
|
17: ip -- | lo // GPIO17 = input
|
||||||
|
18: a5 -- | lo // GPIO18 = PWM0
|
||||||
|
19: a5 -- | lo // GPIO19 = PWM1
|
||||||
|
```
|
||||||
|
|
||||||
|
Which looks much better.
|
||||||
|
There is a pwm chip `in /sys/class/pwm`
|
||||||
|
|
||||||
|
After running the `lgpio/pwm-test.py`
|
||||||
|
the pin is back to being listed as an input, so I'm confused.
|
||||||
|
The PWM pin (under load) did the right values. Without a load on the Analog Discovery 2, I just saw noise.
|
||||||
|
|
||||||
|
I commented out `dtoverlay=pwm-2chan` and `lgpio/pwm-test.py` worked.
|
||||||
|
The pwm chip is missing from `/sys/class/pwm` so I'm guess that's not needed.
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user