From f71adf4155506b1f7000a2d748430f971543d271 Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Mon, 2 Oct 2017 22:30:36 +0100 Subject: [PATCH] Initial Commit --- Readme.md | 7 +++++++ WatchPotNeverBoils.ino | 44 ++++++++++++++++++++++++++++++++++++++++++ cv.py | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 Readme.md create mode 100644 WatchPotNeverBoils.ino create mode 100644 cv.py diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..678eb98 --- /dev/null +++ b/Readme.md @@ -0,0 +1,7 @@ +# A Watched Pot Never Boils + +This repo uses a Raspberry Pi and a 433Mhz remote controlled socket to enforce the old idiom, "A Watched Pot Never Boils". + +This code is unmaintained, and was written at 4am after seeing a video by Tom Scott that contained this very concept. + +A writeup of how this was done can be found on my blog, [here]() diff --git a/WatchPotNeverBoils.ino b/WatchPotNeverBoils.ino new file mode 100644 index 0000000..87edf11 --- /dev/null +++ b/WatchPotNeverBoils.ino @@ -0,0 +1,44 @@ +/* +Send an n to turn on, a f to turn off +*/ + + + +#include + +RCSwitch mySwitch = RCSwitch(); +int inbyte = 0; // for incoming serial data + + +void setup() { + + Serial.begin(9600); + + // Transmitter is connected to Arduino Pin #10 + mySwitch.enableTransmit(10); + + // Optional set protocol (default is 1, will work for most outlets) + // mySwitch.setProtocol(2); + + // Optional set pulse length. + mySwitch.setPulseLength(242); + + // Optional set number of transmission repetitions. + // mySwitch.setRepeatTransmit(15); + +} + +void loop() { + + /* Same switch as above, but using binary code */ + if (Serial.available() > 0) { + inbyte = Serial.read(); + switch (inbyte) { + case 102: + mySwitch.send("000011110000000000000000"); + case 110: + mySwitch.send("000011110000000011000000"); + } + } + +} diff --git a/cv.py b/cv.py new file mode 100644 index 0000000..a49db1c --- /dev/null +++ b/cv.py @@ -0,0 +1,39 @@ +import io +import picamera +import cv2 +import numpy +import serial + +#Load a cascade file for detecting faces +face_cascade = cv2.CascadeClassifier('/home/pi/opencv-3.3.0/data/haarcascades/haarcascade_frontalface_default.xml') + +ser = serial.Serial('/dev/ttyACM0') + +while True: + #Create a memory stream so photos doesn't need to be saved in a file + stream = io.BytesIO() + + #Get the picture (low resolution, so it should be quite fast) + #Here you can also specify other parameters (e.g.:rotate the image) + with picamera.PiCamera() as camera: + camera.resolution = (320, 240) + camera.capture(stream, format='jpeg') + + #Convert the picture into a numpy array + buff = numpy.fromstring(stream.getvalue(), dtype=numpy.uint8) + + #Now creates an OpenCV image + image = cv2.imdecode(buff, 1) + + #Convert to grayscale + gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) + + #Look for faces in the image using the loaded cascade file + faces = face_cascade.detectMultiScale(gray, 1.1, 5) + print("Found "+str(len(faces))+" face(s)") + + if len(faces) > 0: + ser.write(b'f') + else: + ser.write(b'n') +