Problem description
You spent many nights on your project for a Design Challenge and sometimes people on the community likes your efforts. So, isn’t it a good opportunity to self-celebrate yourself with this fantastic device?
What is patpat-o-matic?
Patpat-o-matic monitors the number of points on you Element14’s profile. Every time someone likes your contents, the number of points increases, and the device activates to compliment you by giving a pat on your shoulder. Obviously, it’s not easy to pat with the right amount of force, so I will leverage the knowledge I built while making the projects and design challenges to create the perfect pat
Stages
The patpat-o-matic is made has the following stages
Stage 1: Raspberry Pi
A Raspberry Pi with a camera “reads” a computer screen. I received a Raspberry PI HW camera has part of the Photography Project14, where I built the Emoticam, a camera that allows you the overimpress your feelings to the pictures you are taking. This was my first approach to the technique called neural style transfer
By means of Tesseract, the image undergoes the OCR to detect extract the number of points. Luckily, I explored OCR with OpenCV in my Automated car marshal, which was built during the Auto hack Project14.
When the value changes, an output on a Pimoroni Automation hat is activated. You can find more details about the Pimoroni Automation hat in my Gr0G project, which was part of my preparation for my next travel to Mars.
The output is connected to a relay which drives a heater
Here is the source code for the application running on the Raspberry Pi and OCRs the video stream from the camera to detect points
#!/usr/bin/env python3 import sys import time import os import cv2 import pytesseract from pytesseract import Output import automationhat time.sleep(0.1) # Short pause after ads1015 class creation recommended try: from PIL import Image, ImageDraw except ImportError: print("""This example requires PIL. Install with: sudo apt install python{v}-pil """.format(v="" if sys.version_info.major == 2 else sys.version_info.major)) sys.exit(1) cap = cv2.VideoCapture(0) cap.set(cv2.CAP_PROP_BUFFERSIZE, 1) state = 0 start = 0 n = 0 d = None n_boxes = 0 while True: # Capture frame-by-frame ret, frame = cap.read() n = n+1 if n == 10: n = 0 d = pytesseract.image_to_data(frame, output_type=Output.DICT) n_boxes = len(d['text']) for i in range(n_boxes): if int(d['conf'][i]) > 60: (text, x, y, w, h) = (d['text'][i], d['left'][i], d['top'][i], d['width'][i], d['height'][i]) # don't show empty text if text and text.strip() != "": frame = cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) frame = cv2.putText(frame, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 0, 255), 3) automationhat.output[0].on() start = time.time() state = 1 # Display the resulting frame cv2.imshow('frame', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break if (state == 1): end = time.time(); delta = end - start if (delta > 15): automationhat.output[0].off() state = 2 # When everything done, release the capture cap.release() cv2.destroyAllWindows()
Stage 2: Raspberry Pi Micro (1)
The heater heats a Thermorite thermal switch. I experimented with thermal switches during a design challenge. In this challenge, I created two devices to extract otherwise-wasted heat from my boiler and solar plant.
When the target temperature is reached, the thermal switch closes and a Raspberry Pi Micro is powered up. The Raspberry Pi Micro drives a servo motor, that releases a bar made of harmonic steel
Most of the Raspberry Pi Pico runs a very simple code the basically reads a digital input and drives a servo when the input is 1 or 0 (depending on the input being monitored)
from time import sleep from machine import Pin, PWM input=Pin(28,Pin.IN,Pin.PULL_UP) led=Pin(25,Pin.OUT) led.value(0) pwm = PWM(Pin(1)) pwm.freq(50) pwm.duty_u16(5500) done=False led.value(1) sleep(3) led.value(0) while True: led.value(input.value()) if (input.value() == 1): for position in range(5500,2000,-50): pwm.duty_u16(position) sleep(0.01) done=True else: sleep(0.5)
Stage 3: Raspberry Pi Micro (2)
The steel bar passes by a TT Electronic reflective optical proximity switch, which I reviewed some time ago.
A Raspberry Pi Micro reads the output of the proximity sensor. When proximity sensor detects the bar, the Raspberry Pi Micro activates a servo. The lever on the servo shaft activates a switch
Stage 4: TMC2300
The lever on the servo shaft activates a switch which powers a TMC2300. The TMS2300 is a very interesting board.
I initially reviewed this product, and later built an ornament for your Christmas Tree that shows wishes sent via Twitter.
The TMC2300 drives a stepper motor that winds a thread and powers up the next stage
Stage 5: Raspberry Pi Micro (3)
The last step is a Raspberry Pi Micro that drives a servo that controls the pat-pat mechanism. The pat-pat mechanism is driven by a relic from many years ago: it was kindly provided by Element14 as part of the “Enchanted objects” challenge, where I took inspiration from Harry Potter’s Sorting hat to create a Magic hat .
The original idea was to devise a blood pressure instrument based on a novel approach, but unfortunately this experiment failed miserably
Patpat-o-matic in action
But now, no more talk. Let’s have our daily portion of pats!