r/esp8266 • u/mrPotatoSixSeven • 4d ago
r/esp8266 • u/AutoModerator • Aug 24 '24
ESP Week - 34, 2024
Post your projects, questions, brags, and anything else relevant to ESP8266, ESP32, software, hardware, etc
All projects, ideas, answered questions, hacks, tweaks, and more located in our [ESP Week Archives](https://www.reddit.com/r/esp8266/wiki/esp-week_archives).
r/esp8266 • u/AutoModerator • 4d ago
ESP Week - 28, 2026
Post your projects, questions, brags, and anything else relevant to ESP8266, ESP32, software, hardware, etc
All projects, ideas, answered questions, hacks, tweaks, and more located in our [ESP Week Archives](https://www.reddit.com/r/esp8266/wiki/esp-week_archives).
Issues with and ads1115 on a nodemcu Lolin (esp8266). Code in Lua
Hello,
First the setup :

The objective of the setup is to measure intensity (with an SCT013) and voltage (with a ZMPT101B) using code adapted to Lua from EmonLib (https://github.com/openenergymonitor/EmonLib).
It did not work right ahead and I stripped the circuit to the above minimum to find the issue
Second, I am coding in Lua using builds built on https://nodemcu-build.com/. Therefore, I need to port the EmonLib to Lua on an nodemcu esp8266
Last, I do all my tests with the esp connected to the computer with a Visual Studio Code standard extension to access the serial port (read the serial messages and send instructions like uploads or node.restart())
Before showing the code, I have several very different problems:
- Before restarting the esp8266 (node.restart()) after a first startread, I need to disconnect:reconnect the ads1115 VDD from the ESP v3.3 to be able to find the ads1115. If I do not, it fails and reboots on the i2c.setup(...). I have absolutely no clue for why it happens
- If I leave the ALERT pin of the ads1115 floating, the i2c.setup also fails, always. If I connect it the D4 as in the sketch, it works, always, even if I never use it anywhere (I tried several other GPIO pins, it also works). Maybe it pulls it up ?!? but the datasheet seems to say it should work with the ALERT pin left floating
- I am using the lua ads1115 module and the ads.device.startread function (https://nodemcu.readthedocs.io/en/release/modules/ads1115/#ads1115devicestartread) with a while loop (with a timeout) following the startread call to make the read "synchronous" (because this is the way EmonLib is implemented), but the callback is never called before the end of the loop, thus preventing me from using a synchronous code similar to the readADC_SingleEnded function from EmonLib. I have clues (mentionned below) as to why it happens, but I would like the community insights since adaptation of the emonlib might be less literal than I'd hoped
Now the code (simplified for the sake of readability) :
local i2cSpeed = i2c.setup(0,
2, -- SDA
1, -- SCL
i2c.FAST) -- Speed. It works the same with i2c.SLOW
rtctime.set(0)
ads1115.reset()
print("Calling ads1115()")
local adc = ads1115.ads1115(0, ads1115.ADDR_GND)
print("ads1115() executed")
function getMillis()
local sec, usec = rtctime.get()
return sec * 1000 + usec / 1000
end
adc:setting(ads1115.GAIN_4_096V, ads1115.DR_128SPS, ads1115.SINGLE_0, ads1115.SINGLE_SHOT)
local millis = getMillis()
local v = nil
adc:startread(function(volt, volt_dec, adc, sign)
v = volt
print("Conversion happened. Delta="..tostring(getMillis() - millis)..", v="..tostring(v))
end)
-- Wait for conversion result to be available
-- if v is not nil, conversion has happened
-- else if time elapsed is less than 100ms, we loop, conversion will end soon
while (v == nil and getMillis() - millis < 100) do end
print("End. v="..tostring(v))
When I execute the previous code, the message "End. v=nil" is always printed before the callback message is, for instance "Conversion happened. Delta=134, v=1,61".
I tried several things like raising the timeout in the loop to insane values like 10s. The callback is always called 25 to 35ms after the message "End..."
I thought that the startread callback was called with an interrupt and thus I expected it to be able to be executed even if the code is executing the loop, but it does not. The same code seems to be working on an esp32, but I did not try because I do not have one, maybe it is because there are two cores ?!?
I tried to use a tmr.delay(10) inside the loop, thinking that it might allow a switch to the startread callback but it does not work. The tmr.delay(..) probably simply hides a timed out loop very similar to the one I already have.
Initially, the whole startread code (everything after the getMillis definition) was in a tmr ALARM_AUTO callback, but it works exactly the same in each alarm callback call, the startread callback is called only at the end of the alarm callback.
r/esp8266 • u/jmayer70 • 7d ago
issues with time (localtime, NTPclient)
After some weird timing issues i have done some research and learnt a lot about timezones, mktime and localtime. So far, so good. I still have a nagging issue, I don't really understand.
My assumption is that using NTPclient is synchronizing time from an NTP server. Even if it is somewhat off for the first seconds until full sync kicks in, the NTP synchronized time should align with the local time. Well, it seems it doesn't. Here is part of my sketch (inside loop()) to analyze:
// now check tasks based on second or minute
time(&now);
localtime_r(&now, &tm);
// store time values, print later
ss = tm.tm_sec;
ntp = timeClient.getSeconds();
// every 10sec
if (ss % 10 == 0) // every 10 sec
{
if (ss != 0) // 10,20,30,40,50s
{
Serial.print(ss);
Serial.print(" < time ntp > ");
Serial.println(ntp);
do_something();
}
else // full minute
{
do_otherstuff();
timeClient.forceUpdate(); // only every 60s
}
}
I would expect to have tm.tm_sec in sync with timeClient.getSeconds, at least after some time has passed. But it isn't, there is a constant difference of 1s which doesn't change, even after several minutes (up to one hour).
After more than 1 hour runtime:
20:39:40 millis=11090718
50 < time ntp > 49
both values still differ 1s. BTW, the ntp value is correct (compared to other time sources), the localtime value is 1s early. Since the 2 values are collected shotrly after another, there should be no runtime difference.
Anyone have a clue or a pointer, what could happen here? Why is there a 1s difference?
r/esp8266 • u/Particular_Ferret747 • 7d ago
Deep sleep wakeup for d1 mini clone help needed
Hello everybody...
I have a drawer full off D1 mini clones, some say ESP 12f on them others esp8266...
My project is a sonar oil tank level meter, which works great, but it drains my battery setup to fast, so i wanted to add some deep sleep and only measure every 2 hrs or so.
Either way...i have this code:
substitutions:
devicename: oiltankmeter
upper_devicename: Oil Tank Meter
deviceIP: 192.168.178.8
deviceGatew: 192.168.178.1
deviceSub: 255.255.255.0
deviceSSID1: 7390_iot
deviceSSID2: 7390AP
esphome:
name: ${devicename}
comment: ${upper_devicename}
esp8266:
board: d1_mini
packages:
base: !include common/base.yaml
wifi_scan: !include common/wifi_scan_arduino.yaml
api:
encryption:
key: "12345"
ota:
- platform: esphome
password: "12345"
deep_sleep:
id: deep_sleep_control
run_duration: 1min
sleep_duration: 1min
sensor:
- platform: adc
pin: A0
name: "Battery Voltage"
update_interval: 60s
filters:
- multiply: 7.16
unit_of_measurement: "V"
accuracy_decimals: 2
# -------------------------
# ULTRASONIC DISTANCE
# -------------------------
- platform: ultrasonic
trigger_pin: D1
echo_pin: D2
name: "Tank Distance Raw"
id: tank_distance_raw
update_interval: 5s
unit_of_measurement: "cm"
accuracy_decimals: 1
timeout: 4m
filters:
- multiply: 100
- lambda: |-
if (x < 5.0 || x > 350.0) {
return NAN;
}
return x;
# -------------------------
# TANK LEVEL
# -------------------------
- platform: template
name: "Tank Level Percent"
id: tank_level
unit_of_measurement: "%"
device_class: battery
accuracy_decimals: 1
update_interval: 5s
lambda: |-
const float EMPTY = 135.0;
const float FULL_DISTANCE = 25.0;
const float DEAD_ZONE = 20.0;
float d = id(tank_distance_raw).state;
if (isnan(d))
return NAN;
if (d < DEAD_ZONE)
d = DEAD_ZONE;
if (d > EMPTY)
d = EMPTY;
float pct = (EMPTY - d) / (EMPTY - FULL_DISTANCE) * 100.0;
if (pct > 100.0)
pct = 100.0;
if (pct < 0.0)
pct = 0.0;
return pct;
# -------------------------
# TANK VOLUME
# -------------------------
- platform: template
name: "Tank Volume Gallons"
id: tank_volume
unit_of_measurement: "gal"
accuracy_decimals: 0
update_interval: 5s
lambda: |-
float pct = id(tank_level).state;
if (isnan(pct))
return NAN;
return (pct / 100.0) * 275.0;
and for testing right now it is set to 1 min awake and 1 min sleeping...but also tried other time windows...longer and shorter...
D0 is directly wired to rst as needed, but i dont get this thing to wake up.
First i thought it could be the finiky usb chip or volatge regulator, so i went and powered it all direct via 3.3 volts...works great, no usb chip or power regulator involved...but still...3.2 volts constant on D0, no dip to 0 volts when it would be time to wake up.
The reset button itself works...it wakes up, goes through its time of awakens and falls asleep again...
Anyone having any secret sauce to this? Besides kissing it awake every time...
would it make a difference if i change the type on top away from d1_mini to a different chip type or the newer 12f whats not?
r/esp8266 • u/AutoModerator • 11d ago
ESP Week - 27, 2026
Post your projects, questions, brags, and anything else relevant to ESP8266, ESP32, software, hardware, etc
All projects, ideas, answered questions, hacks, tweaks, and more located in our [ESP Week Archives](https://www.reddit.com/r/esp8266/wiki/esp-week_archives).
r/esp8266 • u/Longz-85 • 10d ago
Does anyone have some cool project for my esp8266
I don't have any else, just this
r/esp8266 • u/AutoModerator • 18d ago
ESP Week - 26, 2026
Post your projects, questions, brags, and anything else relevant to ESP8266, ESP32, software, hardware, etc
All projects, ideas, answered questions, hacks, tweaks, and more located in our [ESP Week Archives](https://www.reddit.com/r/esp8266/wiki/esp-week_archives).
r/esp8266 • u/Faldiano_R • 20d ago
Need help with PID tuning on my custom ESP8266 + MPU6050 drone flight controller
Hi everyone, I am an electronics student currently building a custom quadcopter flight controller from scratch using an ESP8266 and MPU6050 (via I2C).
I am having a hard time getting the right PID values to stabilize the drone. It either oscillates too violently (shakes) or reacts too slowly and drifts away.
Here is my current setup and codebase:
Microcontroller: ESP8266 (programmed via Arduino IDE)
IMU: MPU6050
My GitHub Repo (for the full code): https://github.com/exstain/Custom-Drone-Flight-Controller
The Problem:
Whenever I increase the P (Proportional) gain, the drone shakes violently. But if I lower it, it doesn't correct itself fast enough. Since ESP8266 is a single-core processor, I am also worried that my loop time/cycle time might be affecting the PID calculations.
Any advice on how to properly tune the PID values or optimize the loop time for an ESP8266 drone would be highly appreciated. Thank you so much!
r/esp8266 • u/GianlucaBelgrado • 20d ago
SP8266 I2C bus freezing
Hi everyone, I'm currently using a DIY weather station with an ESP8266 WeMos D1. For some time now, I've been having problems with the I2C bus freezing, which forces me to reboot the device, cycle power, and reconnect power to get the sensors working again—sometimes once a day.
Following some advice, I added two 2.2 kΩ pull-up resistors between the 3.3 V pin and the SDA/SCL lines. This seems to have solved the freezing issue; for now, it seems to have been working stably for a full day!
However, I've noticed a side effect: the readings from my TSL2591 ambient light sensor have halved compared to what I was getting before.
I have two questions:
Are there better ways to resolve these I2C bus freezing issues, or is adding external pull-up resistors the standard solution for the ESP8266?
Should I simply compensate for the "offset" in my code, or does the variation in values indicate a deeper issue with the I2C signal integrity caused by the resistors?
Currently, the ESP8266 reads temperature with an SHT40, wind direction with an AS5600 and a 10-meter cable, and light with a TSL2591. This and the SHT40 use two 2-meter cables. (I should join the two sensors to use a single cable, but I hadn't thought of that before installing them.) I added a 470 microF capacitor just to be safe.
Any advice or suggestions on best practices would be greatly appreciated. Thanks!
r/esp8266 • u/Normal_Air_6282 • 22d ago
Switching off esp01s for 1 second
Всем привет! Я надеюсь, никто не против, что я пишу на своем родном языке (я могу читать на английском, но писать мне на нем сложно). К проблеме, я делаю мини проект на esp01s, которое будет позволять удаленно управлять моей дверью. Советуюсь с нейронкой и она выдает мне это. Есть ли тут хоть немного правды на практике (в теории я понимаю, что процессор за 1 секунду может выполнить около 35 миллионов операций), будет ли это как то влиять на энергосбережение? Очевидно, что дверь мне нужно открывать лишь пару раз в день, а не 24/7 пользоваться микроконтроллером
r/esp8266 • u/mysensors • 25d ago
Flashing custom ESP8266 firmware on the $10 GeekMagic Ultra to make a local API desktop monitor
Hey everyone,
I wanted a dedicated, cheap desk display to track my local Claude LLM/API usage limits, so I picked up a $10 GeekMagic Ultra. Instead of using the stock weather firmware, I wrote custom firmware using PlatformIO to turn it into a lightweight desktop dashboard.
How it works:
- Hardware: Contains an ESP8266 (running at 80 MHz with ~45KB available heap) driving a small TFT display.
- Firmware: Built with PlatformIO. It sets up a local Wi-Fi connection and listens for payload data. It supports OTA updates after the initial serial flash, which is great because I accidentally ripped my first screen's flex cable while testing!
- Software: A local Python script runs as a
systemduser service on my PC, polls my API token usage, formats the data, and pushes it directly to the ESP8266 via Wifi.
It’s completely open-source. Once my replacement screen arrives from AliExpress, I'll post a video of it in action. If you have one of these little screens lying around and want to repurpose it, the code is up on GitHub:
https://github.com/henrikekblad/codelight
Let me know if you’ve done any similar modifications to these GeekMagic units!
r/esp8266 • u/AutoModerator • 25d ago
ESP Week - 25, 2026
Post your projects, questions, brags, and anything else relevant to ESP8266, ESP32, software, hardware, etc
All projects, ideas, answered questions, hacks, tweaks, and more located in our [ESP Week Archives](https://www.reddit.com/r/esp8266/wiki/esp-week_archives).
r/esp8266 • u/Dangerous_Captain193 • 25d ago
ESP8266 D1 Mini Phantom Inputs
I have an ESP8266 D1 Mini connected to a PVC hall effect water sensor, and a reed switch brass water sensor, both are presenting the following issue but sporadically, not all are affected....
On the PVC there are three wires coming from the sensor, one going to 5V, one to G, and one to pin D2 (signal). On brass there are two wires coming from the sensor, one going to 3V3, one going to D2, and a resistor from D2 to G.
The issue I am seeing is that in some cases, there is an exorbitant amount of false inputs (I'll refer to these as pulses). There can be not a single drop of water running through these and yet I'll see hundreds to thousands of pulses coming through to the system in some cases (10 -20%).
The firmware checks for a low-high transition on the input pin within the loop, and that is what it's counting. I have an appropriate debounce in place.
What could be causing this? Why does it affect only some and not others? Is something within the environment causing this issue? Any help or advice would be much appreciated!
It's worth noting I have separate firmware running an ISR for pulse counting, and it has the exact same sporadic problem on an ESP32 board.
r/esp8266 • u/AutoModerator • Jun 20 '26
ESP Week - 24, 2026
Post your projects, questions, brags, and anything else relevant to ESP8266, ESP32, software, hardware, etc
All projects, ideas, answered questions, hacks, tweaks, and more located in our [ESP Week Archives](https://www.reddit.com/r/esp8266/wiki/esp-week_archives).
r/esp8266 • u/Nico30061950 • Jun 17 '26
No uploading to ESP8266 D1-Mini
After using an ESP8266 - D1-Mini for a Home Assistant project, I wanted to re-use the D1 Mini for another (non-HA) project. Using the Arduino IDE (1.8.19) and a USB cable, I was unable to get the upload done. The following error:
esptool.py v3.0
Serial port COM10
A fatal esptool.py error occurred: could not open port 'COM10': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)
Now, taking the same D1-Mini, doing the same upload using an external USB-to-UART bridge, it works fine. Back to the direct USB cable it still does not work.
I tried a second D1-Mini used with HA previously, same thing.
I tried different USB cables, same error.
I tried a different USB port, same thing.
I tried with a new D1-Mini and it uploads fine.
Anyone seen this before? Any suggestions?
r/esp8266 • u/AutoModerator • Jun 13 '26
ESP Week - 23, 2026
Post your projects, questions, brags, and anything else relevant to ESP8266, ESP32, software, hardware, etc
All projects, ideas, answered questions, hacks, tweaks, and more located in our [ESP Week Archives](https://www.reddit.com/r/esp8266/wiki/esp-week_archives).
r/esp8266 • u/Circuitnaut24 • Jun 11 '26
Help with auth using softAP and nonos-sdk
I can't seem to get authentication working in softAP mode with the latest (3.0.6) nonos-sdk (I know, I should use the RTOS but bear with me). I've tried everything I can think of and at one point thought it was the DHCP server. However it' definitely the authentication. Even if my password is longer than 8 chars anytime I connect a client I get the resulting log and the client behaves as if I put in the password incorrectly.
add if1
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
bcn 100
add 1
aid 1
station: 64:49:7d:91:82:32 join, AID = 1
station: 64:49:7d:91:82:32 leave, AID = 1
rm 1
add 1
aid 1
station: 64:49:7d:91:82:32 join, AID = 1
station: 64:49:7d:91:82:32 leave, AID = 1
The code is nothing special...
#ifndef USER_CONFIG_H
#define USER_CONFIG_H
// WiFi credentials (AP mode)
#define AP_SSID "ESP"
#define AP_PASSWORD "password"
#define AP_CHANNEL 1
#define AP_MAX_CONNECTIONS 4
#endif
void ICACHE_FLASH_ATTR wifi_init_softap(void) {
struct softap_config ap_config;
wifi_set_opmode(SOFTAP_MODE);
wifi_set_sleep_type(NONE_SLEEP_T);
wifi_set_event_handler_cb(wifi_event_handler_cb);
os_memset(&ap_config, 0, sizeof(ap_config));
os_strncpy((char *)ap_config.ssid, AP_SSID, sizeof(ap_config.ssid));
os_strncpy((char *)ap_config.password, AP_PASSWORD, sizeof(ap_config.password));
ap_config.ssid_len = os_strlen(AP_SSID);
ap_config.channel = AP_CHANNEL;
ap_config.authmode = AUTH_WPA_WPA2_PSK;
ap_config.max_connection = AP_MAX_CONNECTIONS;
ap_config.ssid_hidden = 0;
ap_config.beacon_interval = 100;
wifi_softap_set_config(&ap_config);
struct ip_info ip;
wifi_get_ip_info(SOFTAP_IF, &ip);
os_printf("Access Point \"%s\" started\n", AP_SSID);
os_printf("IP address:\t" IPSTR "\n", IP2STR(&ip.ip));
}
Btw when I change the `authmode` to AUTH_OPEN I can connect to the AP fine. It's once I add any other auth mode is when it doesn't work.
Has anyone come across this behavior and figured it out? I know the nonos sdk is deprecated, but I would like to make use of it anyway, and this seems like it should still work.
r/esp8266 • u/AutoModerator • Jun 06 '26
ESP Week - 22, 2026
Post your projects, questions, brags, and anything else relevant to ESP8266, ESP32, software, hardware, etc
All projects, ideas, answered questions, hacks, tweaks, and more located in our [ESP Week Archives](https://www.reddit.com/r/esp8266/wiki/esp-week_archives).
r/esp8266 • u/BruceTheLoon • Jun 05 '26
D1 mini ESP-12F failed GPIO pin
So I blew a GPIO pin (GPIO13 in ESPHome) into an always low mode and I'd like to avoid repeating that going forward.
Setup is a float switch in a manhole in normally open mode with one leg on the pin and the other to ground via a 5m cable. ESPHome has it as a Binary sensor with inverted true and pin configured for input true and pullup true. Powered from a 100mA 5V/500mA 12V dual output switched mode supply via the 5V and GND pins on the board.
Worked fine for a while, then started going on/off rapidly as if it was bouncing. Found the internal pullup seems to have failed and it worked again with an external pullup. Sometime after that, it repeated the rapid on/off thing and then got stuck with the binary sensor reporting On, which implies the pin is now grounded permanently. The float switch itself was open at the time.
I'm trying to figure out what cause of the failure could have been and how to prevent it in the future. Couple of questions for the ESP-12F electronics experts here.
- Is running the float switch to ground and not to 3.3V a bad idea? The pins available as safe to use seem to only have internal pullup. Should I have used 3.3V with an external pulldown instead.
- With a 5m cable running in a utility shaft and then through soil, could I be getting induced currents and damaged the pin that way?
- Is the power supply not suitable? My meter shows 5.01V. The board boots fine, connects to wifi and isn't driving any outputs. Current rating of the supply is 100mA according to the non-documentation. Should I ditch this supply and power via the USB port from a USB charger instead?
- Should I be running this switch in via an opto-isolator instead of directly onto the pin. I also want to integrate a tipping-bucket rain gauge which is a NO reed switch which pulses with each tip.
Any other advice? The D1 is cheap enough that I don't mind having messed one up figuring this out, but I don't want to send others to the grave as well.
r/esp8266 • u/Ok_Offer_2897 • Jun 05 '26
Purple halo effect
Project Overview
I am building a sensor hub, and right now I am focusing on developing the user interface.
Hardware
- Board: Waveshare ESP32-S3-Touch-LCD-4 (Rev 4.0)
- Development Environment: Arduino IDE
- Graphics Library: LVGL v8
The Problem
As you can see in the photos/video, the text has a very annoying effect around the edges. I've searched online, but this specific issue seems quite rare when using the Arduino IDE framework, and I couldn't find any working solutions. I strongly suspect it's an issue with how LVGL or the underlying display driver is configured.
I have also attached the ESP32 schematic for reference.
The program
```#include <Arduino.h>
#include <ESP_Panel_Library.h>
#include <lvgl.h>
#include "lvgl_port_v8.h"
#include <ESP_IOExpander_Library.h>
#include <demos/lv_demos.h>
#include <examples/lv_examples.h>
#include "HWCDC.h"
HWCDC USBSerial;
#define EXAMPLE_CHIP_NAME TCA95xx_8bit
#define EXAMPLE_I2C_NUM (1)
#define EXAMPLE_I2C_SDA_PIN (8)
#define EXAMPLE_I2C_SCL_PIN (9)
#define _EXAMPLE_CHIP_CLASS(name, ...) ESP_IOExpander_##name(__VA_ARGS__)
#define EXAMPLE_CHIP_CLASS(name, ...) _EXAMPLE_CHIP_CLASS(name, ##__VA_ARGS__)
ESP_IOExpander *expander = NULL;
/* ---------------------------------------------------------------- global variables ---------------------------------------------------------------- */
// sensor values
int Valo1=10;
int Valo2=12;
// number of sensors
int n=3;
// counter for building blocks
int p=0;
// arrays for data
//float Q1[n]; figure out how to make a variable-sized array
int Q1[3]={10,8,6};
int Q2[3]={20,16,12};
/*---------------------------------------------------------------- sensor indicators ---------------------------------------------------------------- */
// arrays for data text boxes
lv_obj_t*Val1[3]; // can be used to update the printed values
lv_obj_t*Val2[3];
void setup() {
expander = new EXAMPLE_CHIP_CLASS(EXAMPLE_CHIP_NAME,
(i2c_port_t)EXAMPLE_I2C_NUM, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000,
EXAMPLE_I2C_SCL_PIN, EXAMPLE_I2C_SDA_PIN);
expander->init();
esp_err_t initStatus = expander->begin();
if (initStatus == ESP_OK) {
USBSerial.println("Expander initialized successfully.");
} else {
expander = new EXAMPLE_CHIP_CLASS(EXAMPLE_CHIP_NAME,
(i2c_port_t)1, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000,
7, 15);
expander->init();
expander->begin();
}
pinMode(16, OUTPUT);
digitalWrite(16, LOW);
USBSerial.println("Original status:");
expander->printStatus();
expander->pinMode(5, OUTPUT);
expander->digitalWrite(5, HIGH);
expander->pinMode(0, OUTPUT);
expander->digitalWrite(0, LOW);
expander->pinMode(2, OUTPUT);
expander->digitalWrite(2, LOW);
expander->printStatus();
delay(200);
expander->digitalWrite(5, LOW);
expander->digitalWrite(2, HIGH);
expander->digitalWrite(0, HIGH);
expander->printStatus();
String title = "LVGL porting example";
USBSerial.begin(115200);
USBSerial.println(title + " start");
USBSerial.println("Initialize panel device");
ESP_Panel *panel = new ESP_Panel();
panel->init();
#if LVGL_PORT_AVOID_TEAR
// When avoid tearing function is enabled, configure the RGB bus according to the LVGL configuration
ESP_PanelBus_RGB *rgb_bus = static_cast<ESP_PanelBus_RGB \*>(panel->getLcd()->getBus());
rgb_bus->configRgbFrameBufferNumber(LVGL_PORT_DISP_BUFFER_NUM);
rgb_bus->configRgbBounceBufferSize(LVGL_PORT_RGB_BOUNCE_BUFFER_SIZE);
#endif
panel->begin();
USBSerial.println("Initialize LVGL");
lvgl_port_init(panel->getLcd(), panel->getTouch());
USBSerial.println("Create UI");
/* Lock the mutex due to the LVGL APIs are not thread-safe */
lvgl_port_lock(-1);
/* ---------------------------------------------------------------- header creation ---------------------------------------------------------------- */
lv_obj_t*rettangle= lv_obj_create(lv_scr_act());
lv_obj_set_size(rettangle, 480, 60);
lv_obj_align(rettangle, LV_ALIGN_TOP_LEFT, 0, 0);
lv_obj_set_style_radius(rettangle, 0, 0);
lv_obj_set_style_bg_color(rettangle, lv_color_make(0, 0, 0), 0); // black
lv_obj_set_style_border_width(rettangle, 3, 0);
lv_obj_set_style_border_color(rettangle, lv_color_make(180, 130, 0), 0);
lv_obj_set_style_border_side(rettangle, LV_BORDER_SIDE_BOTTOM, 0);
USBSerial.println("primo rettangolo");
// tokbo
lv_obj_t*TOKBO= lv_label_create(lv_scr_act());
lv_label_set_recolor(TOKBO, true);
lv_label_set_text(TOKBO, "#ffff55 TOKBO#"); // bright yellow
lv_obj_set_style_text_font(TOKBO, &lv_font_montserrat_16, 0);
lv_obj_align(TOKBO, LV_ALIGN_TOP_LEFT, 8, 22 );
// scan
lv_obj_t*label2= lv_label_create(lv_scr_act());
lv_label_set_recolor(label2, true);
lv_label_set_text(label2, "#ffff55 SCAN#"); // bright yellow
lv_obj_set_style_text_font(label2, &lv_font_montserrat_16, 0);
lv_obj_align(label2, LV_ALIGN_TOP_LEFT, 422, 22 );
/*---------------------------------------------------------------- sensor zone ---------------------------------------------------------------- */
while(p<n){
lv_obj_t*rettangle1= lv_obj_create(lv_scr_act());
lv_obj_set_size(rettangle1, 480, 120);
lv_obj_align(rettangle1, LV_ALIGN_TOP_LEFT, 0, 60+120*p); // alignment
lv_obj_set_style_radius(rettangle1, 0, 0);
lv_obj_set_style_bg_color(rettangle1, lv_color_make(235, 220, 165), 0); // canary yellow background
lv_obj_set_style_border_width(rettangle1, 3, 0);
lv_obj_set_style_border_color(rettangle1, lv_color_make(180, 130, 0), 0);
lv_obj_t*rettangle11= lv_obj_create(lv_scr_act());
lv_obj_set_size(rettangle11, 140, 120);
lv_obj_align(rettangle11, LV_ALIGN_TOP_LEFT, 0, 60+120*p); // alignment
lv_obj_set_style_radius(rettangle11, 0, 0);
lv_obj_set_style_bg_color(rettangle11, lv_color_make(235, 220, 165), 0); // canary yellow background
lv_obj_set_style_border_width(rettangle11, 3, 0);
lv_obj_set_style_border_color(rettangle11, lv_color_make(180, 130, 0), 0);
lv_obj_t*Sens1= lv_label_create(lv_scr_act()); // sensor name
lv_label_set_recolor(Sens1, true);
lv_obj_set_width(Sens1, 126); // increases text box width to center the sensor number
lv_label_set_text_fmt(Sens1, "Sensore \n %d", p);
lv_obj_set_style_text_color(Sens1, lv_color_make(0, 0, 0), 0);// black
lv_obj_set_style_text_align(Sens1, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_set_style_text_font(Sens1, &lv_font_montserrat_16, 0);
lv_obj_align(Sens1, LV_ALIGN_TOP_LEFT, 8, 100+120*p); // alignment
Val1[p] = lv_label_create(lv_scr_act()); // data 1
lv_label_set_recolor(Val1[p], true);
lv_label_set_text_fmt(Val1[p], "Valore \n %d", Q1[p]); // magnitude to be printed
lv_obj_set_style_text_color(Val1[p], lv_color_make(0, 0, 0), 0);// black
lv_obj_set_style_text_align(Val1[p], LV_TEXT_ALIGN_CENTER, 0);
lv_obj_set_style_text_font(Val1[p], &lv_font_montserrat_16, 0);
lv_obj_align(Val1[p], LV_ALIGN_TOP_LEFT, 422, 100+120*p ); // alignment
Val2[p]= lv_label_create(lv_scr_act()); // data 2
lv_label_set_recolor(Val2[p], true);
lv_label_set_text_fmt(Val2[p], "Sensore \n %d", Q2[p]); // magnitude to be printed
lv_obj_set_style_text_color(Val2[p], lv_color_make(0, 0, 0), 0);// black
lv_obj_set_style_text_align(Val2[p], LV_TEXT_ALIGN_CENTER, 0);
lv_obj_set_style_text_font(Val2[p], &lv_font_montserrat_16, 0);
lv_obj_align(Val2[p], LV_ALIGN_TOP_LEFT, 300, 100+120*p ); // alignment
lv_obj_t * indicatore1 = lv_obj_create(lv_scr_act());
lv_obj_set_size(indicatore1, 20, 20);
lv_obj_align(indicatore1, LV_ALIGN_TOP_LEFT, 10, 70+120*p); // alignment
lv_obj_set_style_radius(indicatore1, 50, 0);
lv_obj_set_style_bg_color(indicatore1, lv_color_make(128, 128, 128), 0); // grey
lv_obj_set_style_border_width(indicatore1, 0, 0);
// block count increment
p=p+1;
}
lvgl_port_unlock();
USBSerial.println(title + " end");
}
void loop() {
delay(1000);
// lv_label_set_text_fmt(Val2[0], "Valore \n %d", Q2[0]);
// Q2[0]=Q2[0]+5;
} ```