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
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.
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)
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
It's pretty simple!
Here is a demo video. (Imagine the sound!)
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.
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