Good evening, this is Bono.
A relative of mine has a certain disease, and he has to take his medicine before every meal, but he often forgets to do so.
If it is after every meal, it seems to be okay because of the trigger of rice, but certainly if it is before every meal, it is usually difficult to remember unless you have to remember it yourself.
So, I made and presented a gadget to prevent such forgetting to take medicine, and here is a summary of what I did.
- finished product
- (technical) specification
- What you need
- way of making
This time, I packaged it inside a toy Lodi. (I bought it as a toy, but my child didn't play with it much, so I decided to put it to good use this way.)
The main specifications are written below.
- Sounds at fixed times of 6:00, 11:00, and 17:00 every day.
- Two types of sounds are available: music and voice.
- The music was "A scent of cyclamen" by Akira Fuse, a favorite of my relatives.
- The voice is Fuse Akira's voice, "Are you forgetting something?" and speaks to you.
- Surprise a child's toy that was already in the house with a gadget.
What you need
The following parts/materials are used here.
- Raspberry Pi TypeB
- SD card: 8GB
- Speaker: ELECOM's ASP-SMP100L
- Real Time Clock (RTC): DS3231
- Stuffed animals (anything that can be packaged): Lodi dolls for toys
- power (button on TV, etc.)
- Phonematerials (described below)
- Switch: 2-stage ON/OFF switching type
- Breadboard or universal board
- Electric wire: male-female is useful to connect the board to the Raspberry Pi
- Tupperware: 100 yen uniform is sufficient
way of making
Prepare Raspberry Pi
Follow the previous posts to install the OS on the Raspberry Pi and perform the initial setup.
Install the library pygame for music playback. We referred to the following site for the installation and its configuration.
You can play, stop, fade out, adjust volume, etc., so with a little effort you can even create a jukebox.
Raspberry Pi by itself cannot produce sound, so we purchased speakers.
This time I wanted to mount it all on the Tupperware, so I searched Amazon for speakers and chose the smallest possible. (which ended up sticking out a bit)
The volume is sufficient for use in the house, the sound quality is not bad, it is rechargeable and can be used many times, resulting in a good purchase. I recommend it.
Prepare sound material
Since he is a Fuse Akira fan, we attempted to prepare two types of voices: a hint of cyclamen, his signature song, and his voice.
As a result, we decided to forego voice this time and use only music.
Although pygame can play sounds in several formats, we use the familiar mp3 format here.
Download Cyclamen no Kahori on iTunes.
I then converted it to mp3 format on iTunes according to the following site. This is OK.
It would be best if we had audio of Fuse Akira himself, but since we have no connections or anything, we will not do such a high hurdle.
In such a case, it is all about posting on koebu! (I used it for the first time at a hackathon I competed in the past and found it so useful that I've been saving up to use it somewhere else for a long time.)
Therefore, we have solicited mimicry voices with the following conditions.
- in the manner of Fuse Akira
- Dialogue: hoge, aren't you forgetting something?
- Request: Speak softly to me.
However, after waiting two weeks, no one has submitted any audio.
Was it still too different generations? For now, we decided to give it a miss this time.
I adjusted the volume according to the following website. With this speaker, I got a good volume at about 90%.[crayon] sudo amixer cset numid=1 90
In this case, we want to have the ability to produce sound at a certain time, so it is essential to know the real time.
However, the Raspberry Pi does not have an RTC function to keep track of real time.
The method would be to either use NTP, which uses the network, or an external RTC module.
In this case, we decided not to use the network because there is not much need for it.
So we decided to install an RTC module and get real-time from it.
The purchase was made on Amazon. The price was about 1,300 yen.
The unit price itself is cheaper at places like RS Online, so if you're buying in bulk, that's a better deal.
Writing time to RTC
Basically, we followed the following website.
In addition, although it was not mentioned on this site, after the following line, the following method was used for writing.[crayon] echo ds3231 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
After this, the current time is obtained from the network using the following command.[crayon] sudo ntpd -gq
The following command was then used to write the set time to the RTC.[crayon] sudo hwclock -w
Finally, make sure it is written properly, just to be sure.[crayon] date
Installation of switch section
For versatility, the following multiple switches were installed. The switches themselves were purchased at Akihabara.
- ON/OFF switch: Enables/disables the function
- ON/OFF switch: select music/voice mode
- Push switch: manual mode (toggle playback and stop)
Determination of the number of
The GPIO only needs to be able to detect High/Low levels, so the current should be small.
Here, we used a 10kΩ resistor that we had on hand. (As a precaution, the resistor value should not be too large, since the switch has a minimum current value specification and it is recommended that a higher current be applied.)
Mounted on board
Mount the device on a universal board with a soldering iron.
The universal board is only for testing.
Due to the physical characteristics of the switch, it does not switch instantaneously between ON and OFF the moment it is pressed, but rather repeats ON and OFF several times, settling down after a certain time. (You can see this clearly by looking at it with an oscilloscope.)
This phenomenon is called chattering.
Whenever you use a switch, you must keep this phenomenon of chattering in mind, or you will have a problem somewhere.
There are several measures that can be taken.
For example, a low-pass filter can be created with a resistor and a capacitor to eliminate chattering in a hard way, or a soft way can be used to determine the state when the state has not changed for a certain period of time.
In this case, we wanted to make the circuit as small as possible, so we took care of the problem software-wise.
Attach RTC, switches, speakers, power supply, and circuitry to Raspberry Pi
Drill holes in the tupperware and attach the RTC, switch, power supply, and circuitry as shown in the photo below.
The switch was fixed with hot melt to prevent it from coming off. I actually tried to fix the speaker and circuit as well, but gave up due to lack of time.
Creating a program to play sound
What's in the Program[crayon] import pygame.time
playing = False
pause = False
power_input1 = GPIO.input(23)
power_input2 = GPIO.input(23)
if power_input1 == power_input2: if power_input1 == power_input2: if power_input1 == power_input2
if power_input2 == True: if power_input2 == True
Brief description of the program
First, load a previously created mp3 file.
For power_input1 and power_input2, if the state after 0.1 second matches a certain timing for software chattering prevention, the switch state is assumed to be fixed.
and if the power switch is ON, music is played.
For a playback time of 4 minutes and 34 seconds for Cyclamen's Scent, time.sleep is set to 275 seconds.
The following site was used as a reference for setting up to use GPIOs.
The following command successfully played a hint of cyclamen! Sound quality and volume are not bad.[crayon] sudo python /home/pi/RPi.GPIO-0.4.1a/test/drag.py
Setting up cron
Now that the music has been played above, all that remains is to set up cron to run this command at a certain time!
I thought it would be easy to set up cron, but I ran into a little bit of trouble. I thought it would be, but I got a little stumped.
I called cron with the following command, which is the usual way, and set it up to run every minute as follows.[crayon] crontab -e
- sudo python /home/pi/RPi.GPIO-0.4.1a/hoge.py
- sudo python /home/pi/RPi.GPIO-0.4.1a/hoge.py
However, no matter how long they waited, the line was not executed.
When I type the above command manually instead of cron, it runs fine.
I found an unexpected error when I looked at the following file, which can spit out cron errors.[crayon] vim /var/log/sylog
[/crayon] [crayon] Dec 18 22:40:03 raspberrypi /USR/SBIN/CRON : (CRON) info (No MTA installed, discarding output)
As shown in the following page, others are experiencing the exact same phenomenon. Apparently, cron can only be used if a mailer like postfix is installed.
Since it is not included in Raspberry Pi by default, install as follows.[crayon] $ sudo apt-get install postfix
Here the configuration screen appears. In this case, I selected the lowest, LOCAL USE ONLY.
For your information, we have set the music to play every day at 6:00, 11:30, and 5:30 pm.
It took about two weeks, including the time to gather tools.
He was surprised and pleased with it, and is still using it every day. He still uses it every day.
How to play music on Raspberry Pi
In addition to pygame, there seems to be another software called mpg321. I tried it and was able to play it here as well.
See the following website for details.