|
| 1 | +# Sound Detector in Python* |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This Sound Detector application is part of a series of how-to Intel® Internet of Things (IoT) code sample exercises using the Intel® IoT Developer Kit, Intel® Edison development platform, cloud platforms, APIs, and other technologies. |
| 6 | + |
| 7 | +From this exercise, developers will learn how to:<br> |
| 8 | +- Connect the Intel® Edison development platform, a computing platform designed for prototyping and producing IoT and wearable computing products.<br> |
| 9 | +- Interface with the Intel® Edison platform IO and sensor repository using MRAA and UPM from the Intel® IoT Developer Kit, a complete hardware and software solution to help developers explore the IoT and implement innovative projects.<br> |
| 10 | +- Store the Sound Detector data using Azure Redis Cache\* from Microsoft\* Azure\*, Redis Store\* from IBM\* Bluemix\*, or ElastiCache\* using Redis\* from Amazon Web Services\* (AWS), different cloud services for connecting IoT solutions including data analysis, machine learning, and a variety of productivity tools to simplify the process of connecting your sensors to the cloud and getting your IoT project up and running quickly. |
| 11 | +- Set up a MQTT-based server using IoT Hub from Microsoft\* Azure\*, IoT from IBM\* Bluemix\*, or IoT from Amazon Web Services\* (AWS), different cloud machine to machine messaging services based on the industry standard MQTT protocol. |
| 12 | + |
| 13 | +## What it is |
| 14 | + |
| 15 | +Using an Intel® Edison board, this project lets you create a smart loudness detector system that:<br> |
| 16 | +- monitors a microphone sensor to detect the loudness in the area.<br> |
| 17 | +- keeps track of access, using cloud-based data storage. |
| 18 | + |
| 19 | +## How it works |
| 20 | + |
| 21 | +This sound detector monitor uses the sensor to constantly keep track of the decibel level in a room. |
| 22 | +Every 1sec the sensor finds the average sound samples and prints it to the RGB lcd screen. |
| 23 | + |
| 24 | +Additionally, various events (looking-for-motion, motion-detected, invalid-code, etc.) are logged. |
| 25 | +Optionally, all data can be stored using the Intel® IoT Examples Datastore running in your own Microsoft Azure account. |
| 26 | +Also, optionally, the monitor stores the loudness data using the Intel® IoT Example Data store running in your own Microsoft Azure* account. |
| 27 | + |
| 28 | +## Hardware requirements |
| 29 | + |
| 30 | +Grove* Starter Kit Plus containing: |
| 31 | + |
| 32 | +1. Intel® Edison platform with an Arduino* breakout board. |
| 33 | +2. [Grove Sound Sensor](http://iotdk.intel.com/docs/master/upm/node/classes/microphone.html). |
| 34 | +3. [Grove RGB LCD](http://iotdk.intel.com/docs/master/upm/node/classes/jhd1313m1.html). |
| 35 | + |
| 36 | +DFRobot\* Starter Kit for Intel® Edison, containing: |
| 37 | + |
| 38 | +1. Intel® Edison with an Arduino\* breakout board. |
| 39 | +2. [Analog Sound Sensor](http://iotdk.intel.com/docs/master/upm/node/classes/loudness.html). |
| 40 | +3. [LCD Keypad Shield](http://iotdk.intel.com/docs/master/upm/node/classes/sainsmartks.html). |
| 41 | + |
| 42 | +## Software requirements |
| 43 | + |
| 44 | +1. Microsoft\* Azure\*, IBM\* Bluemix\*, or AWS account (optional) |
| 45 | + |
| 46 | +### How to set up |
| 47 | + |
| 48 | +To begin, clone the **How-To Intel IoT Code Samples** repository with Git* on your computer as follows: |
| 49 | + |
| 50 | + $ git clone https://github.com/intel-iot-devkit/how-to-code-samples.git |
| 51 | + |
| 52 | +To download a .zip file, in your web browser go to <a href="https://github.com/intel-iot-devkit/how-to-code-samples">https://github.com/intel-iot-devkit/how-to-code-samples</a> and click the **Download ZIP** button at the lower right. Once the .zip file is downloaded, uncompress it, and then use the files in the directory for this example. |
| 53 | + |
| 54 | +### Installing the program manually on the Intel® Edison board |
| 55 | + |
| 56 | +You can set up the code manually on the Intel® Edison board. |
| 57 | + |
| 58 | +Clone the **How-To Intel IoT Code Samples** repository to your Intel® Edison board after you establish an SSH connection to it, as follows: |
| 59 | + |
| 60 | + $ git clone https://github.com/intel-iot-devkit/how-to-code-samples.git |
| 61 | + |
| 62 | +Then, navigate to the directory with this example. |
| 63 | + |
| 64 | +To install Git\* on the Intel® Edison board (if you don’t have it yet), establish an SSH connection to the board and run the following command: |
| 65 | + |
| 66 | + $ opkg install git |
| 67 | + |
| 68 | +### Connecting the Grove\* sensors |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +You need to have a Grove* Shield connected to an Arduino-compatible breakout board to plug all the Grove devices into the Grove Shield. Make sure you have the tiny VCC switch on the Grove Shield set to **5V**. |
| 73 | + |
| 74 | +1. Plug one end of a Grove cable into the Grove Sound Sensor, and connect the other end to the A0 port on the Grove Shield. |
| 75 | + |
| 76 | +2. Plug one end of a Grove cable into the Grove RGB LCD, and connect the other end to any of the I2C ports on the Grove Shield. |
| 77 | + |
| 78 | +### Connecting the DFRobot\* sensors |
| 79 | + |
| 80 | +You need to have a LCD Display Shield connected to an Arduino\*-compatible breakout board to plug all the DFRobot\* devices into the LCD Display Shield. |
| 81 | + |
| 82 | +1. Plug one end of a DFRobot\* cable into the Analog Sound Sensor, and connect the other end to the A2 port on the LCD Display Shield. |
| 83 | + |
| 84 | +### Intel® Edison board setup |
| 85 | + |
| 86 | +If you're running this code on your Intel® Edison board, you need to install some dependencies by establishing an SSH session to the Edison and run the commands in the sections below. |
| 87 | + |
| 88 | +#### Update the opkg repo |
| 89 | + |
| 90 | +To add the Intel opkg repository: |
| 91 | + |
| 92 | + $ echo "src mraa-upm http://iotdk.intel.com/repos/3.5/intelgalactic/opkg/i586" > /etc/opkg/mraa-upm.conf |
| 93 | + $ opkg update |
| 94 | + |
| 95 | +You'll only need to perform this step once. |
| 96 | + |
| 97 | +#### Git |
| 98 | + |
| 99 | +To install Git\* on the Intel® Edison board (if you don’t have it yet): |
| 100 | + |
| 101 | + $ opkg update |
| 102 | + $ opkg install git |
| 103 | + |
| 104 | +#### MRAA and UPM Dependencies |
| 105 | + |
| 106 | +To install the latest versions of the MRAA\* and UPM\* libraries: |
| 107 | + |
| 108 | + $ opkg update |
| 109 | + $ opkg install mraa |
| 110 | + $ opkg install upm |
| 111 | + |
| 112 | +#### Python Package Manager (pip) |
| 113 | + |
| 114 | +To install the Python\* package manager needed to install and run the example: |
| 115 | + |
| 116 | + $ pip install --upgrade pip setuptools |
| 117 | + |
| 118 | + |
| 119 | +#### Install the example |
| 120 | + |
| 121 | +Once all dependencies are installed you can install the example itself with the following command: |
| 122 | + |
| 123 | + $ pip install --src ~/python/examples/ -e "git+https://github.com/intel-iot-devkit/how-to-code-samples.git#egg=iot_sound_detector&subdirectory=sound-detector/python" |
| 124 | + |
| 125 | +The `pip` command will install required Python dependencies, save the source code for the example in `~/python/examples/iot_sound_detector/` and link the package to the global Python `site-packages` folder. |
| 126 | + |
| 127 | +### Intel® IoT Gateway setup |
| 128 | + |
| 129 | +You can run this example using an Intel® IoT Gateway connected to an Arduino\*/Genuino\* 101. |
| 130 | + |
| 131 | +Make sure your Intel® IoT Gateway is setup, by following the directions on the web site here: |
| 132 | + |
| 133 | +https://software.intel.com/en-us/node/633284 |
| 134 | + |
| 135 | +You must install the Intel® XDK on the Intel® IoT Gateway, by following the directions on the above link, under the section "Connecting to the Intel® XDK". |
| 136 | + |
| 137 | +The Arduino\*/Genuino\* 101 needs to have the Firmata\* firmware installed. If you have IMRAA installed on your gateway, this will be done automatically. Otherwise, install the StandardFirmata or ConfigurableFirmata sketch manully on to your Arduino\*/Genuino\* 101. |
| 138 | + |
| 139 | +You will also need to configure the `config.json` in the example to use the Arduino\*/Genuino\* 101. See the section "Configuring the example" below. |
| 140 | + |
| 141 | +### Data store server setup |
| 142 | + |
| 143 | +Optionally, you can store the data generated by this sample program in a back-end database deployed using Microsoft\* Azure\*, IBM\* Bluemix\*, or AWS, along with Node.js\*, and a Redis\* data store. |
| 144 | + |
| 145 | +For information on how to set up your own cloud data server, go to: |
| 146 | + |
| 147 | +[https://github.com/intel-iot-devkit/intel-iot-examples-datastore](https://github.com/intel-iot-devkit/intel-iot-examples-datastore) |
| 148 | + |
| 149 | +### MQTT server setup |
| 150 | + |
| 151 | +You can also optionally store the data generated by this sample program using MQTT, a machine-to-machine messaging server. You can use MQTT to connect to Microsoft\* Azure\*, IBM\* Bluemix\*, or AWS. |
| 152 | + |
| 153 | +For information on how to connect to your own cloud MQTT messaging server, go to: |
| 154 | + |
| 155 | +[https://github.com/intel-iot-devkit/intel-iot-examples-mqtt](https://github.com/intel-iot-devkit/intel-iot-examples-mqtt) |
| 156 | + |
| 157 | +## Configuring the example |
| 158 | + |
| 159 | +When the example is installed through `pip` the `config.json` file that holds the configuration for the example lives in `~/python/examples/iot_sound_detector/sound-detector/python/iot_sound_detector/config.json`. |
| 160 | + |
| 161 | +To configure the example for the Grove* kit, just leave the `kit` key in the `config.json` set to `grove`. To configure the example for the DFRobot* kit, change the `kit` key in the `config.json` to `dfrobot` as follows: |
| 162 | + |
| 163 | +```JSON |
| 164 | +{ |
| 165 | + "kit": "dfrobot" |
| 166 | +} |
| 167 | +``` |
| 168 | + |
| 169 | +To configure the example for the optional Microsoft\* Azure\*, IBM\* Bluemix\*, or AWS data store, add the `SERVER` and `AUTH_TOKEN` keys in the `config.json` file below the "CODE" key as follows: |
| 170 | + |
| 171 | +```JSON |
| 172 | +{ |
| 173 | + "kit": "grove", |
| 174 | + "SERVER": "http://intel-examples.azurewebsites.net/logger/access-control", |
| 175 | + "AUTH_TOKEN": "s3cr3t" |
| 176 | +} |
| 177 | +``` |
| 178 | + |
| 179 | +For information on how to configure the example for the optional Microsoft\* Azure\*, IBM\* Bluemix\*, or AWS MQTT messaging server, go to: |
| 180 | + |
| 181 | +[https://github.com/intel-iot-devkit/intel-iot-examples-mqtt/](https://github.com/intel-iot-devkit/intel-iot-examples-mqtt/) |
| 182 | + |
| 183 | +## Running the program |
| 184 | + |
| 185 | +Once the example is installed through `pip` you can run the program by running the following command in an SSH session to the board: |
| 186 | + |
| 187 | + $ python -m iot_sound_detector |
| 188 | + |
| 189 | +### Determining the Intel® Edison board's IP address |
| 190 | + |
| 191 | +You can determine what IP address the Intel® Edison board is connected to by running the following command: |
| 192 | + |
| 193 | + ip addr show | grep wlan |
| 194 | + |
| 195 | +You will see the output similar to the following: |
| 196 | + |
| 197 | + 3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 |
| 198 | + inet 192.168.1.13/24 brd 192.168.1.255 scope global wlan0 |
| 199 | + |
| 200 | +The IP address is shown next to `inet`. In the example above, the IP address is `192.168.1.13`. |
| 201 | + |
| 202 | +IMPORTANT NOTICE: This software is sample software. It is not designed or intended for use in any medical, life-saving or life-sustaining systems, transportation systems, nuclear systems, or for any other mission-critical application in which the failure of the system could lead to critical injury or death. The software may not be fully tested and may contain bugs or errors; it may not be intended or suitable for commercial release. No regulatory approvals for the software have been obtained, and therefore software may not be certified for use in certain countries or environments. |
0 commit comments