Compare commits
23
Commits
075fd124cd
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c96d0bb829 | ||
|
|
58206eb384 | ||
|
|
7cc99fb75e | ||
|
|
b292dbd6e9 | ||
|
|
7fa93735bd | ||
|
|
a4d28d02f7 | ||
|
|
b0d632f0c5 | ||
|
|
040a6ca33f | ||
|
|
e74eff43a2 | ||
|
|
73b4e98a36 | ||
|
|
9ba6b30e1f | ||
|
|
a73e40b960 | ||
|
|
e6a0556147 | ||
|
|
9c49411159 | ||
|
|
eb5a4cb3d9 | ||
|
|
dd7821834a | ||
|
|
c72108a0aa | ||
|
|
2ca5bc2dd2 | ||
|
|
104aaabde4 | ||
|
|
447a0fcca3 | ||
|
|
ba377393a5 | ||
|
|
f4283353a2 | ||
|
|
39c0f158fe |
@@ -6,8 +6,16 @@ Scripts and documentation for setting up a Raspberry Pi (Zero W 1 or 2) for use
|
|||||||
1. [Raspberry Pi Imager procedure to setup ssh and Raspberry Pi Connect](imager.md)
|
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. 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. [Solder the GPIO header pins](solder-gpio.md)
|
||||||
1. [Gadget Mode to setup a serial connection over USB](gadget.md)
|
1. Login to the pi using ssh or serial. (Pi Connect breaks wihle upgrading the Pi Connect program). Now update the packages on your pi:
|
||||||
1. [Marcel's script on github to show the IP address on the OLED screen](https://github.com/mkyas/cpsy-display-ip)
|
```
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get -y upgrade
|
||||||
|
```
|
||||||
|
|
||||||
|
1. [Gadget Mode to setup a network connection over USB](https://github.com/raspberrypi/rpi-usb-gadget). A more explanatory version in the [Raspberry Pi Newsletter](https://www.raspberrypi.com/news/usb-gadget-mode-in-raspberry-pi-os-ssh-over-usb/)
|
||||||
|
* If you don't have Internet Connection Sharing, th pi will show up as 10.12.194.1
|
||||||
|
1. [Setup the OLED screen to print the IP](oled-display/README.md)
|
||||||
|
Based upon [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)]
|
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
|
## RU student-only guides at ROB-IOT
|
||||||
@@ -41,3 +49,32 @@ Credit: Daníel Bjartur Guðmundsson, transcribed by Joseph T. Foley
|
|||||||
1. Show details of "preconfigured" network: nmcli connection show preconfigured
|
1. Show details of "preconfigured" network: nmcli connection show preconfigured
|
||||||
1. Change the SSID (which wireless network you will connect to) in the "New_SSID": nmcli connection modify preconfigured wifi.ssid "New_SSID"
|
1. Change the SSID (which wireless network you will connect to) in the "New_SSID": nmcli connection modify preconfigured wifi.ssid "New_SSID"
|
||||||
1. Change the wireless access password in the "New_Password": nmcli connection modify preconfigured wifi-sec.psk "New_Password"
|
1. Change the wireless access password in the "New_Password": nmcli connection modify preconfigured wifi-sec.psk "New_Password"
|
||||||
|
|
||||||
|
## Wifi keeps dropping out. What do I do?
|
||||||
|
1. `sudo raspi-config`
|
||||||
|
1. Advanced Options > A12 WLAN Power Save
|
||||||
|
1. Yes to disabling
|
||||||
|
|
||||||
|
## I'd like to stop typing my password all the time
|
||||||
|
1. Copy your private key to your pi from `~/.ssh/id_*` to the Pi
|
||||||
|
1. On the Pi, start ssh-agent with
|
||||||
|
```eval $(ssh-agent)```
|
||||||
|
1. Now add your key
|
||||||
|
```ssh-add```
|
||||||
|
|
||||||
|
## I'd like to access my pi's files directly on my computer.
|
||||||
|
In linux, you can use sshfs: https://github.com/libfuse/sshfs
|
||||||
|
1. Install sshfs
|
||||||
|
```sudo apt install sshfs```
|
||||||
|
1. Make a place to mount the files on the pi
|
||||||
|
```mkdir username-rover```
|
||||||
|
1. Now we mount the pi's filesystem using sshfs
|
||||||
|
```sshfs username@host-or-ip /home/username ~/username-rover```
|
||||||
|
|
||||||
|
## How do I get the python virtual environment to start each time
|
||||||
|
1. Edit your `.bashrc` to have this at the end:
|
||||||
|
```
|
||||||
|
if [ -f ~/env/bin/activate ]; then
|
||||||
|
source ~/env/bin/activate
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|||||||
+23
-7
@@ -9,20 +9,36 @@ if [ $(id -u) -ne 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -f /boot/firmware/GADGET_MODE ]; then
|
||||||
# Is the dwc2 overlay installed? Nothing will work if it isn't.
|
systemd-cat -t gadget.sh -p info echo "/boot/firmware/GADGET_MODE exists: GADGET mode enabled"
|
||||||
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
|
else
|
||||||
systemd-cat -t gadget.sh -p warning echo "DWC2 module missing. Aborting OTG setup."
|
systemd-cat -t gadget.sh -p warning echo "/boot/firmware/GADGET_MODE missing: GADGET mode disabled"
|
||||||
systemctl disable serial-getty@ttyGS0.service
|
systemctl disable serial-getty@ttyGS0.service
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo modprobe libcomposite
|
# Is the dwc2 overlay installed? Nothing will work if it isn't.
|
||||||
|
<<<<<<< HEAD
|
||||||
|
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"
|
||||||
|
=======
|
||||||
|
if [ -d /sys/class/udc ] && [ -n "$(ls -A /sys/class/udc)" ]; then
|
||||||
|
systemd-cat -t gadget.sh -p info echo "DWC2 precompiled, setting up OTG gadget serial and ethernet"
|
||||||
|
elif lsmod | grep -q "dwc2"; then
|
||||||
|
systemd-cat -t gadget.sh -p info echo "Pre 6.18.39 kernel. DWC2 module loaded, setting up OTG gadget serial and ethernet"
|
||||||
|
>>>>>>> master
|
||||||
|
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
|
if [ -d "MyGadget" ]; then
|
||||||
systemd-cat -t gadget.sh -p warning echo "MyGadget already exists. Aborting OTG setup."
|
echo "MyGadget already exists. Aborting OTG setup." | logger -t $0 -p info
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ Based upon Adafruit guide: https://learn.adafruit.com/turning-your-raspberry-pi-
|
|||||||
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
|
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 :
|
## Important :
|
||||||
|
- **We are still working out the kinks with the gadget mode switching on the Pi Zero W 2**
|
||||||
- **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.
|
- **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.
|
||||||
|
- The blue USB cables included in the kit in 2026 are flakey. We recommend replacing them ASAP.
|
||||||
- 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.
|
- 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.
|
||||||
|
|
||||||
|
|
||||||
@@ -17,18 +19,18 @@ Make sure you have your USB cable plugged into the left port **USB** and not the
|
|||||||
```
|
```
|
||||||
sudo su
|
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
|
1. Check that we can load the libcomposite module
|
||||||
```
|
```
|
||||||
modprobe libcomposite
|
modprobe libcomposite
|
||||||
```
|
```
|
||||||
|
1. Reboot
|
||||||
|
```
|
||||||
|
restart now
|
||||||
|
```
|
||||||
|
1. Become root again
|
||||||
|
```
|
||||||
|
sudo su
|
||||||
|
```
|
||||||
1. Put a copy of this repository in root's home directory using git
|
1. Put a copy of this repository in root's home directory using git
|
||||||
```
|
```
|
||||||
cd /root
|
cd /root
|
||||||
@@ -85,7 +87,44 @@ This is similar to the procedure for accessing an Arduino.
|
|||||||
```
|
```
|
||||||
1. Press enter and you will be prompted to log in to the Pi with default credentials. User: pi - PW: raspberry
|
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
|
# Enabling/Disabling the OTG mode to use a keyboard and mouse again
|
||||||
|
|
||||||
|
## Disable
|
||||||
|
1. Remove the SD card and access it on your computer
|
||||||
|
1. Delete the file called `GADGET_MODE` in the boot partition/drive usually called `bootfs`.
|
||||||
|
1. If the Pi is booted, you can `sudo rm /boot/firmware/GADGET_MODE` and reboot.
|
||||||
|
|
||||||
|
## Enable
|
||||||
|
1. Remove the SD card and access it on your computer
|
||||||
|
1. Create a file called `GADGET_MODE` in the boot partition/drive called `bootfs`.
|
||||||
|
2. If the Pi is booted, you can `sudo touch /boot/firmware/GADGET_MODE` and reboot
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
# Old DWC Instructions (for older versions)
|
||||||
|
|
||||||
|
## Setting up
|
||||||
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Disabling the OTG mode to use a keyboard and mouse again
|
||||||
|
|
||||||
**WARNING: Untested**
|
**WARNING: Untested**
|
||||||
1. Comment out the dwg2 line in `/boot/firmware/config.txt` using a `#` in front of the line
|
1. Comment out the dwg2 line in `/boot/firmware/config.txt` using a `#` in front of the line
|
||||||
@@ -105,16 +144,3 @@ This is similar to the procedure for accessing an Arduino.
|
|||||||
```
|
```
|
||||||
systemctl disable serial-getty@ttyGS0.service
|
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)
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
#!/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!
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
#!/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!
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#!/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,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 Marcel
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# cpsy-display-ip
|
||||||
|
Demonstrates the SSD1306 OLED by showing the IP address on the system boot.
|
||||||
|
Originally at https://github.com/mkyas/cpsy-display-ip and customized for Mechatronics 1 students.
|
||||||
|
|
||||||
|
This project contains the file `display-ip.py` that displays an IP
|
||||||
|
address on the SSD1306 OLED screen and the file `display-ip.service`
|
||||||
|
that executes the script on boot after the Raspberry Pi is connected
|
||||||
|
to a network.
|
||||||
|
|
||||||
|
To use the script, you first must connect the screen to the Pi's
|
||||||
|
I2C bus.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
Do the following steps on your Raspberry Pi.
|
||||||
|
|
||||||
|
1. Enable I2C in `raspi-config`
|
||||||
|
1. Go to your home directory: `cd ~`
|
||||||
|
1. Clone this repository to your raspberry pi `git clone https://gitea.cs.ru.is/RU-V207/rover-pi`
|
||||||
|
1. Install [pillow](https://python-pillow.org/), numpy, and venv:
|
||||||
|
> sudo apt install python3-venv python3-pil python3-numpy
|
||||||
|
1. Create a virtual environment, here called cpsy:
|
||||||
|
> python3 -m venv cpsy
|
||||||
|
1. Edit the generated `pyvenv.cfg` to set `include-system-site-packages = true`
|
||||||
|
1. Activate the environment `source cpsy/bin/activate`
|
||||||
|
1. Install the display driver: `pip install adafruit-circuitpython-ssd1306`
|
||||||
|
1. Edit `display-ip.service`:
|
||||||
|
- Replace `foley` with your user name on the Pi.
|
||||||
|
- the `WorkingDirectory` points to the directory containing `display-ip.py`
|
||||||
|
- the path to python points to your virtual environment
|
||||||
|
1. Copy the edited `display-ip.service` to `/etc/systemd/system`
|
||||||
|
```sudo cp display-ip.service /etc/systemd/system/.```
|
||||||
|
1. Enable the service `sudo systemctl enable display-ip.service`
|
||||||
|
1. Test by starting the service `sudo systemctl start display-ip.service` which should turn on the screen.
|
||||||
|
1. If nothing happens, check on the status with `sudo systemctl status display-ip` and look for error messages.
|
||||||
|
1. If you make additional changes to the service file, you may have to reload the `systemd`:
|
||||||
|
```sudo systemctl daemon-reload ```
|
||||||
|
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
"""
|
||||||
|
This demo will fill the screen with white, draw a black box on top
|
||||||
|
and then print the device's hostname and IP address in the center of the display
|
||||||
|
|
||||||
|
This example is for use on (Linux) computers that are using CPython with
|
||||||
|
Adafruit Blinka to support CircuitPython libraries. CircuitPython does
|
||||||
|
not support PIL/pillow (python imaging library)!
|
||||||
|
"""
|
||||||
|
|
||||||
|
import board
|
||||||
|
import digitalio
|
||||||
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
import adafruit_ssd1306
|
||||||
|
import socket
|
||||||
|
import platform
|
||||||
|
|
||||||
|
# Define the Reset Pin
|
||||||
|
oled_reset = None
|
||||||
|
try:
|
||||||
|
oled_reset = digitalio.DigitalInOut(board.D4)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
# No reset pin
|
||||||
|
|
||||||
|
# Change these
|
||||||
|
# to the right size for your display!
|
||||||
|
WIDTH = 128
|
||||||
|
HEIGHT = 64
|
||||||
|
BORDER = 5
|
||||||
|
|
||||||
|
# Use for I2C.
|
||||||
|
i2c = board.I2C() # uses board.SCL and board.SDA
|
||||||
|
oled = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3C, reset=oled_reset)
|
||||||
|
|
||||||
|
# Clear display.
|
||||||
|
oled.fill(0)
|
||||||
|
oled.show()
|
||||||
|
|
||||||
|
# Create blank image for drawing.
|
||||||
|
# Make sure to create image with mode '1' for 1-bit color.
|
||||||
|
image = Image.new("1", (oled.width, oled.height))
|
||||||
|
|
||||||
|
# Get drawing object to draw on image.
|
||||||
|
draw = ImageDraw.Draw(image)
|
||||||
|
|
||||||
|
# Draw a white background
|
||||||
|
draw.rectangle((0, 0, oled.width, oled.height), outline=255, fill=255)
|
||||||
|
|
||||||
|
# Draw a smaller inner rectangle
|
||||||
|
draw.rectangle(
|
||||||
|
(BORDER, BORDER, oled.width - BORDER - 1, oled.height - BORDER - 1),
|
||||||
|
outline=0,
|
||||||
|
fill=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Load default font.
|
||||||
|
font = ImageFont.load_default()
|
||||||
|
|
||||||
|
# Get the local IP address as a string.
|
||||||
|
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
||||||
|
s.connect(("8.8.8.8", 80))
|
||||||
|
ipaddr = s.getsockname()[0]
|
||||||
|
|
||||||
|
hostname = platform.node()
|
||||||
|
text = hostname + "\n" + ipaddr
|
||||||
|
|
||||||
|
bbox = font.getbbox(ipaddr)
|
||||||
|
(font_width, font_height) = bbox[2] - bbox[0], bbox[3] - bbox[1]
|
||||||
|
|
||||||
|
draw.multiline_text(
|
||||||
|
xy=(10,10),
|
||||||
|
text=text,
|
||||||
|
fill=255,
|
||||||
|
font=font,
|
||||||
|
spacing=2, #pixel gap between lines,
|
||||||
|
align="left",
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
# Display image
|
||||||
|
oled.image(image)
|
||||||
|
oled.show()
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
"""
|
||||||
|
This demo will fill the screen with white, draw a black box on top
|
||||||
|
and then print the device's IP address in the center of the display
|
||||||
|
|
||||||
|
This example is for use on (Linux) computers that are using CPython with
|
||||||
|
Adafruit Blinka to support CircuitPython libraries. CircuitPython does
|
||||||
|
not support PIL/pillow (python imaging library)!
|
||||||
|
"""
|
||||||
|
|
||||||
|
import board
|
||||||
|
import digitalio
|
||||||
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
import adafruit_ssd1306
|
||||||
|
import socket
|
||||||
|
|
||||||
|
# Define the Reset Pin
|
||||||
|
oled_reset = None
|
||||||
|
try:
|
||||||
|
oled_reset = digitalio.DigitalInOut(board.D4)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
# No reset pin
|
||||||
|
|
||||||
|
# Change these
|
||||||
|
# to the right size for your display!
|
||||||
|
WIDTH = 128
|
||||||
|
HEIGHT = 64
|
||||||
|
BORDER = 5
|
||||||
|
|
||||||
|
# Use for I2C.
|
||||||
|
i2c = board.I2C() # uses board.SCL and board.SDA
|
||||||
|
oled = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3C, reset=oled_reset)
|
||||||
|
|
||||||
|
# Clear display.
|
||||||
|
oled.fill(0)
|
||||||
|
oled.show()
|
||||||
|
|
||||||
|
# Create blank image for drawing.
|
||||||
|
# Make sure to create image with mode '1' for 1-bit color.
|
||||||
|
image = Image.new("1", (oled.width, oled.height))
|
||||||
|
|
||||||
|
# Get drawing object to draw on image.
|
||||||
|
draw = ImageDraw.Draw(image)
|
||||||
|
|
||||||
|
# Draw a white background
|
||||||
|
draw.rectangle((0, 0, oled.width, oled.height), outline=255, fill=255)
|
||||||
|
|
||||||
|
# Draw a smaller inner rectangle
|
||||||
|
draw.rectangle(
|
||||||
|
(BORDER, BORDER, oled.width - BORDER - 1, oled.height - BORDER - 1),
|
||||||
|
outline=0,
|
||||||
|
fill=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Load default font.
|
||||||
|
font = ImageFont.load_default()
|
||||||
|
|
||||||
|
# Get the local IP address as a string.
|
||||||
|
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
||||||
|
s.connect(("8.8.8.8", 80))
|
||||||
|
text = s.getsockname()[0]
|
||||||
|
|
||||||
|
# Draw it into a box.
|
||||||
|
bbox = font.getbbox(text)
|
||||||
|
(font_width, font_height) = bbox[2] - bbox[0], bbox[3] - bbox[1]
|
||||||
|
draw.text(
|
||||||
|
(oled.width // 2 - font_width // 2, oled.height // 2 - font_height // 2),
|
||||||
|
text,
|
||||||
|
font=font,
|
||||||
|
fill=255,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Display image
|
||||||
|
oled.image(image)
|
||||||
|
oled.show()
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=display-ip
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=foley
|
||||||
|
WorkingDirectory=/home/foley/rover-pi/oled-display
|
||||||
|
ExecStart=/home/foley/cpsy/bin/python3 display-ip.py
|
||||||
|
Restart=never
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
Reference in New Issue
Block a user