[PYTHON] I tried to automate [a certain task] using Raspberry Pi

Introduction

How does your company feel at the beginning and end of work? I think that there are things such as notifying by in-house broadcasting, starting work without permission when the time comes, starting a morning assembly when the time comes.

At the company I used to work for

  1. The ipod sounds an alarm (quiet) at the start of work
  2. The person in charge stops the alarm
  3. Manually ring the following chime (?) To inform people in the company. image.png ↑ Hit this with a stick to make it sound

I was doing it in the flow.

~~ To be honest, it takes time to stop the alarm and hit it every day. ~~ I think we should simply sound the alarm on time.

However, *** That's not interesting, so let's automate the action of hitting this chime anyway! *** So I automated it using Raspberry Pi (and Python) (studying). Just because Sync had a Raspberry Pi, I decided to make it with half the story with Sync.

Preparation

We first looked at what was needed to automate it. Fortunately, Raspberry Pi had the same thing, so I didn't have much to prepare. The purchases are as follows.

Both purchased on Amazon! As for the servo motor, I bought a digital micro servo SG90 (770 yen).

The automation mechanism is simple, just control the angle of the motor with a program and hit the chime. It's cool to say automation, but it's not a big deal (laughs)

development of

The code I wrote this time looks like this.

# -*- coding: utf-8 -*-             #Encoding specification
import RPi.GPIO as GPIO             #Import modules for GPIO
import time                         #Import module for time control
import sys                          #Import sys module

#Port number definition
Servo_pin = 18                      #variable"Servo_pin"Store 18 in

#GPIO settings
GPIO.setmode(GPIO.BCM)              #GPIO mode"GPIO.BCM"Set to the method of handling GPIO by port number
GPIO.setup(Servo_pin, GPIO.OUT)     #Set GPIO18 to output mode

#PWM settings
#Servo motor SG90 frequency is 50[Hz]
Servo = GPIO.PWM(Servo_pin, 50)     #GPIO.PWM(port number,frequency[Hz])

Servo.start(0)                      #Servo.start(Duty ratio[0-100%])

#Function to find the duty ratio from the angle
def servo_angle(angle):
    duty = 2.5 + (12.0 - 2.5) * (angle + 90) / 180   #Find the duty ratio from the angle
    Servo.ChangeDutyCycle(duty)                      #Change duty ratio
    time.sleep(0.2)                                  #0.Wait 2 seconds

#Control the angle of the servo motor with the duty ratio
#Servo.ChangeDutyCycle(Duty ratio[0-100%])
servo_angle(0)                 #Move the servo motor to the initial position
servo_angle(90)                #Servo motor 90 °
servo_angle(0)                 #Return the servo motor to its initial position
Servo.stop()                   #Stop the servo motor
GPIO.cleanup()                 #Clean up GPIO
sys.exit()                     #Exit the program

The code itself is not difficult because it only controls the angle of the servo motor, and there was a lot of information on the net, so it was smooth.

Although I graduated from the mechanical department, I didn't have much experience in electronic work (I mainly studied lathes, welding, drafting, etc. at university), so I did research while connecting jumper wires.

By automating, I set Coulomb to run the program during the start and end hours. I didn't know the existence of Coulomb, and I was taught from the same period (I learned)

Cron is a type of resident program (daemon) that is used as standard in many UNIX-based OSs, and periodically starts the specified program according to the schedule set by the user. Reference source: IT Glossary e-Words

The finished product

It's pretty simple!

ささとら君 photo3.JPG

ささとら君 photo1.PNG

Here is a demo video. (Imagine the sound!) ささとら君 動画.gif

How about that? It's a pretty surreal finish (laughs) When actually using it, I try to hit it only once. With this, I didn't have to hit it manually anymore, and I was able to leave only the goodness of the chime.

Summary

This time, I tried to automate the start and end chimes with Raspberry Pi.

I think the fun of programming is that you can solve the inconveniences and inefficiencies that you felt while living in this way. It was fun to actually try it, and it was a great experience to learn what I didn't know.

Everyone can use something as simple as this, so why not try it?

Recommended Posts

I tried to automate [a certain task] using Raspberry Pi
I tried to automate the watering of the planter with Raspberry Pi
I tried to make a motion detection surveillance camera with OpenCV using a WEB camera with Raspberry Pi
I tried to make a ○ ✕ game using TensorFlow
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
I talked to Raspberry Pi
I tried to draw a configuration diagram using Diagrams
I tried to create a button for Slack with Raspberry Pi + Tact Switch
I tried using the DS18B20 temperature sensor with Raspberry Pi
I tried to make a stopwatch using tkinter in python
Using a webcam with Raspberry Pi
I tried to make a simple text editor using PyQt
I wanted to run the motor with Raspberry Pi, so I tried using Waveshare's Motor Driver Board
I tried to automate "one heart even if separated" using a genetic algorithm in Python
I tried using PI Fu to generate a 3D model of a person from one image
I tried to automate the construction of a hands-on environment using IBM Cloud's SoftLayer API
[5th] I tried to make a certain authenticator-like tool with python
I tried to get a database of horse racing using Pandas
[2nd] I tried to make a certain authenticator-like tool with python
I tried to make a regular expression of "amount" using Python
I made a web server with Raspberry Pi to watch anime
I tried to make a regular expression of "time" using Python
I tried to implement anomaly detection using a hidden Markov model
[3rd] I tried to make a certain authenticator-like tool with python
I tried to get a list of AMI Names using Boto3
I tried to make a todo application using bottle with python
[4th] I tried to make a certain authenticator-like tool with python
[1st] I tried to make a certain authenticator-like tool with python
I tried to create a linebot (implementation)
I tried using Azure Speech to Text.
I tried playing a ○ ✕ game using TensorFlow
I tried drawing a line using turtle
I tried to classify text using TensorFlow
I tried to estimate the pi stochastically
I tried to make a Web API
I tried using pipenv, so a memo
I tried to predict Covid-19 using Darts
I tried to perform a cluster analysis of customers using purchasing data
I tried to create a sample to access Salesforce using Python and Bottle
I tried to build a super-resolution method / ESPCN
I tried to build a super-resolution method / SRCNN ①
Try using a QR code on a Raspberry Pi
I tried to find 100 million digits of pi
I tried L-Chika with Raspberry Pi 4 (Python edition)
I tried using Pythonect, a dataflow programming language.
I tried reading a CSV file using Python
I tried to automate sushi making with python
I tried to generate a random character string
Create a visitor notification system using Raspberry Pi
I tried to build a super-resolution method / SRCNN ③
I tried to build a super-resolution method / SRCNN ②
Connect your Raspberry Pi to your smartphone using Blynk
I tried using a database (sqlite3) with kivy
I have a question. Unable to make protocol buffers on raspberry pi 3 modelB.
[Python] Deep Learning: I tried to implement deep learning (DBN, SDA) without using a library.
I tried to build an environment of Ubuntu 20.04 LTS + ROS2 with Raspberry Pi 4
I tried running Flask on Raspberry Pi 3 Model B + using Nginx and uWSGI
I tried to make a translation BOT that works on Discord using googletrans
I tried to make a suspicious person MAP quickly using Geolonia address data
I tried using parameterized
I tried using argparse