Category Archives: Tech

Mini DF MP3 player with MQTT control

Resistor is 1K, speaker is 4 ohm

I’ve got the DFPlayer with the GD3200B instead of the better YX5200, but it works.

As part of my game, so MQTT controlled.

First sound is low in volume.

Code

I’m using Soft Serial

// based on code from: 
// https://github.com/Makuna/DFMiniMp3/blob/master/examples/PlayMp3/PlayMp3.ino
// above example has no wifi/mqtt and is missing the SoftSerial include line
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <WiFiClient.h>
#include <DFMiniMp3.h>
#include "SoftwareSerial.h"
#include <Ethernet.h>

#define wifi_ssid "SSID"
#define wifi_password "SSIDPASS"
#define mqtt_server "MQTTSERVER"
#define mqtt_port 1883

WiFiClient espClient;
EthernetClient ethClient;
PubSubClient mqtt(espClient);

class Mp3Notify; 

SoftwareSerial secondarySerial(D6, D5); // RX, TX
typedef DFMiniMp3<SoftwareSerial, Mp3Notify> DfMp3;
DfMp3 dfmp3(secondarySerial);

class Mp3Notify
{
public:
  static void PrintlnSourceAction(DfMp3_PlaySources source, const char* action)
  {
    if (source & DfMp3_PlaySources_Sd) 
    {
        Serial.print("SD Card, ");
    }
    if (source & DfMp3_PlaySources_Usb) 
    {
        Serial.print("USB Disk, ");
    }
    if (source & DfMp3_PlaySources_Flash) 
    {
        Serial.print("Flash, ");
    }
    Serial.println(action);
  }
  static void OnError([[maybe_unused]] DfMp3& mp3, uint16_t errorCode)
  {
    // see DfMp3_Error for code meaning
    Serial.println();
    Serial.print("Com Error ");
    Serial.println(errorCode);
  }
  static void OnPlayFinished([[maybe_unused]] DfMp3& mp3, [[maybe_unused]] DfMp3_PlaySources source, uint16_t track)
  {
    Serial.print("Play finished for #");
    Serial.println(track);  

    // start next track
    track += 1;
    // this example will just start back over with 1 after track 3
    if (track > 3) 
    {
      track = 1;
    }
    dfmp3.playMp3FolderTrack(track);  // sd:/mp3/0001.mp3, sd:/mp3/0002.mp3, sd:/mp3/0003.mp3
  }
  static void OnPlaySourceOnline([[maybe_unused]] DfMp3& mp3, DfMp3_PlaySources source)
  {
    PrintlnSourceAction(source, "online");
  }
  static void OnPlaySourceInserted([[maybe_unused]] DfMp3& mp3, DfMp3_PlaySources source)
  {
    PrintlnSourceAction(source, "inserted");
  }
  static void OnPlaySourceRemoved([[maybe_unused]] DfMp3& mp3, DfMp3_PlaySources source)
  {
    PrintlnSourceAction(source, "removed");
  }
};

