The car sensor is a useful tool for anyone who rides their bike while listening to music, a podcast or just does not have the best hearing in general. It utilizes ODAS in order to detect the sound of a car and display red lights from the direction the car is coming from to alert the user.
Required HardwareBefore getting started, let's review what you'll need.
- Raspberry Pi 3 (Recommended). Not tested yet in Pi 2 Model B.
- MATRIXCreator/MATRIXVoice - Raspberry Pi does not have a built-in microphone, the MATRIX Creator/MATRIXVoice have an 8 mic array - Buy MATRIX Voice/MATRIX Creator
- Micro-USB power cable for Raspberry Pi.
- Portable Charger that you can use to power your MATRIX Device.
- Phone Mount to attach your Raspberry Pi and MATRIX Device to your bicycle.
- Micro SD Card (Minimum 8 GB) - An operating system is required to get started. You can download Raspbian Stretch and use etcher.io to flash the image onto your SD Card.
- A USB Keyboard & Mouse, and an external HDMI Monitor - we also recommend having a USB keyboard and mouse as well as an HDMI monitor handy. You can also use the Raspberry Pi remotely through SSH, see this guide from Google.
- Internet connection (Ethernet or WiFi). Note: Pi 3 has built-in WiFi.
If you haven't already, be sure to setup your Raspberry Pi with your MATRIX Device.
Once setup, ensure you enable SSH on your Raspberry Pi.
1. Install MATRIX LibrariesFollow the steps below in order for Rhasspy to work on your Raspberry Pi.
2. Install ODASODAS is the library we will be using to get the direction of arrival of a cars horn and engine.
Install Required Dependancies (one at a time)
sudo apt-get install g++ git cmake
sudo apt-get install libfftw3-dev
sudo apt-get install libconfig-dev
sudo apt-get install libasound2-dev
sudo apt install libjson-c-dev
Clone & Build Our ODAS Repository
cd ~/
git clone https://github.com/matrix-io/odas.git
cd odas
git checkout yc/add-matrix-demo
mkdir build
cd build
cmake ..
make
3. Test the demo!We need to run two applications. The first is called odaslive, this app performs all of the audio processing. The second we need to run the matrix-odas app that receives the results and use them to draw colors into the MATRIX Everloop.
Run matrix-odas:
cd ~/odas/bin
./matrix-odas &
Run odaslive in the same terminal:
for MATRIX Creator use:
./odaslive -vc ../config/matrix-demo/matrix_creator.cfg
for MATRIX Voiceuse:
./odaslive -vc ../config/matrix-demo/matrix_voice.cfg
Make some noise!... you should see a blue lights indicating where the sound is coming from.
Once done testing press Ctrl + C to terminate the process.
4. Edit the sensitivity and colorGo into matrix-odas.cpp file to edit the lights and sounds.
cd ~/odas/demo/matrix-demos
nano matrix-odas.cpp
We've found that a sensitivity increment of 16 is best to detect a cars horn. Change the increment from 20 to 16 as shown below.
// INCREMENT : controls sensitivity
#define INCREMENT 16
Then change MIN_THRESHOLD from 10 to 255 and MAX_BRIGHTNESS from 25 to 255.
// MAX_BRIGHTNESS: Filters out low energy
#define MIN_THRESHOLD 255
// MAX_BRIGHTNESS: 0 - 255
#define MAX_BRIGHTNESS 255
Finally change the value for the color blue to 0 and make the color red's value color as shown below.
image1d.leds[i].red = color;
image1d.leds[i].green = 0;
image1d.leds[i].blue = 0;
image1d.leds[i].white = 0;
5. Test the programRun matrix-odas:
cd ~/odas/bin
./matrix-odas &
Run odaslive in the same terminal:
for MATRIX Creator use:
./odaslive -vc ../config/matrix-demo/matrix_creator.cfg
for MATRIX Voiceuse:
./odaslive -vc ../config/matrix-demo/matrix_voice.cfg
Now that the sensitivity has been changed you will need to yell at your MATRIX device in order to test this. Being really close to the microphones will also help in detecting a sound if you are not using a real car horn to test.
Once done testing press Ctrl + C to terminate the process.
6. Running the program on bootOnce you have verified that your program is running successfully, you can it run on boot so that it starts whenever your Raspberry Pi starts up.
In your Raspberry Pi, open the rc.local file using the following command in the terminal.
sudo nano /etc/rc.local
Add the following line to the beginning of the file.
for MATRIX Creator use:
/./home/pi/odas/bin/matrix-odas &
/home/pi/odas/bin/odaslive -vc ../config/matrix-demo/matrix_creator.cfg &
for MATRIX Voice use:
/./home/pi/odas/bin/matrix-odas &
/home/pi/odas/bin/odaslive -vc ../config/matrix-demo/matrix_voice.cfg &
Save the file by entering Ctrl-X, then Y.
Check to see if rc.local woks by running the following command in your pi's terminal.
/etc/rc.local
If the sensor runs through rc.local as expected, then you are good to go.
Now mount your MATRIX Device to your bike and have a safe trip!
Comments