Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b3278b2
Move function to fix error message
bvmensvoort May 16, 2021
c0b1bfa
Fix min/max to be the same as the average after a while
bvmensvoort May 16, 2021
ceed5bb
Merge pull request #3 from bvmensvoort/two-changes
meekm May 16, 2021
3cc6738
Update README.md
meekm Aug 19, 2021
16abda0
Update README.md
meekm Aug 19, 2021
505b349
Update README.md
meekm Aug 19, 2021
6063803
Major upgrade
meekm Aug 19, 2021
0811c7b
display deveui on OLED
meekm Aug 19, 2021
ee37e5e
payloadformatter TTN V3
meekm Aug 19, 2021
126222a
Update README.md
meekm Aug 19, 2021
1204185
#define for microphone dependent offset
meekm Nov 3, 2021
0f715f8
set microphone dependent correction
meekm Nov 3, 2021
f2535aa
microphone dependent correction
meekm Nov 3, 2021
30c2bc6
Add files via upload
meekm Nov 3, 2021
d5cb75a
ICS43434 added
meekm Nov 3, 2021
1b62702
Update README.md
meekm Nov 3, 2021
6e745df
Add files via upload
meekm Nov 3, 2021
54aa115
changes version 3
meekm Nov 4, 2021
b8ecb3d
Test report
meekm Nov 4, 2021
9157813
moved
meekm Nov 4, 2021
ed067fd
Test report
meekm Nov 4, 2021
734af4e
Test Report
meekm Nov 4, 2021
9e5de07
Update README.md
meekm Nov 4, 2021
50a90c9
typo
meekm Nov 4, 2021
479d2eb
typo
meekm Nov 4, 2021
f4347cb
ttn ok, was one cycle behind
meekm Nov 8, 2021
8604ba7
Add a timer indicator to display when the next upload to LoRa will be
bvmensvoort Nov 27, 2021
d0f70d0
Merge pull request #5 from bvmensvoort/add-progressbar
meekm Nov 29, 2021
bc40e4e
Update README.md
meekm Mar 1, 2024
f5e86ed
Update README.md
meekm Mar 1, 2024
96ddd6b
Update README.md
meekm Mar 1, 2024
829d030
Update README.md
meekm Mar 18, 2024
707433b
Add files via upload
meekm Mar 18, 2024
16632f6
Add files via upload
meekm Mar 18, 2024
97cbed1
Update README.md
meekm Mar 18, 2024
5ec8971
Update release.txt
meekm Mar 18, 2024
e9bbd44
Delete src/lorasoundkit directory
meekm Mar 18, 2024
79e3bfd
Add files via upload
meekm Mar 18, 2024
e7ef25a
Add files via upload
meekm Mar 18, 2024
029b0d7
Update config.h
meekm Mar 18, 2024
481af01
Update README.md
meekm Mar 18, 2024
7fbdd7f
add test read and change oled
meekm Mar 21, 2024
15c3da7
add build flags
meekm Apr 14, 2024
b1fcf12
add build flags
meekm Apr 14, 2024
1908c03
Update main.cpp
meekm Nov 2, 2024
6206d3f
Update config.h
meekm Nov 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 122 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,118 +3,128 @@