void setup_wifi() {
  delay(10);
  WiFi.mode(WIFI_STA);
  WiFi.begin(wifi_ssid, wifi_password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
}

void setup() 
{
  setup_wifi();
  mqtt.setServer(mqtt_server, mqtt_port);
  mqtt.setCallback(callback);
  Serial.begin(115200);
  Serial.println("initializing...");

  WiFiClient espClient;
  PubSubClient mqtt(espClient);

  mqtt.setClient(espClient);
  mqtt.setServer(mqtt_server, 1883);
    
  mqtt.setCallback(callback);
  mqtt.subscribe("escape/soundin");
  
  dfmp3.begin();

  uint16_t volume = dfmp3.getVolume();
  Serial.print("volume ");
  Serial.println(volume);
  dfmp3.setVolume(24);
  
  uint16_t count = dfmp3.getTotalTrackCount(DfMp3_PlaySource_Sd);
  Serial.print("files ");
  Serial.println(count);
  
  Serial.println("starting...");

  // start the first track playing
  // dfmp3.playMp3FolderTrack(1);  // sd:/mp3/0001.mp3
}

void reconnect() {
  // Loop until we're reconnected
  while (!mqtt.connected()) {
    // Create a random client ID
    String clientId = "ESP8266Client-";
    clientId += String(random(0xffff), HEX);
    // Attempt to connect
    if (mqtt.connect(clientId.c_str())) {
      // Once connected, publish an announcement...
      mqtt.publish("escape", "sound connected");
      // ... and resubscribe
      mqtt.subscribe("escape/soundin");
    } else {
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}


void callback(char* topic, byte* payload, unsigned int length) {
    //  digitalWrite(led, HIGH);

    String topicStr = topic;
      byte value = atoi((char*)payload);
dfmp3.playMp3FolderTrack(value);  // sd:/mp3/0001.mp3
  Serial.println(value);
}

void waitMilliseconds(uint16_t msWait)
{
  uint32_t start = millis();

  while ((millis() - start) < msWait)
  {
    dfmp3.loop(); 
    delay(1);
  }
}

void loop() 
{
  
  if (!mqtt.connected()) {
    reconnect();
  }
    mqtt.loop();
  waitMilliseconds(100);
}

Shelly Devices

I love shellies, easy to implement and hacker friendly.

MQTT out of the box.
Curl in and out – you can switch it on/off using curl, but it can send a http command also.
I’ve used this with Domoticz and Home Assistant.
It has a webinterface, with timers, and there is also a client for Android/Iphone
You’ve got some own gpio pins to your disposal and the unit is flash-able!

curl -X POST https://shellydevice/device/relay/control -d "channel=IDHERE&turn=on&id=ID&auth_key=AUTH"

The device is not isolated from the mains. To flash it, the mains must be disconnected.

SHELLY 1

I use this for simple on/off switches around the house.
Using it with a physical switch and MQTT (Nodered)

SHELLY 2 PM

Same as above but this one has a build in power meter

SHELLY DIMMER

Generic dimmer

Dimmer with low voltage rotary encoder!
https://www.instructables.com/Shelly-Dimmer-Wall-Switch-With-Rotary-Knob-and-Hom/

SHELLY RGBW2

A RGBW / 4 Channel controller
You can connect RGB strips, but also dimmable white strips in 4 channels. 12V or 24V.
NOTE! : There is a common 12V connection, and GND will be controlled!

SHELLY PLUG S

I love these small wall plugs, i’ve used these also to find power consuming devices around the house.

For example, i made a nodered flow, to see if the washing machines are running or not.

SHELLY BUTTON

This became my all purpose alarm thinghy

SHELLY DOORSENSOR

A door sensor WITH temperature and light sensor build in!

Home Assistant example

SHELLY WATER SENSOR

This one lays below our washing machine

SHELLY SMOKE ALARM

(Preordered)

SHELLY PM4

A four channel power measure/switch for your fuse box


GENERIC SHELLY STUFF
A smart doorbell schematic i found

https://www.thingiverse.com/thing:5756154
Very nice .. printable cases for your shellies!

At last .. my own lasercutter

I did a lot of lasercutting at Fablab Utrecht, but they stopped a few years ago, and I moved to Hilversum.

I loved making this at this Fablab.

  • Lasercutting : Boxes, A cryptex of my own design, Xmas ornaments, Shogi game, things in acrylic, Rubber stamps
  • Cutting plotter ( Nae Bother Case logo’s )
  • CNC Machines
  • Vacuum form

Then i bought a mini engraver, which you can attach to your 3D printer.

But I really wanted a cutter, so there it is … the Sculptfun S9

First test. crafting paper. No burning and a really high resolution!

This laser module has a new optical design, so it can cut wood as thick as 10+ mm.
It can engrave metal, cut non-transparant acrylic, leather and more.

Software:

I’m using Inkscape, with the lasercutter tool plugin from Jtech.
https://jtechphotonics.com/

I’ve also tested with LaserGRBL, which can be run under linux using Wine.

I’m trail testing LightBurn. (Native Linux App)

I will post my findings and test on this post.

UPDATE: 20230221

A stone slate engraved
Speed3000 mm/s
Laser Power100%
Lines per mm10

UPDATE: 20230306

Calibrate your machine! .. But NOT as found on YouTube using a 10x10mm or 1 inch by 1 inch. square.
As big as you can. This is far more precise!

My list of settings (Work in progress)

I have to check mm/s versus mm/minute!

MaterialSpeedPowerLines/mmPasses
Slate (engrave)
(using lasergrbl)
3000 mm/s100%101
3mm Plywood (cut)20 mm/s90%x8?
Craftpaper1500mm/s70%x1
Cardboard10 mm/s100%x4
Leather
Cork (6mm)

Connect the wires puzzle

As part of my internet based escape room.

I took the idea from the Keep-talking-and-nobody-explodes game.

When starting up, is gets the configuration from a Mqtt Topic.
So i can create a different setup over the internet.

The result is also send back via MQTT.

(example play, all players are on different locations)

  • Player 1 figures out the wires.
  • Player 2 connects the wires.
  • Player 3 sees the result (correct or not) and next puzzle opens up for Player 3

I used a wire with a line. Multiple colors for jacks and sockets.
It’s also possible to connect a jack to a jack.
Loads of possibilities.

Todo:

Wifi and Mqtt part
Debounce software or hardware

Prints from China

A few weeks ago i designed a print using Kicad.

Today they have arrived!

Now I have to wait a little more .. A 74HTC166 and a straightup RCA connector.

I the past, a long time ago i made my own single side pcb’s using acids.
A messy job, often gone wrong.

Old skool example https://www.youtube.com/watch?v=_PwCp3A3RSk

Or https://www.circuitsonline.net/artikelen/view/1/print

Not much new

Last days .. welllll doing al kinds of stuff.

Composite video print designed and ordered from china.

Changed some vlans in my network.
I need to think of a way to extract/migrate domoticz 433 info into a new instance.
For example .. i’ve got some instances in my device list which are only being controlled by domoticz, there is no remote i can reuse.

Tried welding again, because i could not do it for a long time, i noticed i have to practice again after 2 years.
(I’ve got a dedicated power outlet outside now .. 🙂

Last 8mm films work done. (Converted all of my dad’s old 8mm reels)

Designed a hidden remote cabinet, holding remotes out of sight for the occasions when automation doesn’t work.

Designed also a wooden wall with hidden cabinets in our bedroom.

Repaired a Gardena Leafblower .. again!

Android tips

Using hotspot?
Want to see which devices are connected?
https://www.henriaanstoot.nl/2022/09/16/android-and-devices-in-your-neighbourhood/

Another JuiceSSH tip .. connection type mosh, will open a ssh session using udp to your server.
( If you got mosh installed on your server )
A disconnect or bad connections will not break your ssh session, it just resumes.
Even when you are changing from network, and have a different IP.

Your android as Webcam (in OBS)

Install scrcpy on your linux machine, and opencamera on your android.
If you got adb installed plug in your android and start scrcpy.
You should be seening your android screen on your linux workstation.
When you openup the stock version of your camera you get a overlay of the gui, which you probably can’t disable/remove. There where’s opencamera comes in.
https://play.google.com/store/apps/details?id=net.sourceforge.opencamera

Settings > On screen GUI > Immersive Mode and select Hide everything
You probably want to set the aspect ratio to 19.5:9 so the whole screen will be used.

There is a lot more you can do with scrcpy !
https://github.com/Genymobile/scrcpy
https://www.henriaanstoot.nl/2022/02/02/android-oculus-quest-screen-record/

Keyboard leds sound reactive

How much fun …. just wanted to share my recording

I’ve written some tools for my keyboard like a mqtt client, but this is someone else’s. But it gave me some ideas …

My keyboard is a Razer BlackWidow V3

G1200 Microscope

Another good suggestion by Bigred.

We are all getting older and electronics smaller. It’s hard to see if your soldering blobs are okay!
Those blobs can reflect the light in a way that it’s not visible anymore to check them.

So i took Bigreds advice, and bought a G1200 Microscope.
It’s a cheap but helpfull little gadget.

  • 1-1200 times zoom
  • 7inch screen (720p)
  • SDcard
  • Lipo battery
  • Recording on micro sdcard in 12 mega pixels pictures and 1080P Video.
    (even got a timer)
  • Focus button, and extra lights (There is a light source in de camera head, which can be adjusted by a knob)
  • When connecting to your pc, you get 3 options
    • PC Camera ( … so you can record using your pc with for example OBS)
    • Mass Storage, to read the SDCARD
    • Rec_mode ?!? – No idea yet

Below some examples:

Picture example
Video example

SDCard Access:

Access to the sdcard is a little hard. Connecting via Mass Storage is a solution. But i’ve put a little piece of tape to get the card in or out of the slot.

You can view the recordings on the Microscope itself. So i was wondering, can it play any other movie files?

I placed different MOV files on the sdcard, but the microscope skipped the ones i places on the sdcard myself.

I started to look at the metadata, and saw a Codec ID
“qt 2016.04.21 (qt )”

 mediainfo VID_001.MOV
General
Complete name                            : VID_001.MOV
Format                                   : MPEG-4
Format profile                           : QuickTime
Codec ID                                 : qt   2016.04.21 (qt  )
File size                                : 551 MiB
Duration                                 : 12s 0ms
Overall bit rate                         : 385 Mbps
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L4.1
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 1 frame
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 12s 0ms
Source duration                          : 12s 360ms
Bit rate                                 : 14.5 Mbps
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.280
Stream size                              : 20.8 MiB (4%)
Source stream size                       : 21.3 MiB (4%)
Language                                 : 33
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00
mdhd_Duration                            : 12000

Audio
ID                                       : 2
Format                                   : PCM
Format settings, Endianness              : Little
Format settings, Sign                    : Signed
Codec ID                                 : sowt
Duration                                 : 12s 0ms
Source duration                          : 12s 288ms
Bit rate mode                            : Constant
Bit rate                                 : 128 Kbps
Channel(s)                               : 1 channel
Channel positions                        : Front: C
Sampling rate                            : 8 000 Hz
Bit depth                                : 16 bits
Stream size                              : 188 KiB (0%)
Source stream size                       : 192 KiB (0%)
Language                                 : 33
Default                                  : Yes
Alternate group                          : 1
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

Tried to change this with ffmpeg, but it would not change the way i want.

ffmpeg -i VID_002.MOV -c copy -map 0 -brand 'qt   2016.04.21 (qt  )' VID_007.MOV

mediainfo VID_007.MOV
General
Complete name                            : VID_007.MOV
Format                                   : MPEG-4
Format profile                           : QuickTime
Codec ID                                 : qt   0000.02 (qt  )  <--------------- nope

Header of the movie clip
maybe i have to look into this … later

00000000  00 00 00 14 66 74 79 70  71 74 20 20 20 16 04 21  |....ftypqt   ..!|
00000010  71 74 20 20 00 00 00 08  77 69 64 65 01 57 c7 e4  |qt  ....wide.W..|
00000020  6d 64 61 74 00 00 01 d8  0c 00 00 00 4a 4b 4c 4a  |mdat........JKLJ|
00000030  19 00 00 00 80 07 00 00  38 04 00 00 01 00 00 00  |........8.......|
00000040  10 00 00 00 40 1f 00 00  00 20 00 00 01 00 00 00  |....@.... ......|
00000050  0c 00 00 00 73 6f 77 74  00 02 00 00 00 00 00 00  |....sowt........|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|