Compare commits

..

9 Commits

Author SHA1 Message Date
foley 39c0f158fe switch to logger (more POSIX) 2026-07-02 11:04:19 +00:00
foley 9f51718235 test if running as root 2026-07-02 10:39:13 +00:00
foley 01b3a189ed enable/disable gettys as needed 2026-07-02 10:34:26 +00:00
foley 3ef2ca02a6 test if MyGadget already exists 2026-07-02 10:29:54 +00:00
foley cc0b37af8b Merge branch 'master' of https://gitea.cs.ru.is/RU-V207/rover-pi 2026-07-02 10:08:56 +00:00
foley 17c0ffab67 ECM was not breaking network 2026-07-02 10:08:47 +00:00
foley 29fb570ae5 Adding module detect functionality 2026-07-02 10:05:09 +00:00
foley b667926315 API link 2026-07-02 09:49:02 +00:00
foley 39aeb47d0e disabling ethernet 2026-06-29 00:35:34 +00:00
2 changed files with 34 additions and 3 deletions
+1
View File
@@ -21,6 +21,7 @@ Scripts and documentation for setting up a Raspberry Pi (Zero W 1 or 2) for use
- [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. - [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.
- [Python gpiozero library](https://gpiozero.readthedocs.io/en/stable/) a simple interface for working with GPIO devices - [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. - [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 ## 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. - [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.
+33 -3
View File
@@ -2,10 +2,34 @@
# Adapted from # Adapted from
# "Using OTG mode on Raspberry Pi SBCs" # "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 # https://pip-assets.raspberrypi.com/categories/685-app-notes-guides-whitepapers/documents/RP-009276-WP/Using-OTG-mode-on-Raspberry-Pi-SBCs
sudo modprobe libcomposite
# 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
echo "DWC2 module loaded, setting up OTG gadget serial and ethernet" | logger -t $0 -p info
echo "DWC2 module loaded"
else
echo "DWC2 module missing. Aborting OTG setup." | logger -t $0 -p info
echo "DWC2 module missing"
systemctl disable serial-getty@ttyGS0.service
exit 1
fi
modprobe libcomposite
cd /sys/kernel/config/usb_gadget cd /sys/kernel/config/usb_gadget
if [ -d "MyGadget" ]; then
echo "MyGadget already exists. Aborting OTG setup." | logger -t $0 -p info
exit 1
fi
# Create our new gadget # Create our new gadget
sudo mkdir MyGadget mkdir MyGadget
cd MyGadget cd MyGadget
# Add some boilerplate data that the gadget needs # Add some boilerplate data that the gadget needs
echo 0x1d6b > idVendor # Linux Foundations USB VID. Replace with your own VID if required echo 0x1d6b > idVendor # Linux Foundations USB VID. Replace with your own VID if required
@@ -30,6 +54,7 @@ echo "Config 1" > configs/c.1/strings/0x409/configuration
### Remember to create the storage block device first ### Remember to create the storage block device first
## cd /root ## cd /root
### Example: Make a 256 MB file to act as "USB stick" ### 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 ## sudo dd if=/dev/zero of=drive.bin bs=1M count=256
### Create a VFAT file system on the backing store ### Create a VFAT file system on the backing store
## sudo mkfs.vfat drive.bin ## sudo mkfs.vfat drive.bin
@@ -45,9 +70,14 @@ mkdir functions/acm.usb0
ln -s functions/acm.usb0 configs/c.1/ ln -s functions/acm.usb0 configs/c.1/
## Ethernet (RNDIS and ECM) ## 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 mkdir functions/ecm.usb0
ln -s functions/ecm.usb0 configs/c.1/ ln -s functions/ecm.usb0 configs/c.1/
## USB Device Controller update ## USB Device Controller update
UDC=`ls /sys/class/udc` UDC=`ls /sys/class/udc`
echo $UDC > UDC echo $UDC > UDC
# Enable the gettys
systemctl enable serial-getty@ttyGS0.service