Skip to content

Instantly share code, notes, and snippets.

View martinohanlon's full-sized avatar

Martin O'Hanlon martinohanlon

View GitHub Profile
from sense_hat import SenseHat
def display_acceleration(x, y, z):
print("{:06.2f}|{:06.2f}|{:06.2f}".format(x, y, z))
sense = SenseHat()
while True:
acceleration = sense.get_accelerometer_raw()
x = acceleration['x']
@martinohanlon
martinohanlon / img_pad.py
Created July 14, 2020 08:08
A utility for padding image files.
"""
A utility for padding image files.
"""
from PIL import Image, ImageOps, UnidentifiedImageError
import os.path
def find_files(path, file_names=[], extensions=[]):
def valid_file(file_path):
@martinohanlon
martinohanlon / sensehat_thermalcam.py
Created November 20, 2017 21:54
Python thermal camera example using Sense Hat and AMG8833
"""
An adaptation of Adafruit's thermal camera example which
uses the sense hat to display temperatures.
Martin O'Hanlon
@martinohanlon
stuffaboutco.de
"""
from sense_hat import SenseHat
from Adafruit_AMG88xx import Adafruit_AMG88xx
@martinohanlon
martinohanlon / demo.py
Last active September 23, 2020 10:21
DM@H paint app
from guizero import App, Text, Drawing, Combo, Box, Slider, PushButton
def start(event):
painting.start_event = event
def draw(event):
painting.line(
painting.start_event.x, painting.start_event.y,
event.x, event.y,
color=color_picker.value,
@martinohanlon
martinohanlon / detect_motion.py
Last active June 28, 2022 08:29
picamera motion detection - super hacky!
from picamera import PiCamera, PiCameraCircularIO, PiVideoFrameType
from picamera.array import PiRGBArray
from time import sleep
import io
import cv2
def diff_image(t0, t1, t2):
d1 = cv2.absdiff(t2, t1)
d2 = cv2.absdiff(t1, t0)
return cv2.bitwise_and(d1, d2)
@martinohanlon
martinohanlon / guizero_stopmotion.py
Last active August 29, 2022 20:53
a guizero app which uses the picamera to make stop motion gifs
# This is a simple gui for creating stop motion animations using the Pi camera
# martin@ohanlonweb.com
# stuffaboutcode.com
# Instructions:
# - Connect a camera module
# - Enable the camera (Menu > Preferences > Raspberry Pi Configuration, Interfaces, Camera)
# - Install the relevant modules, open a terminal (Menu > Accessories > Terminal) and run:
# - sudo pip3 install guizero
# - sudo pip3 install imageio
@martinohanlon
martinohanlon / guizero_pushbutton_animation.py
Created June 15, 2018 15:26
A push button animation with guizero
# Install
# - sudo pip3 install guizero
# - sudo pip3 install imageio
# - Attached a picamera and a button to pin 17
# - Run it
from guizero import App, Picture, PushButton, Text
from picamera import PiCamera
from picamera.array import PiRGBArray
from gpiozero import Button