Skip to content

Commit 3748a85

Browse files
authored
Merge pull request #4 from UT2UH/SDP810
SDP810 infrasound mic example added
2 parents 2c2c5fe + 25d914b commit 3748a85

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SDP810
2+
3+
![SDP810](https://pschatzmann.github.io/arduino-audio-tools/doc/resources/ut2uh_sdp810_mic.jpeg)
4+
5+
The SDP810 is a 16 bit differential pressure sensor connected via I2C.
6+
7+
### Pins:
8+
9+
| SDP810 | ESP32
10+
|---------|---------------
11+
| SCL | SCL GPIO22
12+
| VDD | 3.3
13+
| GND | GND
14+
| SDA | SDA GPIO21
15+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Record output from SDP810 infrasonic microphone and send it to the Serial output
3+
*
4+
*/
5+
6+
#include <Wire.h>
7+
#include <SDPSensors.h> //https://github.com/UT2UH/SDP3x-Arduino/tree/SDP8x
8+
#include <AudioTools.h>
9+
10+
using namespace audio_tools;
11+
typedef int16_t sound_t; // sound will be represented as int16_t
12+
13+
const int sample_rate = 1024;
14+
const int buffer_size = 64;
15+
bool status;
16+
int16_t pressure;
17+
18+
SDP8XX Mic = SDP8XX(Address5, DiffPressure, Wire);
19+
TimerAlarmRepeating samplingTimer(1);
20+
NBuffer<int16_t> buffer(buffer_size, 3);
21+
22+
// callback to record the sound data into a buffer
23+
void writeSample(void *ptr) {
24+
status = Mic.readMeasurement(&pressure, NULL, NULL);
25+
sound_t sample = pressure;
26+
buffer.write(sample);
27+
}
28+
29+
// Arduino Setup
30+
void setup(void) {
31+
Serial.begin(115200);
32+
33+
// setup SDP810 infrasound microphone
34+
Wire.begin();
35+
Mic.begin();
36+
Mic.startContinuous(false);
37+
38+
// start the timer to record the data
39+
long waitUs = 1000000 / sample_rate;
40+
samplingTimer.start(writeSample, waitUs, TimerAlarmRepeating::US);
41+
42+
}
43+
44+
void printSampleRate() {
45+
static long next_time;
46+
if (millis()>next_time){
47+
next_time = next_time+1000;
48+
Serial.print("sample rate: ");
49+
Serial.println(buffer.sampleRate());
50+
}
51+
}
52+
53+
void printSamples() {
54+
static sound_t array[buffer_size][2];
55+
size_t len = buffer.readFrames(array);
56+
for (int j=0;j<len;j++){
57+
Serial.print(array[j][0]);
58+
Serial.print(" ");
59+
Serial.println(array[j][1]);
60+
}
61+
}
62+
63+
// Arduino loop - repeated processing
64+
void loop() {
65+
// copy sound data from samples to Serial
66+
printSamples();
67+
printSampleRate();
68+
}

src/AudioTools.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
#include "AudioTools/AudioI2S.h"
1717
#include "AudioTools/AnalogAudio.h"
1818
#include "AudioTools/AudioLogger.h"
19-
#include "AudioTools/Buffers.h"
19+
#include "AudioTools/TimerAlarmRepeating.h"
2020
#include "AudioTools/Streams.h"
2121
#include "AudioTools/AudioCopy.h"

0 commit comments

Comments
 (0)