Introduction: IOT123 - D1M BLOCK - SLOG Assembly
D1M BLOCKS add tactile cases, labels, polarity guides and breakouts for the popular Wemos D1 Mini SOC/Shields/Clones.
Like a lot of micro-controllers, the Wemos D1 Mini has software and hardware watchdogs. There are several (not unusual) conditions where neither of these are effective and the micro-controllers can effectively stall. Also the Wemos D1 Mini also has an energy saving mode called deep sleep, but it requires hardware pins to be setup (RST connected to D0) in order to work.
This shield (SLeep + watchdOG) provides an easy way to setup deep sleep or use an external hardware watchdog.
I did proof-of-concepts using a 555 timer, a 74HC4060 binary counter and a great ATTiny85 external long watchdog timer (David Zimmer). The layouts were too complex for the limited real estate, once the jumpers for the deep sleep were also included. So using a lot of Davids concepts (he pats dogs which I continued) I created an Attiny85 I2C variety of the watchdog.
The messages the Master (Wemos D1 Mini or other MCU) can send to the SLOG are Enable, Disable, Pat (notify that a reset is not needed), Address (set the I2C Address to EEPROM on the Attiny), Interval (set the interval seconds the watchdog must be patted in, to EEPROM on the Attiny), Get Address (gets the current I2C Address), and Get Interval (gets the current Interval seconds).
If the master does not Pat the watchdog within the required Interval, it causes a reset of the MCU.
Step 1: Material and Tools
There is now a full Bill of Materials and Sources list.
- The Wemos D1 Mini Protoboard shield and long pin female headers
- 3D printed Base and Lid, and labels for the D1M SLOG
- A set of D1M BLOCK - Install Jigs
- Hot glue gun and hot glue sticks
- Strong Cyanoachrylate Adhesive (preferably brush on)
- 1off ATTINY85 20PU
- 1 off 1N4001 diode
- 2 off 3P male headers
- 1 off 2P female header
- 2 off 2.54mm pitch Jumpers
- Hookup wire
- Soldering Iron and solder
Step 2: Uploading the Sketch to the Attiny85
An explanation of using an Arduino to upload onto the ATtiny85 is here.
Step 3: Soldering the Header Pins (using the PIN JIG)
There is a video above that runs through the solder process for the PIN JIG.
- Feed the header pins through bottom of the board (TX right-left) and into the solder jig.
- Press the pins down onto a hard flat surface.
- Press the board down firmly onto the jig.
- Solder the 4 corner pins.Reheat and re position board/pins if needed (board or pins not aligned or plumb).
- Solder the rest of the pins
Step 4: Soldering the Other Components
The 2P female header will be ~2mm too long. Carefully remove pins, file 1mm from both ends of plastic and replace pins. This component is to add a temporary LED to the SLOG whilst debugging (1 short blink for a Pat, 1 long blink for a reset). It is optional; if not including skip this and the wires that connect to it (the ground will till need to go to the ATTINY85).
- Place and solder ATTINY85 to shield, taking note of circle marker position
- Place and solder 2 off 3P male headers
- Place and solder 2P female header
- Place and solder 1N4001 diode taking note of polarity stripe
- Place ground hookup wire through holes and soldered to #4 & #13.
- Place hookup wire between D2 & #5 and solder
- Place hookup wire between #6 & #17 and solder
- Place hookup wire between D1 & #7 and solder
- Place hookup wire between #8 & #15 and solder
- Place hookup wire through 3V3 and solder on other side; solder other end to #16
- Place hookup wire through D0 and solder on other side; solder other end to #11
- Place hookup wire through RST and solder on other side; solder other end to #12
- Remove plastic collars from P3 male headers
- Cut P3 male headers pins down level with other pins.
Step 5: Gluing the Component to the Base
Not covered in the video, but recommended: put a large dob of hot glue in the empty base before quickly inserting board and aligning - this will create compression keys on either side of the board.
- With the base casing bottom surface ponting down, place the soldered assembly plastic header through the holes in the base; the (TX pin will be on side with the central groove).
- Place the hot glue jig under the base with the plastic headers placed through its grooves.
- Sit the hot glue jig on a firm flat surface and carefully push the PCB down until the plastic headers hit the surface; this should have the pins positioned correctly.
- When using the hot glue keep it away from the header pins and at least 2mm from where the lid will be positioned.
- Apply glue to all 4 corners of the PCB ensuring contact with the base walls; allow seepage to both sides of the PCB if possible.
- On some PCBs where the board ends close to the pins, dob a large amount of glue onto the base to the height of the PCB; when this cools apply more glue on the top of the PCB bridging to the lower glue.
Step 6: Gluing the Lid to the Base
- Ensure the pins are free of glue and the top 2mm of the base is free of hot glue.
- Pre-fit the lid (dry run) making sure no print artifacts are in the way.
- Take appropriate precautions when using the Cyanoachrylate adhesive.
- Apply Cyanoachrylate to the bottom corners of the lid ensuring coverage of the adjacent ridge.
- Quickly fit the lid to the base; clamping shut the corners if possible.
- After the lid is dry, manually bend each pin so it is central in the void if necessary.
Step 7: Adding the Adhesive Labels
- Apply pinout label on underside of base, with RST pin on side with groove.
- Apply identifier label on flat non-grooved side, with the pins void being the top of the label.
- Press labels down firmly, with a flat tool if needed.
Step 8: Testing the Deep Sleep
- Upload this included sketch onto the D1M WIFI BLOCK (or Wemos D1 Mini SOC)
- Disconnect USB/D1M WIFI from PC
- Connect D1M SLOG to D1M WIFI.
- Ensure both jumpers are set to the outer position
- Connect USB/D1M WIFI to PC
- Show console window for correct COM port.
- Ensure 115200 baud rate selected.
- Verify only 3 lines from Loop printed, then sleep for 10 seconds then wake, repeat...
Step 9: Testing the External Hardware Watchdog
This sketch depends on the Wire library; it should be installed with Arduino IDE.
- Upload this included sketch onto the D1M WIFI BLOCK (or Wemos D1 Mini SOC)
- Disconnect USB/D1M WIFI from PC
- Connect D1M SLOG to D1M WIFI.Ensure both jumpers are set to the inner position
- Connect a temporary blue LED (no resistor required) into the 2P Female header, with the +ve (long lead) to the outside of the casing. When the dog is patted a short blink occurs; on reboot a long blink occurs.
- Connect USB/D1M WIFI to PC
- Show console window for correct COM port.
- Ensure 9600 baud rate selected.
- Verify only the dog is patted 3 times, then the D1M WIFI BLOCK reboots.
Step 10: Configuring the Shield From Within Your Sketch
The bare minimum to use the external hardware watchdog in your sketch:
- Setup the D1M WIFI BLOCK as a I2C master (line #4)
- Write to the slave (D1M SLOG using its I2C Address line #8) within a repetitive time frame (defaults to 20 seconds), sending a char 'P' (line #9) and any byte value (line #10).
If the MCU does not or can't pat the dog, it bites the master (resets).
Step 11: Configuring Your Shield Via Console Input
The actions that can be configured via I2C are:
- Enable the watchdog (it looks for pats, and can bite if no pat in time)
cmd: 'E'
param: 0 - Disable (no patting required)
cmd: 'D'
param: 0 - Pat (broadcasts the master is alive
cmd: 'P'
param: 0 - Get the slave I2C Address (needs to know this anyhow - may be useful when many actions have taken place)
cmd: 'G'
param: 0 - Get the Interval is seconds
cmd: 'G'
param: 1 - Set the I2C Address
cmd: 'A'
param: valid (verified) values 8 to 25 - Set the Interval
cmd: 'I'
param: valid values 0 to 255
To send these commands to the D1M SLOG:
- Upload this included sketch onto the D1M WIFI BLOCK (or Wemos D1 Mini SOC) ensuring the slave address is correct.
- Disconnect USB/D1M WIFI from PC
- Connect D1M SLOG to D1M WIFI.
- Ensure both jumpers are set to the inner position
- Connect a temporary blue LED (no resistor required) into the 2P Female header, with the +ve (long lead) to the outside of the casing.
- When the dog is patted a short blink occurs; on reboot a long blink occurs.
- Connect USB/D1M WIFI to PC
- Show console window for correct COM port.Ensure 9600 baud rate selected.
- Set line ending to newline (lower RHS combo box)
- Input the above commands/paras followed by an
- If the param is 0 (zero) it can be omitted, so valid inputs are E (may cause resets), D, P, G0, G1, A9, I40
- Only I2C Slave Address and Interval ar persisted to EEPROM.
Step 12: Next Steps
- Program your D1M BLOCK with D1M BLOCKLY
- Check out Thingiverse
- Ask a question at the ESP8266 Community Forum