Compare commits
46 Commits
16ba60f833
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 464ed79f95 | |||
| d86c7a224d | |||
| 582e2d4a16 | |||
| 33914344ff | |||
| a743e06b9b | |||
| e5b8899488 | |||
| f79b9985db | |||
| 8963441a4f | |||
| 6009a5eff8 | |||
| 18d01e181f | |||
| 3358169ad8 | |||
| 8dac7f3656 | |||
| 8586a25547 | |||
| aa83f5c957 | |||
| b43d1d6798 | |||
| 9f51718235 | |||
| 01b3a189ed | |||
| 3ef2ca02a6 | |||
| cc0b37af8b | |||
| 17c0ffab67 | |||
| 29fb570ae5 | |||
| b667926315 | |||
| 1522244561 | |||
| ca46da2501 | |||
| aebf3aaab8 | |||
| f8dac3c07f | |||
| c6f1642209 | |||
| 2c1bba5a51 | |||
| 37f5100dac | |||
| 60284fdbd7 | |||
| 1eb4e23862 | |||
| 39aeb47d0e | |||
| 6a70ef94d1 | |||
| b7a327904e | |||
| 2595422ec2 | |||
| 789cb5e70e | |||
| d10ad7ee94 | |||
| 5583d2f8d7 | |||
| 73408d620d | |||
| 5ddec9af64 | |||
| 496982c80d | |||
| 923cd37195 | |||
| c818bc62c1 | |||
| c166e10a56 | |||
| 82ca6e9185 | |||
| c4ccb48464 |
@@ -225,3 +225,4 @@ cython_debug/
|
||||
# PyPI configuration file
|
||||
.pypirc
|
||||
|
||||
*.html
|
||||
|
||||
@@ -2,21 +2,36 @@
|
||||
|
||||
Scripts and documentation for setting up a Raspberry Pi (Zero W 1 or 2) for use in Mechatronics 1 or Cyberphysical Systems. This single-board Linux computer is equivalent in power to the Raspberry Pi 2 but in a smaller form factor, includes WiFi and Bluetooth, and is very affordable at 15USD. For operations that need higher computing power, we recommend the Raspberry Pi 3 or 4 which can be purchased later.
|
||||
|
||||
# Guides
|
||||
- [Raspberry Pi Imager procedure to setup ssh and Raspberry Pi Connect](imager.md)
|
||||
- [Gadget Mode using ]
|
||||
- [Marcel's script on github to show the IP address on the OLED screen](https://github.com/mkyas/cpsy-display-ip)
|
||||
# Procedure
|
||||
1. [Raspberry Pi Imager procedure to setup ssh and Raspberry Pi Connect](imager.md)
|
||||
1. Find out your Pi's ethernet addresss in case you need to find it on `iot-research` again. Type `ip addr show dev wlan0` and for something like `link/ether 01:23:45:67:89:ab`. Write this information (the 12 characters and colons) in your notebook. In T-411-MECH we want you to put this information in a spreadsheet links from the main page: this allows us connect Pi's to people in case of any issues.
|
||||
1. [Solder the GPIO header pins](solder-gpio.md)
|
||||
1. [Gadget Mode to setup a serial connection over USB](gadget.md)
|
||||
1. [Marcel's script on github to show the IP address on the OLED screen](https://github.com/mkyas/cpsy-display-ip)
|
||||
1. Install Blinka by following the guide [CircuitPython Libraries on Linux and Raspberry Pi](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi)]
|
||||
|
||||
## RU student-only guides at ROB-IOT
|
||||
- [Starting on Raspberry Pi Zero](https://reykjavik.instructure.com/courses/6589/pages/starting-on-raspberry-pi-zero-w)
|
||||
|
||||
## 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.
|
||||
- [Raspberry Pi Connect](https://connect.raspberrypi.com)
|
||||
- [Setting up Raspberry Pi Connect](https://www.raspberrypi.com/documentation/services/connect.html)
|
||||
- [Raspberry Pi Zero Headless Quick Start](https://learn.adafruit.com/raspberry-pi-zero-creation) This guide assumes you have a serial cable adapter you can plug into the RX/TX serial pins on the Pi.
|
||||
- [Pi Headless Configuration over Bluetooth](https://hacks.mozilla.org/2017/02/headless-raspberry-pi-configuration-over-bluetooth/) Guide from 2017 on how to setup a serial console over Bluetooth
|
||||
- [Turning your Raspberry Pi Zero into a USB Gadget](https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/serial-gadget) Official Adafruit guide to gadget mode to allow the USB port to be used as a serial console to connect to it. We had trouble getting it to work in 2026 due to some changes in Raspberry Pi OS.
|
||||
- [CircuitPython Libraries on Linux and Raspberry Pi](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi)
|
||||
- [Python gpiozero library](https://gpiozero.readthedocs.io/en/stable/) a simple interface for working with GPIO devices
|
||||
- [CircuitPython Libraries on Linux and Raspberry Pi](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi) This is one option for GPIO, I2C, SPI, and PWM access in python.
|
||||
- [Comparing Rasbperry Pi python interfaces](https://raspberry.tips/en/raspberrypi-tutorials/raspberry-pi-gpio-python)
|
||||
|
||||
## For the Future
|
||||
- [Setting up Zeroconf to use local names (.local) to access your Pi](https://learn.adafruit.com/bonjour-zeroconf-networking-for-windows-and-linux): this does not work on iot-research because multicast and MDNS are broken.
|
||||
- [MDNS on iot-research](mdns.md) MDNS is still an ongoing development.
|
||||
|
||||
## TODO
|
||||
- Finding the Pi using `nmap` or `arp`
|
||||
- Create a interface HAT that makes it easy to attach to a digital analyzer (v207) and an Analog Discovery
|
||||
# Some Tricks
|
||||
|
||||
Here is a page of tricks we have discovered that may involve advanced techniques.
|
||||
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
#!/bin/bash
|
||||
# Adapted from
|
||||
# "Using OTG mode on Raspberry Pi SBCs"
|
||||
# https://pip-assets.raspberrypi.com/categories/685-app-notes-guides-whitepapers/documents/RP-009276-WP/Using-OTG-mode-on-Raspberry-Pi-SBCs
|
||||
|
||||
# This script only works if you are running it as root
|
||||
if [ $(id -u) -ne 0 ]; then
|
||||
echo "Please run as root or use sudo"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Is the dwc2 overlay installed? Nothing will work if it isn't.
|
||||
if lsmod | grep -q "dwc2"; then
|
||||
systemd-cat -t gadget.sh -p info echo "DWC2 module loaded, setting up OTG gadget serial and ethernet"
|
||||
else
|
||||
systemd-cat -t gadget.sh -p warning echo "DWC2 module missing. Aborting OTG setup."
|
||||
systemctl disable serial-getty@ttyGS0.service
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sudo modprobe libcomposite
|
||||
cd /sys/kernel/config/usb_gadget
|
||||
if [ -d "MyGadget" ]; then
|
||||
systemd-cat -t gadget.sh -p warning echo "MyGadget already exists. Aborting OTG setup."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create our new gadget
|
||||
mkdir MyGadget
|
||||
cd MyGadget
|
||||
# Add some boilerplate data that the gadget needs
|
||||
echo 0x1d6b > idVendor # Linux Foundation’s USB VID. Replace with your own VID if required
|
||||
echo 0x0104 > idProduct # Multifunction Composite Gadget
|
||||
echo 0x0100 > bcdDevice # v1.0.0
|
||||
echo 0x0200 > bcdUSB # USB2
|
||||
mkdir strings/0x409 # 0x409 = English
|
||||
# Insert your own manufacturer and gadget name here
|
||||
echo "RaspberryPi" > strings/0x409/manufacturer
|
||||
echo "MyPiGadget" > strings/0x409/product
|
||||
# Make the serial number the same as the Raspberry Pi serial number; you can use whatever is required here
|
||||
SERIAL=`cat /proc/cpuinfo | awk '/Serial/ {print $3}' `
|
||||
echo $SERIAL > strings/0x409/serialnumber
|
||||
# Create a configuration area and populate
|
||||
mkdir configs/c.1
|
||||
echo 120 > configs/c.1/MaxPower
|
||||
mkdir configs/c.1/strings/0x409
|
||||
echo "Config 1" > configs/c.1/strings/0x409/configuration
|
||||
|
||||
# Create our specific gadget type
|
||||
## Mass storage device
|
||||
### Remember to create the storage block device first
|
||||
## cd /root
|
||||
### Example: Make a 256 MB file to act as "USB stick"
|
||||
## Only create it once or it will delete the previous content
|
||||
## sudo dd if=/dev/zero of=drive.bin bs=1M count=256
|
||||
### Create a VFAT file system on the backing store
|
||||
## sudo mkfs.vfat drive.bin
|
||||
##
|
||||
# mkdir functions/mass_storage.usb0
|
||||
## Set up our backing store
|
||||
# echo "/home/pi/drive.bin" > functions/mass_storage.usb0/lun.0/file
|
||||
## Link our function to our configuration
|
||||
#ln -s functions/mass_storage.0 configs/c.1/
|
||||
|
||||
## Serial (CDC ACM)
|
||||
mkdir functions/acm.usb0
|
||||
ln -s functions/acm.usb0 configs/c.1/
|
||||
|
||||
## Ethernet (RNDIS and ECM)
|
||||
## Of note, this may cause the IP to show up as 127.0.0.1
|
||||
## and wireless to suddenly fail to connect
|
||||
mkdir functions/ecm.usb0
|
||||
ln -s functions/ecm.usb0 configs/c.1/
|
||||
|
||||
## USB Device Controller update
|
||||
UDC=`ls /sys/class/udc`
|
||||
echo $UDC > UDC
|
||||
|
||||
# Enable the gettys
|
||||
systemctl enable serial-getty@ttyGS0.service
|
||||
@@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=Serial and Ethernet over OTG USB
|
||||
#After=systemd-user-sessions.service
|
||||
Before=serial-getty@ttyGS0.service
|
||||
[Service]
|
||||
ExecStart=/root/rover-pi/Scripts/gadget.sh
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,79 @@
|
||||
# Bluetooth on the Raspberry Pi Zero W (1 or 2)
|
||||
The Zero W series has Bluetooth capability because of the Wifi chip on the board.
|
||||
**Warning: This is a work in progress!!!**
|
||||
|
||||
# Reference
|
||||
- "Exploring Raspberry Pi" by Derek Molloy pg 537-544
|
||||
- [Connecting to a Headless Raspberry Pi using Bluetooth](https://medium.com/@tomw3115/connect-to-a-headless-raspberry-pi-using-bluetooth-0e61c05e1b68)
|
||||
- https://github.com/sorah/bluetooth-getty
|
||||
- [Use dbus insteadd of sdptool](https://linuxvox.com/blog/bluez-adding-services-attributes-and-profiles-without-sdptool-command/)
|
||||
|
||||
# Getting Bluetooth working
|
||||
1. Login to the pi via a USB-serial port or monitor-keyboard-mouse. Configuring bluetooth can sometimes kick you off the wifi.
|
||||
1. Tell `rfkill` to unblock bluetooth. Perhaps this is a security thing?
|
||||
```
|
||||
sudo rfkill unblock bluetooth
|
||||
```
|
||||
1. Restart the bluetooth service and check it's status
|
||||
```
|
||||
sudo systemctl restart bluetooth
|
||||
sudo systemctl status bluetooth
|
||||
```
|
||||
1. Figure out the address using `hcitool`
|
||||
```
|
||||
hcitool dev
|
||||
```
|
||||
1. If you have a laptop set to be discoverable, you can check if bluetooth is working
|
||||
```
|
||||
hcitool scan
|
||||
```
|
||||
1. You can then query that device for what services it offers
|
||||
```
|
||||
sdptool browse ADDRESS
|
||||
```
|
||||
1. Now we want to make the Pi discoverable to our phone, tablet, or laptop
|
||||
```
|
||||
sudo hciconfig hci0 piscan
|
||||
sudo hciconfig hci name RaspberryPi
|
||||
```
|
||||
1. A Serial Port Profile(SPP) is needed for our serial port
|
||||
```
|
||||
sudo sdptool add SP
|
||||
```
|
||||
1. For some reason, we have to put the bluetooth daemon in compatibility mode. (True as of 2016-2026 --foley). Find the line with `ExecStart` and put `--compat` at the end
|
||||
```
|
||||
sudo nano /lib/systemd/system/bluetooth.service
|
||||
```
|
||||
1. Test the SPP is setup
|
||||
|
||||
```
|
||||
sudo sdptool browse local
|
||||
```
|
||||
1. Time to pair it with a device
|
||||
```
|
||||
sudo bluetoothctl
|
||||
discoverable on
|
||||
agent on
|
||||
pairable on
|
||||
scan on
|
||||
```
|
||||
and once you have paired it
|
||||
```
|
||||
discoverable off
|
||||
exit
|
||||
```
|
||||
|
||||
1. If this works, you can install the `bluetooth.services` and `rfcomm.service` files to automate some of this setup.
|
||||
```
|
||||
sudo cp bluetooth.service /etc/systemd/system/bluetooth.target.wants/.
|
||||
sudo cp rfcomm.service /etc/systemd/system/.
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable rfcomm
|
||||
sudo reboot
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
# Discussion
|
||||
Apparently Bluez's `sdptool` is now depricated and they are telling people to use this new GATT via `busctl` or `dbus-send`. [linuxvox article on depricated sdptool](https://linuxvox.com/blog/bluez-adding-services-attributes-and-profiles-without-sdptool-command/)
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
# Initial connection to the Raspberry Pi
|
||||
Now that you have an image with ssh and Raspberry Pi connect on your SD, you can connect to the pi
|
||||
|
||||
|
||||
## 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,119 @@
|
||||
# Gadget Mode to setup a serial connection over USB
|
||||
Prepare Raspberry Pi OS connection over a microUSB serial cable
|
||||
|
||||
Based upon Adafruit guide: https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/serial-gadget:
|
||||
The author discovered the guide was out of date, consulted the [2025 Raspberry Pi whitepaper on OTG](https://pip-assets.raspberrypi.com/categories/685-app-notes-guides-whitepapers/documents/RP-009276-WP/Using-OTG-mode-on-Raspberry-Pi-SBCs), found additional errors, and was finally able to correct them thanks to this blog https://www.isticktoit.net/?p=1383
|
||||
|
||||
## Important :
|
||||
- **Using the Gadget Mode will make the usb port unable to connect to a mouse or keyboard!!!** You will need to disable it make them work again.
|
||||
- You will want to disable the serial console on RX/TX in `raspi-config` if you are trying to use that serial port for communicating with other devices.
|
||||
|
||||
|
||||
## Procedure
|
||||
|
||||
Make sure you have your USB cable plugged into the left port **USB** and not the right port marked **PWR**.
|
||||
1. Open a connection to the device via ssh or Raspberry Pi Connect
|
||||
1. Become root (the superuser)
|
||||
```
|
||||
sudo su
|
||||
```
|
||||
1. Enable the DWC version 2 USB peripheral device tree overlay by appending it to the end after the `[all]` category (which is at the end)
|
||||
```
|
||||
echo "dtoverlay=dwc2" >> /boot/firmware/config.txt
|
||||
```
|
||||
1. We add the required module `dwc2` for loading at startup
|
||||
```
|
||||
echo "dwc2" >> /etc/modules
|
||||
```
|
||||
1. Check that we can load the libcomposite module
|
||||
```
|
||||
modprobe libcomposite
|
||||
```
|
||||
1. Put a copy of this repository in root's home directory using git
|
||||
```
|
||||
apt install -y git
|
||||
git clone https://gitea.cs.ru.is/RU-V207/rover-pi.git
|
||||
```
|
||||
1. Go to Scripts and test if the `gadget.sh` runs without errors and hopefully a Serial port appers in Device Manager or equivalent
|
||||
```
|
||||
cd rover-pi/Scripts/
|
||||
./gadget.sh
|
||||
```
|
||||
1. Install the systemd
|
||||
```
|
||||
cp serial-ether-gadget.service /lib/systemd/system/.
|
||||
```
|
||||
1. Enable the service
|
||||
```
|
||||
systemctl enable serial-ether-gadget.service
|
||||
```
|
||||
1. Enable the getty (which connects a login terminal to the serial port)
|
||||
```
|
||||
systemctl enable serial-getty@ttyGS0.service
|
||||
```
|
||||
1. Reboot and see if the serial port appears
|
||||
|
||||
# Connecting to the serial terminal
|
||||
You will need a serial terminal program (which used to be very very common) in order to communicate over your serial port
|
||||
|
||||
## Windows
|
||||
- Putty: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
|
||||
- MobaXterm: https://mobaxterm.mobatek.net/
|
||||
|
||||
## Linux
|
||||
If using a Linux VM, you will need to pass the Pi USB connection there.
|
||||
This is similar to the procedure for accessing an Arduino.
|
||||
1. Start the Linux VM if you haven't already
|
||||
1. Menu: Devices > USB
|
||||
1. Look for "Silicon Labs CP210x USB to UART Bridge" and click on it.
|
||||
1. check if port /dev/ttyUSB0 is found. The Pi will most often be accessible over this port.
|
||||
```
|
||||
ls -l /dev/ttyU*
|
||||
```
|
||||
1. The user must be in the dialout group to access it. Use the Linux command: `uid` -to check if you are in the group. If not in the dialout group, use:
|
||||
```
|
||||
sudo usermod -a -G dialout <username>
|
||||
```
|
||||
1. You will use the GNU `screen` application in Linux to access the Pi. You can install it with:
|
||||
```
|
||||
sudo apt install screen
|
||||
```
|
||||
1. You should now gain access to the Pi with:
|
||||
```
|
||||
` sudo screen /dev/ttyUSB0 115200
|
||||
```
|
||||
1. Press enter and you will be prompted to log in to the Pi with default credentials. User: pi - PW: raspberry
|
||||
|
||||
# Disabling the OTG mode to use a keyboard and mouse again
|
||||
|
||||
**WARNING: Untested**
|
||||
1. Comment out the dwg2 line in `/boot/firmware/config.txt` using a `#` in front of the line
|
||||
```
|
||||
[all]
|
||||
#dtoverlay=dwg2
|
||||
```
|
||||
1. Comment out the dwg2 line in `/etc/modules` using a `#` in front of the line
|
||||
```
|
||||
#dwg2
|
||||
```
|
||||
1. Disable the gadget service
|
||||
```
|
||||
systemctl disable serial-ether-gadget.service
|
||||
```
|
||||
1. Disable the getty
|
||||
```
|
||||
systemctl disable serial-getty@ttyGS0.service
|
||||
```
|
||||
|
||||
# Connecting over the USB ethernet to ssh into your Pi
|
||||
|
||||
I have not tested this procedure because the serial console and normal network connection is sufficient for me --foley
|
||||
|
||||
https://www.raspberrypi.com/news/usb-gadget-mode-in-raspberry-pi-os-ssh-over-usb/
|
||||
|
||||
|
||||
# Untested
|
||||
Here are items that bear investigating but haven't been tested yet
|
||||
|
||||
- [Modify Imager manifest to install otg](https://github.com/raspberrypi/rpi-imager/tree/main/doc/local_json)
|
||||
|
||||
@@ -23,7 +23,7 @@ We don't have many monitors and keyboards in V207 for students to use, so we wil
|
||||

|
||||
1. Once you have uploaded your `id_edcsa.pub` file it should look like this.
|
||||

|
||||
1. Since we don't have enough monitors, we will need another way to setup the initial connection. The officially supported option is Raspberry Pi Connect. You will need to:
|
||||
1. Since we don't have a monitor, keyboard, and mouse available, we will need another way to setup the initial connection. The officially supported option is Raspberry Pi Connect. You will need to enable it then:
|
||||
1. Register for an account first at https://connect.raspberrypi.com
|
||||
2. Confirm your account with email
|
||||
2. Login with that account
|
||||
@@ -42,8 +42,10 @@ We don't have many monitors and keyboards in V207 for students to use, so we wil
|
||||
1. Now you get to watch the writing then verifying.
|
||||

|
||||

|
||||
1. The process is complete!
|
||||
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
|
||||
|
||||
@@ -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,9 @@
|
||||
# Multicast DNS
|
||||
|
||||
# Setting it up on your pi (or other linux system)
|
||||
|
||||
Setup Multicast DNS discovery of ssh in a Terminal with the [Avahi](https://wiki.debian.org/Avahi) package (usually preinstalled)
|
||||
|
||||
We tell the avahi daemon to publish ssh `sudo cp /usr/share/doc/avahi-daemon/examples/ssh.service /etc/avahi/services/`
|
||||
We restart the daemon to see the file: `sudo systemctl restart avahi-daemon`
|
||||
See if you can find your IP and MAC address with `avahi-browse -a`. You may have to install the program first with `sudo apt install avahi-utils`. If the browser doesn't show other devices, multicast is probably broken.
|
||||
@@ -0,0 +1,61 @@
|
||||
# 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
|
||||
- [CircuitPython Libraries on Linux and Raspberry Pi](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi)
|
||||
- [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)
|
||||
- [CircuitPython pwmio documentation](https://docs.circuitpython.org/en/latest/shared-bindings/pwmio/index.html)
|
||||
|
||||
|
||||
# Important Points
|
||||
1. The `gpio` program is no longer available. It has been replaced with `pinctrl` which works a little differently.
|
||||
1. The Blinka/CircuitPython interface uses `lgpio` to do hardware PWM on the pins. This requires the `pwm-2chan` overlay to be setup correctly, which it's documented procedure does. Details on relevant pins on line 4267 of the [overleays README](https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README)
|
||||
|
||||
# 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.
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# raspi-config options to check
|
||||
|
||||
```
|
||||
sudo raspi-config
|
||||
3 - Interface options
|
||||
P2 enable SSH
|
||||
P4 enable SPI
|
||||
P5 enable I2C
|
||||
P6 enable serial (You may have to update this later and turn it off for certain UART features to work)
|
||||
```
|
||||
@@ -0,0 +1,14 @@
|
||||
# Solder the Header pins on the Pi Zero W
|
||||
|
||||
You will need header pins to access the GPIO on the Pi. GPIO is needed in order to connect to the Pi via the MicroUSB cable. [Details on what the GPIO pins do](https://www.raspberrypi.org/documentation/usage/gpio/)
|
||||
|
||||
|
||||
1. Read the helpful guide on soldering: [Soldering is Easy Guide](https://mightyohm.com/files/soldercomic/FullSolderComic_EN.pdf)
|
||||
1. No really, read the comic [Soldering is Easy Guide](https://mightyohm.com/files/soldercomic/FullSolderComic_EN.pdf). The teaching staff will make fun of you if you don't read it before you try doing it for real.
|
||||
1. Apparently reading is hard because some people still haven't looked at the comic. Go to [Adafruit's guide on soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) which includes videos.
|
||||
1. Mount the raspberry Pi zero into a Panavise or other mechanism to hold it steady. If none of those are available, you can use tape to stick it to a piece of cardboard, then stick that to the table. Be aware the tape will melt or burn if it comes into contact with the soldering iron.
|
||||
1. Get the dual row pins: 2x20. The pins are available in the stock room of V207 if they weren't included in your kit.
|
||||
1. Drop them in from the top of the PCB and hold them in place. The short ends go into the PCB. Wrap a piece of electrical tape from one edge of the PCB across the center of the tall pins, to the other edge. This should temporarily secure them to the PCB. Flip the board over. The pins should just be sticking a little bit out the bottom of the board.
|
||||
1. Heat and apply solder to the pins on the end (away from the tape). Check that the solder joints are cool and strong, then remove the tape. Finish the rest of the soldering.
|
||||
1. Inspect the soldering joints under the microscope to make sure that there are not holes or anything else that might result in a flaky connection. If you see "spiky things" sticking out, that means you didn't heat the pin and solder enough.
|
||||
1. If any of the connections look questionable, remove the solder on that joint and do it again. **Unreliable solder joints will cause your system to be flaky which will drive you crazy later in the semester!**
|
||||
Reference in New Issue
Block a user