Skip to content

Commit eee4e9b

Browse files
committed
add ESP32_LCD code
1 parent 3b24967 commit eee4e9b

File tree

950 files changed

+338365
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

950 files changed

+338365
-0
lines changed

ESP32_LCD/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch

ESP32_LCD/include/mydsipweb.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* IotWebConf01Minimal.ino -- IotWebConf is an ESP8266/ESP32
3+
* non blocking WiFi/AP web configuration library for Arduino.
4+
* https://github.com/prampec/IotWebConf
5+
*
6+
* Copyright (C) 2020 Balazs Kelemen <prampec+arduino@gmail.com>
7+
*
8+
* This software may be modified and distributed under the terms
9+
* of the MIT license. See the LICENSE file for details.
10+
*/
11+
12+
/**
13+
* Example: Minimal
14+
* Description:
15+
* This example will shows the bare minimum required for IotWebConf to start up.
16+
* After starting up the thing, please search for WiFi access points e.g. with
17+
* your phone. Use password provided in the code!
18+
* After connecting to the access point the root page will automatically appears.
19+
* We call this "captive portal".
20+
*
21+
* Please set a new password for the Thing (for the access point) as well as
22+
* the SSID and password of your local WiFi. You cannot move on without these steps.
23+
*
24+
* You have to leave the access point before to let the Thing continue operation
25+
* with connecting to configured WiFi.
26+
*
27+
* Note that you can find detailed debug information in the serial console depending
28+
* on the settings IOTWEBCONF_DEBUG_TO_SERIAL, IOTWEBCONF_DEBUG_PWD_TO_SERIAL set
29+
* in the IotWebConf.h .
30+
*/
31+
32+
#include <IotWebConf.h>
33+
#include <IotWebConfUsing.h> // This loads aliases for easier class names.
34+
#include <IotWebConfOptionalGroup.h>
35+
36+
// UpdateServer includes
37+
// For ESP32 IotWebConf provides a drop-in replacement for UpdateServer.
38+
# include <IotWebConfESP32HTTPUpdateServer.h>
39+
40+
// -- Initial name of the Thing. Used e.g. as SSID of the own Access Point.
41+
const char thingName[] = "WDP";
42+
43+
// -- Initial password to connect to the Thing, when it creates an own Access Point.
44+
const char wifiInitialApPassword[] = "12345678";
45+
46+
#define STRING_LEN 128
47+
#define NUMBER_LEN 32
48+
49+
// -- Configuration specific key. The value should be modified if config structure was changed.
50+
#define CONFIG_VERSION "1.01"
51+
52+
// -- When CONFIG_PIN is pulled to ground on startup, the Thing will use the initial
53+
// password to buld an AP. (E.g. in case of lost password)
54+
#define CONFIG_PIN 35
55+
56+
#define LED_BUILTIN (4) //led
57+
58+
// -- Status indicator pin.
59+
// First it will light up (kept LOW), on Wifi connection it will blink,
60+
// when connected to the Wifi it will turn off (kept HIGH).
61+
#define STATUS_PIN LED_BUILTIN
62+
63+
// -- Maximal length the input-range attributes can have.
64+
#define RANGE_ATTR_LENGTH 60
65+
66+
67+
// -- Method declarations.
68+
void handleRoot();
69+
// -- Callback methods.
70+
void wifiConnected();
71+
void configSaved();
72+
void parseBytes(const char* str, char sep, byte* bytes, int maxBytes, int base);
73+
74+
DNSServer dnsServer;
75+
WebServer server(80);
76+
HTTPUpdateServer httpUpdater;
77+
78+
byte ip[4];
79+
80+
81+
char MeterIp[STRING_LEN];
82+
char metertypeParamValue[NUMBER_LEN];
83+
84+
IotWebConf iotWebConf(thingName, &dnsServer, &server, wifiInitialApPassword, CONFIG_VERSION);
85+
86+
iotwebconf::OptionalParameterGroup MeterGroup = iotwebconf::OptionalParameterGroup("IAMMETER DSP", "IAMMETER", false);
87+
iotwebconf::TextParameter MeterIpParam = iotwebconf::TextParameter("IP address", "MeterIp", MeterIp, STRING_LEN, "192.168.1.6");
88+
iotwebconf::NumberParameter metertypeParam = iotwebconf::NumberParameter("MeterType 1:Single 3:Three", "MeterType", metertypeParamValue, NUMBER_LEN, "3", "1..3", "min='1' max='3' step='1'");
89+
90+
// -- An instance must be created from the class defined above.
91+
iotwebconf::OptionalGroupHtmlFormatProvider optionalGroupHtmlFormatProvider;

