Audacity made quick work of converting a few .wav and .mp3 sound clips of Yoda’s voice to the preferred Ogg Vorbis / .ogg format. The preinstalled firmware on the VS1000D wants to find files in either .ogg or .wav format on the microSD card. The files should be named AUDIOxx.OGG or FILESxx.WAV (xx is 00 thru 31). Unfortunately, you need to start with 00 and not skip any slots.
I based my project on the Hardware Example Project from the Sparkfun Hook-up Guide. I removed the code for the servo and added code to prevent immediate re-triggering and to randomly select the file to play. The random selection is configured not to repeat a file until all have played – card deal style.
#include "SparkFun_PapaSoundie.h"
int motionStatusOld = LOW;
int motionStatus = LOW;
int sounds[] = {1, 2, 3, 4, 5};
int len = 5;
#define PIR_DOUT 9
PapaSoundie sfx = PapaSoundie();
void setup() {
Serial.begin(115200); // Serial is used to view Analog out
// Analog and digital pins should both be set as inputs (not actually necessary for Analog):
pinMode(PIR_DOUT, INPUT);
Serial.println("Getting ready");
sfx.begin();
}
void loop() {
int rnd;
int choice;
motionStatusOld = motionStatus;
motionStatus = digitalRead(PIR_DOUT);
if (motionStatus == HIGH && motionStatus != motionStatusOld) {
if (len > 1) {
rnd = random(len);
choice = sounds[rnd];
sounds[rnd] = sounds[len-1];
len = len - 1;
} else {
choice = sounds[0];
len = 5;
for ( int i = 0; i < len; ++i ){
sounds[i] = i+1;
}
}
Serial.println(choice);
sfx.playFileNumber(choice);
delay(1000);
}
}
The wiring is very basic – 5vdc and ground in on the VIN and GND pins, 3.3vdc and ground out to the sensor from the 3.3v and GND pins and the output of the sensor to pin D9.
Keep in mind the sensor does require a bit of time after power-up before being active. The LED on the sensor PCB will blink slowly during start-up. Once up and running the LED will indicate motion.
Sadly, I never posted any notes on the Sonoff products. Long ago I ordered a set of S31 outlets and B1 lamps. Both of which I reflashed with espurna. The notes on how to flash tasmota are helpful here, too. I found a quick tutorial on flashing with a Raspberry Pi in their docs. In todays world you might need to use pip3 instead of pip to install esptool. Tinkerman has posted lots of great details for the S31.
NEVER connect the S31 to mains power when flashing. For the S31 the connections to the Pi are very simple:
S31 Pin - Pi Pin
Vcc - #1 (3.3vdc) - do not connect yet
RX - #8 (TX)
TX - #10 (RX)
GND - #39 (Ground)
Once you have the wiring ready you can setup the Pi – make sure you have esptool installed. If not sudo pip3 install esptool should handle it. You can then use raspi-config -> InterfaceOptions -> Serial to say No to shell on the serial port and Yes to Serial hardware.
The S31 will enter loader mode if you hold down the button, connect Vcc and continue holding the button for 10 seconds. You are now ready to actually flash the device(I was using an older Pi 2):
If you are using a Pi 3 or 4 replace ttyAMA0 with ttyS0.
The bad news is the Sonoff B1 is no longer made and their replacement uses a different chip and is not re-flashable. For the B1 lamps I have MQTT control after reflashing is awesome. MQTT make the integration with Openhab super easy. If you happen to come across these at a good price then the flashing instructions at the Tasmota site are very helpful.