Skip to content

Instantly share code, notes, and snippets.

@topshed
topshed / pir_example.md
Last active January 11, 2022 08:49
PIR example

Reading the value attribute from a gpiozero MotionSensor

This example shows how to use the .value attribute. Note that it is not a function and so does not use paranethseses. Here pir.value is treated in the same way as you would a variable.

from gpiozero import MotionSensor
from time import sleep

pir = MotionSensor(12)

Find folders without main.py files

 find Izzy -mindepth 1 -maxdepth 1 -type d '!' -exec test -e "{}/main.py" ';' -print
@topshed
topshed / Arduino - sound detection.md
Last active May 9, 2019 11:42
Arduino - sound detection

Imgur

const int sensorPin = A0; 
int sensorValue = 0;

void setup() {
  Serial.begin(9600);
  pinMode(sensorPin, INPUT); 
}

Mapping Astro Pi Life on Earth Images

A simple way to visualise the path of the ISS while your experiment was running is to plot your photos on a map. You can use a free software application on the Raspberry Pi to do this easily and quickly.

Note: In order for this to work, you should have embedded into the EXIF meta-data of your photo the latitiude and longitude of the ISS at the time the image was captured (this process was described in this section of the Phase 2 guide).

If you saved your latitude/longitude into a CSV file but did not embed the data into the appropriate EXIF fields then you could write some code to do this now.

Installation

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
@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"]

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 / 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

@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