Compare commits
8 Commits
8963441a4f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 464ed79f95 | |||
| d86c7a224d | |||
| 582e2d4a16 | |||
| 33914344ff | |||
| a743e06b9b | |||
| e5b8899488 | |||
| f79b9985db | |||
| 8dac7f3656 |
@@ -8,6 +8,7 @@ Scripts and documentation for setting up a Raspberry Pi (Zero W 1 or 2) for use
|
||||
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)
|
||||
@@ -30,6 +31,7 @@ Scripts and documentation for setting up a Raspberry Pi (Zero W 1 or 2) for use
|
||||
|
||||
## 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.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
[Unit]
|
||||
Description=Serial and Ethernet over OTG USB
|
||||
After=systemd-user-sessions.service
|
||||
#After=systemd-user-sessions.service
|
||||
Before=serial-getty@ttyGS0.service
|
||||
[Service]
|
||||
ExecStart=/root/rover-pi/Scripts/gadget.sh
|
||||
[Install]
|
||||
|
||||
@@ -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/)
|
||||
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!
|
||||
+13
-13
@@ -5,21 +5,21 @@ 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:
|
||||
lgpio.gpio_claim_output(h, 16) # GPIO16 as output (MOTA2)
|
||||
lgpio.gpio_write(h, 16, 0) # LOW
|
||||
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)
|
||||
|
||||
# Hardware PWM on GPIO18 (pin 12) must be PWM-capable
|
||||
# Frequency: 1000 Hz, duty cycle: 50%
|
||||
lgpio.tx_pwm(h, 18, 1000, 50)
|
||||
time.sleep(2)
|
||||
|
||||
# Reduce duty cycle to 20%
|
||||
lgpio.tx_pwm(h, 18, 1000, 20)
|
||||
time.sleep(2)
|
||||
|
||||
lgpio.tx_pwm(h, 18, 0, 0) # Stop PWM
|
||||
|
||||
finally:
|
||||
lgpio.tx_pwm(h, pwm_pin, 0, 0) # Stop PWM
|
||||
lgpio.gpiochip_close(h) # Always close!
|
||||
|
||||
@@ -4,15 +4,20 @@ The Raspberry Pi zero (1 and 2) have 2 PWM peripherals, allowing you to pulse pi
|
||||
|
||||
|
||||
# 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.
|
||||
|
||||
Reference in New Issue
Block a user