ESP32_LCD/include/mymodbus.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <ModbusIP_ESP8266.h>
2+
3+
typedef struct _MeterDatas
4+
{
5+
float Voltage_a ; //Voltage 0x0000 /100 V
6+
float Current_a; //Current 0x0001 /100 A
7+
float Power_a; //Power 0x0002 W
8+
double ImportEnergy_a; //ImportEnergy 0x0004 /800 kWh
9+
double ExportGrid_a; //ExportGrid 0x0006 /800 kWh
10+
float power_factor_a; //power_factor 0x0008 /1000
11+
//NC 0x0009
12+
13+
float Voltage_b ; //Voltage 0x000A /100 V
14+
float Current_b; //Current 0x000B /100 A
15+
float Power_b; //Power 0x000C W
16+
double ImportEnergy_b; //ImportEnergy 0x000E /800 kWh
17+
double ExportGrid_b; //ExportGrid 0x0010 /800 kWh
18+
float power_factor_b; //power_factor 0x0012 /1000
19+
//NC 0x0013
20+
21+
float Voltage_c ; //Voltage 0x0014 /100 V
22+
float Current_c; //Current 0x0015 /100 A
23+
float Power_c; //Power 0x0016 W
24+
double ImportEnergy_c; //ImportEnergy 0x0018 /800 kWh
25+
double ExportGrid_c; //ExportGrid 0x001A /800 kWh
26+
float power_factor_c; //power_factor 0x001C /1000
27+
//NC 0x001D
28+
29+
float Frequency; //Frequency 0x001E /100 Hz
30+
//NC 0x001F
31+
float Power_s; //Power sum 0x0020 W
32+
double ImportEnergy_s; //ImportEnergy sum 0x0022 /800 kWh
33+
double ExportGrid_s; //ExportGrid sum 0x0024 /800 kWh
34+
35+
float apparent_power_a; //apparent_power
36+
float reactive_power_a; //reactive_power
37+
38+
uint16_t address = 0x0048; //starting at register
39+
uint16_t quantitysingle = 10; //single phase meter
40+
uint16_t quantity = 38; //IAMMETER Three phase meter
41+
bool data_ok = false;
42+
43+
String jsondata;
44+
} MeterDatas;
45+
46+
MeterDatas wem3080t;
47+
uint16_t read_datas[38];
48+
49+
const int REG = 0; // Modbus Hreg Offset
50+
IPAddress remote(192, 168, 1, 6); // Address of Modbus Slave device
51+
const int LOOP_COUNT = 10;
52+
long refreshTime = 1000;
53+
54+
ModbusIP mb; //ModbusIP object

