Purpose
Play startup sound when raspi boots
Prepare
- Raspberry Pi Zero W
- Gravity: UART MP3 Voice Module
Reference
- https://qiita.com/ikemura23/items/6f9adce99a3db555a0e4
- http://hendigi.karaage.xyz/2016/11/auto-boot/
- https://tomosoft.jp/design/?p=11677
- https://wiki.dfrobot.com/Voice_Module_SKU__DFR0534
Auto run methods
/etc/rc.local
Run script as root
crontab
Run script as user
systemd
Manage as a service
Implement
Select /etc/rc.local
at this time
Edit /home/pi/Boot/boot_syateki_server.py
as below
import serial
# open serial port
s = serial.Serial('/dev/serial0', 9600, timeout=10)
# set volume 0x16 (0x00 - 0x1E)
s.write(serial.to_bytes([0xAA,0x13,0x01,0x16,0xD4]))
# play file 01.mp3
s.write(serial.to_bytes([0xAA,0x07,0x02,0x00,0x01,0xB4]))
Confirm access authorizations
pi@raspberrypi:~/Boot $ pwd
/home/pi/Boot
pi@raspberrypi:~/Boot $ ls -l ./
total 4
-rw-r--r-- 1 root root 248 Oct 13 10:37 boot_syateki_server.py
Edit /etc/rc.local
as below
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
echo "Boot syateki server START"
/usr/bin/python3 /home/pi/Boot/boot_syateki_server.py &
echo "Boot syateki server END"
exit 0
Reboot raspi and confirm whether speaker sounds
pi@raspberrypi:~ $ sudo reboot