Don’t underestimate the… Doorbell#
A while ago I needed a doorbell, so I hacked one together using a Raspberry Pi I had laying around. It was a temporary fix while I got around to building an Arduino based replacement. A month or so ago the SD card croaked, so it was time.
I have a bunch of Wemos D1 Mini’s which would be the basis of my project and I also wanted it to play an actual sound file, so I’d ordered an I2S based Class-D Mono Amplifier from Adafruit.
I’d stumbled across a project using the same amplifier and they’d used a permissive license, so I didn’t actually end up needing to write much of my own code. I however spent a number of hours trying to figure out why the sound was extremely distorted, only to note that I’d hooked up LRC
to TX
instead of D4
.
Pin Connections#
Adafruit I2S DAC | ESP8266 | D1 Mini | Description |
---|---|---|---|
LRC | GPIO2/TX1 LRCK | D4 | Left/Right audio |
BCLK | GPIO15 BCLK | D8 | I2S Clock |
DIN | GPIO03/RX0 DATA | RX | I2S Data |
GAIN | n/c | n/c | 9 dB gain |
SD | n/c | n/c | Stereo average |
GND | GND | GND | Ground |
Vin | BAT | 5V | 3.3/5V power |
I’ve broken the Non Blocking WAV player into a separate library ESP8266-wavplay along with one for the Wav SPIFFS reader ESP8266-wavspiffs, which makes for a tiny amount of code to produce a functional doorbell.
#include "ESP8266Wavplay.h"
void setup()
{
Serial.begin(115200);
Serial.println("Booting");
// Set D3 as Switch pin
pinMode(D3, INPUT_PULLUP);
// Setup WavPlay
wavSetup();
showDir();
}
void loop() {
int state = digitalRead(D3);
if ( state == 0 && !wavPlaying()) {
wavStartPlaying("/doorbell.wav");
}
// WavPlay is non blocking, we need to call it to make
// sure it keeps playing until file end.
wavLoop();
}
You can find the project here and is already laid out as a PlatformIO project. If you’ve yet to come across PlatformIO and you do a lot with Arduino, it takes a lot of the pain out of things like managing dependencies, custom libraries, platform independent code etc.
Happy Hacking and may the force be with you.