[ESP32] DeepSleep until wake up by timer or button
Code for sending ESP32-family MCU into DeepSleep. And checking the waking up by the counter saved into RTC-memory between sleep and wakes up. Sub Process_Globals 'These global variables will be declared once when the application starts. 'Public variables can be accessed from all...

Button processing class: press, short click, long click, periodic event
The module for working with buttons (GND connected buttons now tested only). #Region Project Attributes #AutoFlushLogs: True #CheckArrayBounds: True #StackBufferSize: 600 #End Region Sub Process_Globals Public Serial1 As Serial End Sub Private Sub AppStart...

esp32 OLED display: Adafruit_SSD1306 library
Basing on https://github.com/adafruit/Adafruit_SSD1306 'module name: esp_oled 'I2C device found at address: 0x3C (60) 'https://github.com/adafruit/Adafruit_SSD1306 'v.0.16 Sub Process_Globals 'Setup I2C pins Dim pinSDAnumber As Byte = 5 'ignore GPIO5 (SDA), for ex. Dim...

INA3221: triple ampermeter & voltmeter
INA3221 can help with measuring up to 3 points: current and voltage. Default shunt resistors on INA3221 board are 0.1 Ohm (R100) and allow to measure up to ±1.638 Amper, so, i have added over them one more 0.1 Ohm resistors (to 1 and 3 channels only), and got the parallel resistance of 0.05 Ohm...

LED lighting PWM control
Power can be controlled by the PWM (pulse width modulation). The positive pulse width (duty) on this photo is 55% of 100% full frequency (10 kHz) period. So, 55% of power now is going to the controlled equipment. 0% means the power is off. We can try to control the microcontroller's LED: slowly...

ds18b20: 1Wire temperature sensor, B4R pin variable
Finally reworked code for the ds18b20 sensor, with the pin setting. 'Module name = "esp_ds18b20", (c) Peacemakerv 'v.2 'Libs: https://github.com/milesburton/Arduino-Temperature-Control-Library; https://github.com/PaulStoffregen/OneWire Sub Process_Globals 'These global variables will be...

Using these code snippets - i could develop an original torch testing board, actually, a headlamp project.
Just for fun.
The idea is that a LED torch should have just a single setting - the needed qty of working hours that are guaranteed for user, on the current available battery capacity.
So, any time you need just to decide how long you plan to use a torch: 3 hours of work in a dark floor, 7 hours of night fishing, or 48 hours if lost in a cave... With a weak light, but working for sure torch. And any time you can re-change the needed hours on the rest battery capacity.
Another idea is that any Li-battery can be used due to ... ampermeters will help to measure the real battery capacity and the real current consumption of the LED.
And basing on the needed Hours, currents, and counting the time - we can calculate the needed PWM parameters to control the LED consumption to get the maximal luminous flux during the time.
Today charging current, LED current are measured, OLED-display can show them, single button can switch it on or off, and setup the Hours by long pressing or pressing from a switched off state (deepsleep). Button and plugged USB charging cable are waking the esp32-c3 MCU up.
MCU calculates all (the needed current, battery capacity...) and makes PWM control of the LED driver that is a light dimmer.
It looks like i'm going to a realization



Last edited: