We used a AZDelivery TP4056 Micro USB 5V as charger.
About the circuit, its quite simple:
Micro usb charger gets power via micro USB to charge the battery, after that we disconect the usb and see how long it run on battery. IN connections of charger are not connected because we use the micro USB on it. OUT + and ground are connected with LiPo Battery and the WEMOS + and GND.
At the Wemos we have also connected a AZDelivery 5 x 1,3 Zoll OLED Display via I2C.
And we used digital GPIO of the Wemos for up, left, right, top and A and B botton for our software.
The code itself is quite massive but only because of what we doing with our programm, but the sleep function works, and our tests states it only draws around 0,5mA if in DeepSleep for the estimated time of 1/2 minutes(now 2 minutes, first test with 1 minute).
WiFi or BT are not used. I show you here the code without the unrelevant and menue we programmed for the device
Oh and by the way, I forgot we also use a gpio for wakeup on botton. So you not need to wait 2 minutes if you want to wakeup the device and use it.
But the wakeup all 2 minutes is also required but we measure something with the device in that period of time even if the user dont press a key.
#include <U8g2lib.h>
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0); //https://github.com/olikraus/u8g2/wiki
#include <SPI.h>
#include <Wire.h>
#include <iostream>
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
#include <FS.h> // Für FLASH Speicherfunktion
#include "SPIFFS.h" // Für FLASH Speicherfunktion
RTC_DATA_ATTR int bootphase = 0;
RTC_DATA_ATTR int flashMemoryState=0;
int i1, i2, i3, i4, i5, i6, i7, i8, i9;
int L1, L2, L3, L4, L5, L6; // Loop variables
int up = 0, down = 0, left = 0, right = 0, buta = 0, butb = 0;
int uphold = 0, downhold = 0, righthold = 0, lefthold = 0;
int sleepTimeMilliSeconds;
int phase = 0;
void setup(void)
{
u8g2.begin();
Serial.begin(9600);// Für SerialComAusgabe
randomSeed(1567);
btStop(); // Bluetooth Stop
pinMode(40, INPUT_PULLUP); // up
pinMode(38, INPUT_PULLUP); // right
pinMode(37, INPUT_PULLUP); // down
pinMode(39, INPUT_PULLUP); // left
pinMode(12, INPUT_PULLUP); // A
pinMode(11, INPUT_PULLUP); // B
// Some wires which interruption will be tested:
pinMode(2, OUTPUT);
pinMode(3, INPUT_PULLUP); // wire 1
pinMode(4, OUTPUT);
pinMode(5, INPUT_PULLUP); // wire 2
pinMode(6, OUTPUT);
pinMode(7, INPUT_PULLUP); // wire 3
u8g2.setFont(u8g2_font_mozart_nbp_tf );
phase =50;
bool success = SPIFFS.begin(); // For flash data access
if (flashMemoryState==0) // at first start format memory
{
flashMemoryState=1;
SPIFFS.format(); // For flash data access
}
}
void loop(void)
{
u8g2.clearBuffer(); // clear the internal memory
////////////////////// READ INPUTS
i1=40; // Pin nummer UP
if (digitalRead(i1) == 1) up = 0;
if (digitalRead(i1) == 0) // if pressed
{
//Serial.println("UP");
if (up == 1) up = 2;
if (up == 0) up = 1;
}
i1=38; // Pin nummer RIGHT
if (digitalRead(i1) == 1) right = 0;
if (digitalRead(i1) == 0) // if pressed
{
//Serial.println("RIGHT");
if (right == 1) right = 2;
if (right == 0) right = 1;
}
i1=39; // Pin nummer LEFT
if (digitalRead(i1) == 1) left = 0;
if (digitalRead(i1) == 0) // if pressed
{
//Serial.println("LEFT");
if (left == 1) left = 2;
if (left == 0) left = 1;
}
i1=37; // Pin nummer DOWN
if (digitalRead(i1) == 1) down = 0;
if (digitalRead(i1) == 0) // if pressed
{
//Serial.println("DOWN");
if (down == 1) down = 2;
if (down == 0) down = 1;
}
i1=12; // Pin nummer BUT A
if (digitalRead(i1) == 1) buta = 0;
if (digitalRead(i1) == 0) // if pressed
{
//Serial.println("A");
if (buta == 1) buta = 2;
if (buta == 0) buta = 1;
}
i1=11; // Pin nummer BUT B
if (digitalRead(i1) == 1) butb = 0;
if (digitalRead(i1) == 0) // if pressed
{
//Serial.println("B");
if (butb == 1) butb = 2;
if (butb == 0) butb = 1;
}
if ( phase == 50 ) // Deep Sleep Mode - Waiting for wakeup
{
// Do something / testing and save results
/*
...
*/
if ( butb >= 1 ) // Enter menue by user
{
phase = 100;
}
else
{
// Deep-Sleep for a while ( after that time the Wemos will reboot
u8g2.setPowerSave(1); // Display save power
esp_sleep_enable_ext0_wakeup(GPIO_NUM_11, 0);
esp_sleep_enable_timer_wakeup(120 * uS_TO_S_FACTOR); // wakeup any 2 minutes
esp_deep_sleep_start();
}
}
if (phase == 1000 )
{
// USER INTERFACE... using the buttons and the oled as display, until go to STANDYB again
/*
...
*/
}
u8g2.sendBuffer(); // transfer internal memory to the display
} // End main loop