ESP32_LCD/include/touchPanel.h

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
#include <lvgl.h>
3+
#include <LovyanGFX.hpp>
4+
5+
class LGFX : public lgfx::LGFX_Device
6+
{
7+
lgfx::Panel_ILI9341 _panel_instance;
8+
lgfx::Bus_SPI _bus_instance; // SPI bus instance // SPIバスのインスタンス
9+
lgfx::Light_PWM _light_instance;
10+
lgfx::Touch_XPT2046 _touch_instance;
11+
12+
public:
13+
LGFX(void)
14+
{
15+
{ // バス制御の設定を行います。
16+
auto cfg = _bus_instance.config(); // Gets the structure for bus configuration. // バス設定用の構造体を取得します。
17+
cfg.spi_host = HSPI_HOST; // Select the SPI to use // 使用するSPIを選択 (VSPI_HOST or HSPI_HOST)
18+
cfg.spi_mode = 0; // Set SPI communication mode (0 ~ 3) // SPI通信モードを設定 (0 ~ 3)
19+
cfg.freq_write = 55000000; // SPI clock at the time of transmission (up to 80MHz, rounded to the value obtained by dividing 80MHz by an integer) // 送信時のSPIクロック (最大80MHz, 80MHzを整数で割った値に丸められます)
20+
cfg.freq_read = 20000000; // SPI clock when receiving // 受信時のSPIクロック
21+
cfg.spi_3wire = false; // Set true when receiving with MOSI pin // 受信をMOSIピンで行う場合はtrueを設定
22+
cfg.use_lock = true; // Set to true when using transaction lock // トランザクションロックを使用する場合はtrueを設定
23+
cfg.dma_channel = 1; // Set the DMA channel (1 or 2. 0=disable) // 使用するDMAチャンネルを設定 (0=DMA不使用)
24+
cfg.pin_sclk = 14; // Set SPI SCLK pin number // SPIのSCLKピン番号を設定
25+
cfg.pin_mosi = 13; // Set SPI MOSI pin number // SPIのMOSIピン番号を設定
26+
cfg.pin_miso = 12; // Set SPI MISO pin number (-1 = disable) // SPIのMISOピン番号を設定 (-1 = disable)
27+
cfg.pin_dc = 2; // Set SPI D / C pin number (-1 = disable) // SPIのD/Cピン番号を設定 (-1 = disable)
28+
29+
_bus_instance.config(cfg); // The set value is reflected on the bus. // 設定値をバスに反映します。
30+
_panel_instance.setBus(&_bus_instance); // Set the bus on the panel. // バスをパネルにセットします。
31+
}
32+
33+
{ // Set the display panel control.//表示パネル制御の設定を行います。
34+
auto cfg = _panel_instance.config(); // Gets the structure for display panel settings.// 表示パネル設定用の構造体を取得します。
35+
cfg.pin_cs = 15; // Pin number to which CS is connected (-1 = disable) // CSが接続されているピン番号 (-1 = disable)
36+
cfg.pin_rst = -1; // Pin number to which RST is connected (-1 = disable) // RSTが接続されているピン番号 (-1 = disable)
37+
cfg.pin_busy = -1; // Pin number to which BUSY is connected (-1 = disable) // BUSYが接続されているピン番号 (-1 = disable)
38+
cfg.memory_width = 240; // Maximum width supported by driver IC // ドライバICがサポートしている最大の幅
39+
cfg.memory_height = 320; // Maximum height supported by driver IC // ドライバICがサポートしている最大の高さ
40+
cfg.panel_width = 240; // Actually displayable width // 実際に表示可能な幅
41+
cfg.panel_height = 320; // Actually displayable height // 実際に表示可能な高さ
42+
cfg.offset_x = 0; // Amount of X-direction offset of the panel // パネルのX方向オフセット量
43+
cfg.offset_y = 0; // Amount of Y-direction offset of the panel // パネルのY方向オフセット量
44+
cfg.offset_rotation = 0; // Offset of values in the direction of rotation 0 ~ 7 (4 ~ 7 are upside down) // 回転方向の値のオフセット 0~7 (4~7は上下反転)
45+
cfg.dummy_read_pixel = 8; // Number of dummy read bits before pixel reading // ピクセル読出し前のダミーリードのビット数
46+
cfg.dummy_read_bits = 1; // Number of bits of dummy read before reading data other than pixels // ピクセル以外のデータ読出し前のダミーリードのビット数
47+
cfg.readable = true; // Set to true if data can be read // データ読出しが可能な場合 trueに設定
48+
cfg.invert = false; // Set to true if the light and darkness of the panel is reversed // パネルの明暗が反転してしまう場合 trueに設定
49+
cfg.rgb_order = false; // Set to true if the red and blue of the panel are swapped // パネルの赤と青が入れ替わってしまう場合 trueに設定
50+
cfg.dlen_16bit = false; // Set to true for panels that send data length in 16-bit units // データ長を16bit単位で送信するパネルの場合 trueに設定
51+
cfg.bus_shared = true; // If the bus is shared with the SD card, set to true (bus control is performed with drawJpgFile etc.) // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います)
52+
53+
_panel_instance.config(cfg);
54+
}
55+
56+
{ // Set the backlight control. (Delete if not needed // バックライト制御の設定を行います。(必要なければ削除)
57+
auto cfg = _light_instance.config(); // Gets the structure for the backlight setting. // バックライト設定用の構造体を取得します。
58+
59+
cfg.pin_bl = 21; // Pin number to which the backlight is connected // バックライトが接続されているピン番号
60+
cfg.invert = false; // True if you want to invert the brightness of the backlight // バックライトの輝度を反転させる場合 true
61+
cfg.freq = 44100; // Backlight PWM frequency // バックライトのPWM周波数
62+
cfg.pwm_channel = 7; // PWM channel number to use // 使用するPWMのチャンネル番号
63+
64+
_light_instance.config(cfg);
65+
_panel_instance.setLight(&_light_instance); // Set the backlight on the panel. // バックライトをパネルにセットします。
66+
}
67+
68+
{ // Set the touch screen control. (Delete if not needed) // タッチスクリーン制御の設定を行います。(必要なければ削除)
69+
auto cfg = _touch_instance.config();
70+
cfg.x_min = 0; // Minimum X value (raw value) obtained from touch screen // タッチスクリーンから得られる最小のX値(生の値)
71+
cfg.x_max = 239; // Maximum X value (raw value) obtained from the touch screen // タッチスクリーンから得られる最大のX値(生の値)
72+
cfg.y_min = 0; // Minimum Y value (raw value) obtained from touch screen // タッチスクリーンから得られる最小のY値(生の値)
73+
cfg.y_max = 319; // Maximum Y value (raw value) obtained from the touch screen // タッチスクリーンから得られる最大のY値(生の値)
74+
cfg.pin_int = 36; // Pin number to which INT is connected // INTが接続されているピン番号
75+
cfg.bus_shared = true; // Set to true if you are using the same bus as the screen // 画面と共通のバスを使用している場合 trueを設定
76+
cfg.offset_rotation = 0;// Adjustment when the display and touch orientation do not match Set with a value from 0 to 7 // 表示とタッチの向きのが一致しない場合の調整 0~7の値で設定
77+
cfg.spi_host = VSPI_HOST;// Select the SPI to use (HSPI_HOST or VSPI_HOST) // 使用するSPIを選択 (HSPI_HOST or VSPI_HOST)
78+
cfg.freq = 2500000; // Set SPI clock // SPIクロックを設定
79+
cfg.pin_sclk = 25; // Pin number to which SCLK is connected // SCLKが接続されているピン番号
80+
cfg.pin_mosi = 32; // Pin number to which MOSI is connected // MOSIが接続されているピン番号
81+
cfg.pin_miso = 39; // Pin number to which MISO is connected // MISOが接続されているピン番号
82+
cfg.pin_cs = 33; // Pin number to which CS is connected // CSが接続されているピン番号
83+
84+
_touch_instance.config(cfg);
85+
_panel_instance.setTouch(&_touch_instance); // Set the touch screen on the panel. // タッチスクリーンをパネルにセットします。
86+
}
87+
setPanel(&_panel_instance); // Set the panel to be used. // 使用するパネルをセットします。
88+
}
89+
};
90+
91+
92+
/*Change to your screen resolution*/
93+
static const uint32_t screenWidth = 320;
94+
static const uint32_t screenHeight = 240;
95+
static lv_disp_draw_buf_t draw_buf;
96+
static lv_color_t buf[ screenWidth * 10 ];
97+

0 commit comments

Comments
 (0)