* [General](#General)
* [Electronic components assembly](#electronic-components-assembly)
* [Board configuration](#Board-configuration)
* [Libraries](#Libraries)
* [Software Build](#Software-Build)
* [Config file](#Config-file)
* [Specification](#Specification)
* [Test Report](#Test-Report)
* [TTN message interface](#TTN-message-interface)
* [Example graphical output Sound Kit](#Example-graphical-output-Sound-Kit)
* [Last Updates](#Last-Updates)
* [To Do](#To-Do)

## General
This Soundkit is easy to build for a low cost price (ca. 40 euro) and is therefore very suitable to be used for citizen sensing.

This Soundkit sensor measures continuously audible sound by analyzing the data using FFT. The results are send each minute to the LoRa network. The sensor measures audible spectrum from 31.5 Hz to 8 kHz divided in 9 octaves. Also each minute the average, minimum and maximum levels are calculated for the 3 weighting curves dB(A), dB(C) and db(Z).
This sensor measures continuously audible sound by analyzing the data using FFT process. The measured results are send in a report at regular time intervals to the LoRaWan network, where it can be picked up for visualization.

<img src="images/soundkit.jpg" alt="Sound Kit Sparkfun board" width="200"/>
No adjustments are needed, because the sensor uses a digital MEMS microphone. which is factory calibrated. Furthermore it can easily be connected to the community network, viz. it is independent of a home or office network.

> Sound Kit Sparkfun board
The sensor make use of the powerful ESP32 processor, which is a dual core processor. One core handles continuously the processing of audio, while the other core handles the LoRaWan communication.

<img src="images/ttgo.jpg" alt="Sound Kit TTGO board" width="300"/>
The sensor measures audible spectrum from 31.5 Hz to 8 kHz divided in 9 octaves. Each regular time interval the average, minimum and maximum levels are calculated for the 3 weighting curves dB(A), dB(C) and db(Z).

> Sound Kit TTGO board

<img src="images/ttgo-oled.jpg" alt="Sound Kit TTGO OLED display" width="300"/>
<img src="images/ttgo.jpg" alt="Sound Kit TTGO board" width="400"/>

> Sound Kit TTGO OLED display

Several MEMS microphones can be used, the Soundkit is tested with SPH0645 and ICS43434.
The ICS43434 is adviced by Sensor.community, because the small headerboard can be assembled in a half inch pipe (13mm) fillled with resin in order to minimize audio resonance. Sound calibrators uses also this diameter size.

<img src="images/ics43434.jpg" alt="ICS43434 microphone" width="150"/>

> ICS43434 in pipe filled with resin

## Electronic components assembly
The software is based on ESP32 processor with Lora module. Two boards has been tested viz. Sparkfun LoRa board and TTGO LoRa board.
The software is based on TTGO LoRa T3 board, this board includes a ESP32 processor, a Lora RFM95 module, LoRa antenna.
The TTGO LoRa board does have an OLED display, and will display the average dB(A), dB(C) and dB(z) levels.

#### Components
* Sparkfun LoRa Gateway 1-channel ESP32 (used as Sensor), or TTGO LoRa32 V1
* I2S MEMS microphone SPH046 or I2S MEMS microphone NMP441
* antenna ¼ lambda, e.g a wire of 8.4 cm length or 868MHz Helical Antenna
* power adapter 5V, 0.5A

The table below shows the wiring between MEMS microphone (SPH0645 or NMP443) and the processor board (Sparkfun or TTGO):
| SPH0645 | NMP442 | |Sparkfun| TTGO |
| ------- | ------ |--|--------|-------|
| 3V | 3V | <--> | 3V | 3V |
| GND | GND | <--> | GND | GND|
| BCLK | SCK | <--> | GPIO18 | GPIO13 |
| DOUT | SD | <--> | GPIO19 | GPIO35 |
| LRCL | WS | <--> | GPIO23 | GPIO12 |
| | LR | GND | | |
| SEL | | not connected | | |

#### N.B.
For sound measurements lower then 30 dB, the supply to the MEMS microphone must be very clean. The 3V supplied by the Sparkfun ESP gives in my situation some rumble in low frequencies. It can be uncoupled by extra 100nf and 100 uF or a separate 3.3V stabilzer.

## Board configuration in PlatformIO

Choose your board in the platformio.ini file and change "default_envs" in one of the two lines below:
* default_envs = ttgo
* default_envs = sparkfun
Several MEMS microphones can be connected SPH0645 or ICS43434
The SPH0645 was slightly better in low frequencies. This is more important if you want to measure dB(C) and dB(Z) levels.
The ICS43434 is better in low levels, less noise.

## Board configuration in Arduino

Install ESP32 Arduino Core
Add the line in Arduino→preferences→Additional Boardsmanagers URL:
#### Components
- Processor board: LilyGO TTGO T3 LoRa32
- I2S Microphone: SPH0645 or ICS43434
- power adapter 5V, 0.5A

The table below shows the wiring between MEMS microphone (SPH0645 or ICS43434) and the processor board TTGO:
| SPH0645 | ICS43434| | TTGO T3|
| ------- | ------ | ------ |--------|
| 3V | 3V | <--> | 3V |
| GND | GND | <--> | GND |
| BCLK | SCK | <--> | GPIO00 |
| DOUT | SD | <--> | GPIO35 |
| LRCL | WS | <--> | GPIO12 |
| | LR | | GND |
| SEL | | |not connected| |

**Remark 1:**

The length of the wires between MEMS and TTGO-board should not exceed 15 cm and tie the wires close to each other, or use a 5 wire flat cable.

**Remark 2**

For sound measurements lower then 30 dB, the power to the MEMS microphone must be very clean. The 3.3V supplied to the MEMS can cause some rumble in low frequencies. It can be improved by placing an extra 100nf and 100 uF capacitor in parallel.

## Software Build
The sources are developed and compiled by Visual Code with the PlatformIO.
### Board configuration
The platformio.ini file is configured for the LilyGO TTGO T3 LoRa32 board.
```
https://dl.espressif.com/dl/package_esp32_index.json
[env:ttgo-lora32-v21]
```
Restart Arduino environment.

In the Arduino menu Tools→Boards, choose your board you want to use:
* Select TTGO LoRa32-OLED V1 board or
* Select Sparkfun LoRa Gateway 1-Channel board

The Sounkit sourcecode supports both boards. If Sparkfun Lora gateway is not vissible check the presence of the Sparkfun variant file, see instructions at https://learn.sparkfun.com/tutorials/sparkfun-lora-gateway-1-channel-hookup-guide/programming-the-esp32-with-arduino <br>


## Libraries

If you develop in PlatformIO, you can skip this section, libraries and macros are defined in platformio.ini and are installed automatically.
### Libraries
Libraries are installed automatically. The macros and libs are defined in platformio.ini. The following libraries are used in this project:
- espressif32@3.5.0
- mcci-catena/MCCI LoRaWAN LMIC library@ 4.1.1,
- adafruit/Adafruit GFX Library and adafruit/Adafruit SSD1306

#### LMIC
There are several LIMC LoRaWan libraries. I use the LMIC library from MCCI-Catena, because this one is currently best maintained.
Download the library from https://github.com/mcci-catena/arduino-lmic and put it in your [arduino-path]\libraries\

Take care that you change the frequency plan to Europe (if you are in Europe), because it is defaulted to the US. It can be changed in the file [arduino-path]\arduino-lmic-master\project_config\lmic_project_config.h
The frequency plan in MCCI LoRaWAN LMIC library is defaulted to US. In the platformio.ini it is overruled to Europe by the build flags:
```
#define CFG_eu868 1
```

#### Monochrome OLED library
For the TTGO board, download the libraries below and put them in your [Arduino-path]\libraries
```
https://github.com/adafruit/Adafruit_SSD1306
https://github.com/adafruit/Adafruit-GFX-Library
build_flags =
-D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS
-D CFG_eu868=1
-D CFG_sx1276_radio=1
```

#### Arduino FFT
I used the https://www.arduinolibraries.info/libraries/arduino-fft library.
The two files “arduinoFFT.h” and arduinoFFT.ccp” are already in your .ino main directory
The two files “arduinoFFT.h” and arduinoFFT.ccp” are already present in your source directory.

## Config file
In the config.h some parameters are defined.
#### Cycle count
The cycle count defines how often a measurement is sent to the thingsnetwork in msec.:
#### CycleTime
The cycle count defines how often a measurement is sent to the thingsnetwork in seconds:
```
#define CYCLETIME 60
```
For RIVM and sensor.community use 150

Set microphone dependent correction in dB
```
#define CYCLECOUNT 60000
#define MIC_OFFSET 0.0
```
for SPH0645 use -1.8</br>
for ICS43434 use 1.5</br>
otherwise use 0.0


#### LoRa TTN keys
The device address and keys have to be set to the ones generated in the TTN console. Login in the TTN console and add your device.
Choose activation mode OTAA and copy the APPEUI, DEVEUI and APPKEY keys into this config file:
TTN V2 stops at the end of 2021, so my advice is use the TTN console V3 to set your keys.
Register your device, choose 'manually' and MAC version 1.03.
Choose activation mode OTAA and copy the the (generated) APPEUI and APPKEY keys into this config file (config,h):
```
#define APPEUI "0000000000000000"
#define DEVEUI "0000000000000000"
#define APPKEY "00000000000000000000000000000000"
```
Note that unique DEVEUI is read from the TTGO ESP32 board id. The DEVEUI is displayed in the TTGO log during startup and is displayed on the OLED display. This value must be entered in the TTN console in the field DEVEUI.

## Specification

#### Sound Measuerment
* sample frequency MEMS microphone 22.628 khz
#### Sound Measurement
* Accuracy < 1 dB
* sample frequency MEMS microphone 22.628 kHz
* 18 bits per sample
* soundbuffer 2048 samples
* FFT bands in bins of 11 Hz (22628 / 2048)
Expand All @@ -123,18 +133,28 @@ Choose activation mode OTAA and copy the APPEUI, DEVEUI and APPKEY keys into thi
* spectrum 31.5Hz, 63Hz, 123Hz, 250Hz, 500 Hz, 1kHz, 2kHz, 4kHz and 8kHz
* average, maximum and minimum level

#### Interface
Every minute a message is composed from all measurements done in one minute, which contains the following values in dB.
## Test Report
The [test report can be found HERE](test/Test-report-TTGO-LoRa-Soundkit.pdf)
The test report desribes the tests of the Soundkit together with the Teensy4 soundsensor of the Sensor Community Germany.
Three test sets are used and the results are compared. The sets are:
- Soundkit LoRa TTGO with ICS43434
- Soundkit LoRa TTGO with SPH0645
- Soundsensor Teensy4 of the Sensor Community Germany.

The tests are executed with certified class 1 calibrator and soundlevel meter.

## TTN message interface
Every interval time (e.g. each 2 minutes) a message is composed from all measurements done in one interval, which contains the following values in dB.
* 9 spectrum levels for dB(A)
* 9 spectrum levels for dB(C)
* 9 spectrum levels for dB(Z)
* min, max, and average levels for dB(A)
* min, max, and average levels for dB(C)
* min, max, and average levels for dB(Z)

The message is send in a compressed binary format to TTN. The TTN payload decoder converts the messsage to a readable JSON message.
The message is send in a compressed binary format to TTN. The TTN payload decoder converts the message to a readable JSON message.

#### Example of a JSON message:
### Example of a JSON message:
```
"la": {
"avg": 44.2,
Expand Down Expand Up @@ -187,15 +207,34 @@ The message is send in a compressed binary format to TTN. The TTN payload decode
}
```
## Example graphical output Sound Kit
Below a graph of a sound measurement in my living room in dB(A).
Below a heatmap and graph of a sound measurement on my balcony in quiet residential area. The values shown are in dB(Z)
In this graph some remarkable items are vissible:
* blue line shows the max level of the belling comtoise clock each half hour
* visible noise of the dishing machine from 0:30 to 1:30
* noise of of the fridge the 125 Hz line
* incrementing outside traffic (63 Hz) at 7.00
* birds at 4khz at sunrise and sunset
* jet airplane at 250 Hz
* morning rush (traffic) at 63 Hz
Note that db(Z) levels shows a lot of noise in low frequencies, which is mostly not vissible in common db(A) measuremnts.

![alt Example output](images/grafana.png "Example output")

The green blocks shows the average spectrum levels.
This graph is made with Nodered, InfluxDb and Grafana.

## Last Updates
Changed 18-3-2024
- Sources adapted for LilyGO TTGO T3 LoRa32 board (10dB better radio performance)
- Sources adapted for VC PlatformIO (arduino IDE support not tested)
- During a TTN connect phase, the I2S MEMS driver is stopped, because it gives Rx radio interference
- The update of the OLED display is moved from the sound thread to the main thread.

Changed 15-8-2021
- MCCI Catena LoRa stack
- Worker loop changed (hang situation solved with TTN V3)
- OLED display added
- DEVEUI obtained from BoardID, (same SW for multiple sensors)
- use the TWO processor cores of ESP (one core for audio and one core for LoRa)
- DC offset MEMS compensated by moving average window
- payload compressed from 27 to 19 bytes
- test report added

## To Do
Advice for sensor housing and microphone placement.

Binary file modified images/grafana.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ics43434.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ics43434.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/ttgo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:ttgo-lora32-v21]
; platform = espressif32
platform = espressif32@3.5.0
board = ttgo-lora32-v21
framework = arduino
lib_deps =
mcci-catena/MCCI LoRaWAN LMIC library@^4.1.1
adafruit/Adafruit GFX Library
adafruit/Adafruit SSD1306

build_flags =
-D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS
-D CFG_eu868=1
-D CFG_sx1276_radio=1

monitor_speed = 115200

; change microcontroller
board_build.mcu = esp32

; change MCU frequency
board_build.f_cpu = 240000000L
16 changes: 16 additions & 0 deletions release.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
Changes in Version 4
- Sources adapted for LilyGO TTGO T3 LoRa32 board (10dB better radio performance)
- Sources adapted for VC PlatformIO (arduino IDE support not tested)
- During a TTN connect phase, the I2S MEMS driver is stopped, because it gives Rx radio interference
- The update of the OLED display is moved from the sound thread to the main thread.

Changes in Version 3
- Test report added
- MCCI Catena LoRa stack
- Worker loop changed (hang situation solved with TTN V3)
- OLED display added
- DEVEUI obtained from BoardID, (same SW for multiple sensors)
- use the TWO processor cores of ESP (one core for audio and one core for LoRa)
- DC offset MEMS compensated by moving average window
- payload compressed from 27 to 19 bytes

Changes in Version 2
- update Readme, TTGO added, pinning diagram for different configurations, interface changed
- config.h, contains all relevant parameters
Expand Down
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Define here your configuration
* - cycletime
* - LoRa TTN keys
* Marcel Meek, May 2020
*
*/

#ifndef _CONFIG_h /* Prevent loading library twice */
#define _CONFIG_h

// define in seconds, how often a message will be sent
#define CYCLETIME 120 // use 150 for RIVM and sensor.community project

// set microphone dependent correction in dB
// for SPH0645 define -1.8
// for ICS43434 define 1.5
// otherwise define 0.0
#define MIC_OFFSET 1.5

// specify here TTN keys

#define APPEUI "70B3D57ED003ED46"
#define APPKEY "53A4419ACE4EABF7BE9E5FB0B8A16F27"
// DEVEU is obtained from ESP board id

#endif
Loading