Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Nuttall bennuttall

View GitHub Profile
View btn.py
from gpiozero import Button
from gpiozero.tools import all_values, any_values
class MyButton(Button):
def __and__(self, other):
return all_values(self, other)
def __or__(self, other):
return any_values(self, other)
View languages.py
from github import Github
from time import sleep
token = '' # enter your github access token
def is_language(path):
# a function to determine whether or not a path from a git tree is a language folder
# must be a "tree" (a folder) rather than a file
# must be 5 characters long with a hyphen in the middle e.g. "fr-CA"
return item.type == 'tree' and len(path) == 5 and path[2] == '-'
View tensorflow-old.sh
# this is the old version, only use if you have issues with the short version
mkdir wheels
cd wheels
wget https://bennuttall.com/files/37wheels/Keras_Applications-1.0.8-py3-none-any.whl
wget https://bennuttall.com/files/37wheels/Keras_Preprocessing-1.1.0-py2.py3-none-any.whl
wget https://bennuttall.com/files/37wheels/Markdown-3.1.1-py2.py3-none-any.whl
wget https://bennuttall.com/files/37wheels/Werkzeug-0.15.4-py2.py3-none-any.whl
wget https://bennuttall.com/files/37wheels/absl_py-0.7.1-cp37-none-any.whl
wget https://bennuttall.com/files/37wheels/astor-0.8.0-py2.py3-none-any.whl
View doorbell.py
from gpiozero import TonalBuzzer, Button
from picamera import PiCamera
from datetime import datetime
from time import sleep
buzzer = TonalBuzzer(20)
doorbell = Button(21)
camera = PiCamera()
def play(tune):
View wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB
network={
ssid="SSID"
psk="PASSWORD"
}
View manual_lightsensor.py
from gpiozero import InputDevice, OutputDevice
from time import time, sleep
def read_light_sensor(pin):
with OutputDevice(pin) as cap:
cap.value = 0
sleep(0.1)
# Time the charging of the capacitor
start = time()
with InputDevice(pin) as ldr:
View sensehat_scroll.md

Sense HAT scroll message

What's needed

  • Raspberry Pi with Sense HAT

The activity

The participant starts by running a pre-written script which scrolls the message "Hello world". They then change the message to one of their own, and run again. They can then change the colour. Finally they are given code with a loop showing the Raspberry Pi logo followed by the scrolling message at a different speed and in different colours, which they can play with.

View noisylightsensor.py
from gpiozero import LightSensor
from time import time, sleep
class NoisyLightSensor(LightSensor):
def _read(self):
# Drain charge from the capacitor
self.pin.function = 'output'
self.pin.state = False
sleep(0.1)
# Time the charging of the capacitor
View piwheels.sh
package=$1
mapfile -t versions < versions.txt
for v in "${versions[@]}"
do
echo $v
date
/usr/bin/time -f "piw-import $package-$v-*.whl -y --duration 00:%E" -ao imports.sh pip3 wheel $package==$v -q --no-deps --no-binary :all:
done