Skip to content

Instantly share code, notes, and snippets.

@topshed
topshed / snippet.md
Last active August 21, 2018 13:37
Raspbian bash script for wifi network switching if Internet drops
#!/bin/bash
# Checks for Internet connectivity and changes to an alternative wifi network if
# it detects a problem.
# Needs to have a wpa_supplicant file for each network:
#  wpa_supplicant_1 for SSID! and wpa_supplicant_2 for SSID2
# Can easily be extended to more than 2 possible networks

# function to bring down wireless interface, stop wpa_supplicant service and
# then bring up wlan0 again
@topshed
topshed / Solar Power Pi - Arduino method.md
Last active September 25, 2018 17:00
Solar Power Pi - Arduino method.md

Equipment

  • RTC
  • Powerbosst 500
  • Pimoroni LipoShim
  • Arduino Trinket

Imgur

Process

@topshed
topshed / Solar Power Pi - TPL5110 method.md
Last active July 25, 2022 18:30
Solar Power Pi - TPL5110

Equipment

  • Powerbosst 500
  • Pimoroni LipoShim
  • Adafruit TPL5110

Imgur

Process

  • Resistor on TPL5110 DELAY pin sets period (120K = 1 hour)
@topshed
topshed / environsensehat_readme.md
Last active November 1, 2018 14:18
Environmental sensing with SenseHAT

Environmental sensing with SenseHAT

What's needed?

A Pi and SenseHAT

Two options. Both really rely on the SenseHAT being somewhat accessible so that participants can actually change the environment. Ideally the PI and SenseHAT would be on the table (perhaps in a 3d printed flight case with with cables glued in to secure it?). Alternatively, there could be a hole cut in perspex screen so that participants can blow on the SenseHAT (to change humidity and temperature).

Option 1: simple bar graph displayed on SenseHAT LED matrix.

Note that I spoke to the creator of this project who said that they were a few bugs in the original code as published. This gist uses the updated, fixed code.

What's needed

A Pi with Minecraft installed

How would the participants interact?

There should be a Minecraft window open and an editor with the almost-complete code alongside. There should be two tabs open in the editor.

@topshed
topshed / usb.md
Last active January 2, 2019 16:56
Creating USB resources drive
  1. Get a usb drive. At least 8GB
  2. Format the drive as a FAT32 single partition with a MBR

Imgur

  1. Insert USB drive into Desktop Raspbian laptop. Copy the iso for Desktop Raspbian onto this machine.

  2. Install gparted onto the laptop:

sudo apt install gparted
@topshed
topshed / distancesensorpizero.md
Last active January 24, 2019 15:01
Using gpiozero distance sensor on Pi Zero
from gpiozero.pins.pigpio import PiGPIOFactory
from gpiozero import DistanceSensor
pigpio = PiGPIOFactory()
ds = DistanceSensor(14,15, max_distance=200, pin_factory=pigpio)

or

Build a rain alarm

The rain sensor detects water that falls on the metal circuit strips on its sensor boards. The sensor board acts as a variable resistor that will change from 100k ohms when wet to 2M ohms when dry. This change in resistence will cause a change in the outout voltage, which we can read using an anlog pin on the Arduino. There is also a digital pin which is pulled HIGH when the resistence falls below a threshold value set by the sensitivity dial (which is another variable resistor)

Imgur

int RainPin = 0;
int RainDigitalPin = 2;
@topshed
topshed / Tonal Buzzer.md
Last active March 8, 2023 15:17
Old macDonald using Tonal Buzzer in gpio zero
from gpiozero import TonalBuzzer
from gpiozero.tones import Tone
from time import sleep
t = TonalBuzzer(21) # change to whatever pin the buzzer is connected

v1 = ["G4", "G4", "G4", "D4", "E4", "E4", "D4"]
v2 = ["B4", "B4", "A4", "A4", "G4"]
v3 = ["D4", "G4", "G4", "G4", "D4", "E4", "E4", "D4"]

Arduino Light Meter

You can use another analog device - a Light Dependent Resisitor (LDR) - to meausure how bright it is (light intensity). As you can probably guess from its name. the resistance of an LDR changes depending on how much light falls on it. By making a voltage divider with another resistor, you can measure a voltage that will change depending on how bright it is.

You can then use an array of LEDs to create a visual indicator of light intensity. As the light level increases, the number of LEDs that are on will also increase. Don't foget every LED needs a current-limiting resistor. To make building the circuit easier you can use a resistor array that has a number of resistors linked togther with a common pin.

Imgur

const int analogPin = A0;   // the pin that the LDR is attached to