Blog Index | Next >> |
---|
Inspired on blog posts from my fellow challengers sakthi.1260, carmelito and Workshopshed, as well as mcb1 comment on my first blog:
When I saw the application, my first thought is how does someone know what the numbers represent ... they are numbers.
I'm sure as you progress that will be sorted.
I decided to let my display speak the different functions when changed with the button.
The problem mcb1 mentioned was already solved by the menu system and the one second function number display, but I decided it is much more fun to let the display speak for itself.
Another goal of my project is to keep the display as original as possible. Therefore I didn't like to add a loudspeaker, or even a connector to add one. In stead I decided to connect a wireless speaker over bluetooth.
Connecting the bluetooth speaker
Connecting the bluetooth speaker was not a big issue with the help of the intel documentation: https://software.intel.com/en-us/articles/play-audio-from-your-intel-edison-via-bluetooth-using-advanced-audio-distribut…
First we need to pair the device:
root@edison_nixie:~# rfkill unblock bluetooth
root@edison_nixie:~# bluetoothctl
[bluetooth]# scan on
[NEW] Controller 98:4F:EE:04:A7:E4 edison_nixie [default]
[NEW] Device 00:1D:DF:CD:2F:DB JBL Flip
[bluetooth]# pair 00:1D:DF:CD:2F:DB
[bluetooth]# quit
This needs to be done just once. Later each time we boot the Edison, the speaker needs to be connected again:
root@edison_nixie:~# rfkill unblock bluetooth
root@edison_nixie:~# bluetoothctl
[NEW] Controller 98:4F:EE:04:A7:E4 edison_nixie [default]
[NEW] Device 00:1D:DF:CD:2F:DB JBL Flip
[bluetooth]# connect 00:1D:DF:CD:2F:DB
Attempting to connect to 00:1D:DF:CD:2F:DB
[CHG] Device 00:1D:DF:CD:2F:DB Connected: yes
Connection successful
[JBL Flip]# quit
[DEL] Controller 98:4F:EE:04:A7:E4 edison_nixie [default]
root@edison_nixie:~# pactl list sinks
Sink #0
State: SUSPENDED
Name: alsa_output.platform-merr_dpcm_dummy.0.analog-stereo
.....................
Sink #2
State: SUSPENDED
Name: bluez_sink.00_1D_DF_CD_2F_DB
Description: JBL Flip
............................
root@edison_nixie:~# pactl set-default-sink bluez_sink.00_1D_DF_CD_2F_DB
And we are done. This gives a pulse audio connection to the speaker. Sound files can be played using:
root@edison_nixie:~# gst-launch-1.0 filesrc location= /home/root/sound.wav ! wavparse ! pulsesink
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstPulseSinkClock
Got EOS from element "pipeline0".
Execution ended after 0:00:00.919603573
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
root@edison_nixie:~#
Espeaking the functions
Then I installed espeak and also alsa-utils in order to speak the function names.
opkg install espeak
opkg install alsa-utils
Unfortunately espeak is based on port audio, while my bluetooth connection uses pulseaudio. So I didn't get any audio out when running:
espeak "Louder please!"
In stead of putting a lot of effort in getting speak to run with pulse audio, I decided to take a shortcut by making sound files for all my functions:
espeak --stdout "Time" > time.wav
espeak --stdout "Date" > date.wav
espeak --stdout "Temperature" > temperature.wav
espeak --stdout "Humidity" > humidity.wav
espeak --stdout "Pressure" > pressure.wav
espeak --stdout "Rain" > rain.wav
espeak --stdout "Views and likes" > viewsandlikes.wav
Node.js code
Finally playing the function names is added to the code. For this I downloaded the node-cmd module:
root@edison_nixie:~# npm install node-cmd
node-cmd@3.0.0 node_modules/node-cmd
root@edison_nixie:~#
Each time the button is released the edison will speak the selected function name:
var cmd=require('node-cmd'); button.on("release", function () { speakFunction(); setTimeout(function () { switch_function = false; }, 1000); });
SpeakFunction just calls the pulse audio play function with the appropriate sound file:
function speakFunction() { switch (display_function) { case 0: cmd.run('gst-launch-1.0 filesrc location= /home/root/time.wav ! wavparse ! pulsesink'); break; case 1: cmd.run('gst-launch-1.0 filesrc location= /home/root/date.wav ! wavparse ! pulsesink'); break; case 2: cmd.run('gst-launch-1.0 filesrc location= /home/root/temperature.wav ! wavparse ! pulsesink'); break; case 3: cmd.run('gst-launch-1.0 filesrc location= /home/root/humidity.wav ! wavparse ! pulsesink'); break; case 4: cmd.run('gst-launch-1.0 filesrc location= /home/root/pressure.wav ! wavparse ! pulsesink'); break; case 5: cmd.run('gst-launch-1.0 filesrc location= /home/root/rain.wav ! wavparse ! pulsesink'); break; case 6: cmd.run('gst-launch-1.0 filesrc location= /home/root/viewsandlikes.wav ! wavparse ! pulsesink'); break; } }
Demonstration video
One more thing!
In order to automatically connect the speaker to the Edison at boot time, I wrote the following shell script:
#!/bin/sh rfkill unblock bluetooth sleep 1 echo -e 'connect 00:1D:DF:CD:2F:DB\nquit' | bluetoothctl sleep 1 pactl set-default-sink bluez_sink.00_1D_DF_CD_2F_DB gst-launch-1.0 filesrc location= /home/root/connected.wav ! wavparse ! pulsesink
Modified the execute permissions and made a connected sound file:
root@edison_nixie:~# chmod 755 startbtspeaker.sh
root@edison_nixie:~# espeak --stdout "Bluetooth speaker connected!" > connected.wav
And finally installed it as system service:
#!/bin/sh [Unit] Description=Sets up the Edison's Bluetooth interface and connects it to a paired device. [Service] ExecStart=/home/root/startbtspeaker.sh Type=idle [Install] WantedBy=basic.target
Put the file above in /lib/systemd/system/startbt.service and:
systemctl enable startbt.service
Now each time the display is turned on, the speaker assuming it is on will be connected and "Bluetooth speaker connected!" is spoken.
Thats it for now, stay tuned for the wrap up later this week!
Top Comments