Skip to content

Commit b1a20b6

Browse files
author
Sebastian
committed
Add LilyGo T-Can485 board support
- Add new lilygo build environment with LILYGO_BOARD flag - Update Pins.h with conditional pin configuration for LilyGo vs standard ESP32 - Add conditional RS485 initialization in ModbusRTU.cpp for LilyGo board - Update documentation (README.md and SoftwareSetup.md) to explain hardware options - Reference GitHub discussion #4 for LilyGo wiring details The LilyGo T-Can485 board includes built-in RS485 transceiver, eliminating the need for external MAX485 module and simplifying hardware setup.
1 parent 1fc906b commit b1a20b6

File tree

5 files changed

+115
-6
lines changed

5 files changed

+115
-6
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,24 @@ HeidelBridge is a firmware for ESP32 microcontrollers. It allows you to bring yo
2121

2222
# Required Hardware
2323

24-
You only need two components for this project: an ESP32 microcontroller and a MAX485 module. Both are available in large quantities and at reasonable prices on the Internet. You will also need a breadboard and a few jumper wires. All in all, it shouldn't cost you more than 10€.
24+
You have two options for the hardware setup:
25+
26+
## Option 1: ESP32 + External MAX485 Module
27+
You need two components: an ESP32 microcontroller and a MAX485 module. Both are available in large quantities and at reasonable prices on the Internet. You will also need a breadboard and a few jumper wires. All in all, it shouldn't cost you more than 10€.
2528

2629
Parts list:
2730
- ESP32 microcontroller*
2831
- MAX485 breakout board
2932
- 6 jumper wires
3033
- A breadboard
3134

35+
## Option 2: LilyGo T-Can485 Board
36+
Alternatively, you can use a LilyGo T-Can485 board which has the RS485 transceiver already built-in, eliminating the need for an external MAX485 module.
37+
38+
Parts list:
39+
- LilyGo T-Can485 board (includes ESP32 + built-in RS485 transceiver)
40+
- 3 jumper wires (for connecting to the wallbox)
41+
3242
This should be enough for quickly putting together a fully functioning prototype.
3343
Of course a well designed PCB would be much nicer, but this is still work in progress. Once the design is ready, the schematics will be available *right here*.
3444

docs/SoftwareSetup.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,55 @@ Then follow these steps:
5151

5252
- Start by cloning or downloading this repository.
5353
- Optional: change `board = ...` in platformio.ini to match the ESP32 board you are actually using.
54+
- Choose the appropriate build environment (see [Build Environments](#build-environments) below).
5455
- Compile the project.
5556
- Build the file system image via the PlatformIO command palette.
5657
- Now connect your ESP32 via USB.
5758
- Upload the file system image.
5859
- Upload the firmware.
60+
61+
## Build Environments
62+
63+
HeidelBridge supports multiple build environments to accommodate different hardware configurations:
64+
65+
### Standard ESP32 + External RS485 Module (`heidelberg`)
66+
This is the default build environment for regular ESP32 development boards with an external RS485 module.
67+
68+
**To compile:**
69+
```bash
70+
pio run -e heidelberg
71+
```
72+
73+
**Pin configuration:**
74+
- GPIO18 → RS485 RO (Receiver Output)
75+
- GPIO19 → RS485 DI (Driver Input)
76+
- GPIO21 → RS485 DE+RE
77+
78+
### LilyGo T-Can485 Board (`lilygo`)
79+
This build environment is specifically designed for the LilyGo T-Can485 board, which has built-in RS485 capabilities and **does not require an external MAX485 module**.
80+
81+
**To compile:**
82+
```bash
83+
pio run -e lilygo
84+
```
85+
86+
**Pin configuration:**
87+
- GPIO21 → RS485 RO (Receiver Output)
88+
- GPIO22 → RS485 DI (Driver Input)
89+
- GPIO21 → RS485 DE+RE
90+
91+
**Additional features:**
92+
- Automatic initialization of onboard RS485 transceivers
93+
- 5V power supply control
94+
- CAN bus support (hardware available but not used in current firmware)
95+
- **No external MAX485 module needed** - RS485 transceiver is built into the board
96+
97+
For detailed wiring information and hardware setup for the LilyGo T-Can485 board, please refer to the [discussion thread](https://github.com/BorisBrock/HeidelBridge/discussions/4).
98+
99+
### Dummy Wallbox (`dummy`)
100+
This build environment creates a simulation mode for testing without actual wallbox hardware.
101+
102+
**To compile:**
103+
```bash
104+
pio run -e dummy
105+
```

platformio.ini

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
default_envs = heidelberg
1313

1414
[env]
15-
platform = espressif32@^6.8.1
16-
board = esp32doit-devkit-v1
15+
platform = espressif32
16+
board = esp32dev
1717
upload_protocol = esptool
18-
upload_port = /dev/ttyUSB*
18+
upload_port = COM4
1919
framework = arduino
2020
board_build.partitions = partitions.csv
2121
monitor_speed = 115200
@@ -40,4 +40,10 @@ build_flags =
4040
build_flags =
4141
-O2
4242
-D DUMMY_WALLBOX
43-
-D LOGGING_LEVEL_DEBUG
43+
-D LOGGING_LEVEL_DEBUG
44+
45+
[env:lilygo]
46+
build_flags =
47+
-O2
48+
-D LILYGO_BOARD
49+
-D LOGGING_LEVEL_ERROR

src/Components/Modbus/ModbusRTU.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ void ModbusRTU::Init()
2525
gMutex = xSemaphoreCreateMutex();
2626

2727
// Init serial conneted to the RTU Modbus
28+
29+
#ifdef LILYGO_BOARD
30+
//config for Lilygo ESP32 RS485 board
31+
pinMode(RS485_EN_PIN, OUTPUT);
32+
digitalWrite(RS485_EN_PIN, HIGH);
33+
34+
pinMode(RS485_SE_PIN, OUTPUT);
35+
digitalWrite(RS485_SE_PIN, HIGH);
36+
37+
pinMode(PIN_5V_EN, OUTPUT);
38+
digitalWrite(PIN_5V_EN, HIGH);
39+
// end config for Lilygo ESP32 RS485 board
40+
#endif
41+
2842
Logger::Info("Starting RS485 hardware serial");
2943
RTUutils::prepareHardwareSerial(gRs485Serial);
3044
gRs485Serial.begin(

src/Configuration/Pins.h

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,43 @@
22

33
namespace Pins
44
{
5+
#ifdef LILYGO_BOARD
6+
// Config for the Lilygo T-Can485 Board
7+
// Pin connections:
8+
// ESP32 GPIO21 -> MAXRS485 RO (Receiver Output)
9+
// ESP32 GPIO22 -> MAXRS485 DI (Driver Input)
10+
// ESP32 GPIO21 -> MAXRS485 DE+RE
11+
constexpr uint8_t PinRX = GPIO_NUM_21;
12+
constexpr uint8_t PinTX = GPIO_NUM_22;
13+
constexpr uint8_t PinRTS = GPIO_NUM_21;
14+
#else
15+
// Config for regular ESP32 boards + external RS485 module
516
// Pin connections:
617
// ESP32 GPIO18 -> MAXRS485 RO (Receiver Output)
718
// ESP32 GPIO19 -> MAXRS485 DI (Driver Input)
819
// ESP32 GPIO21 -> MAXRS485 DE+RE
920
constexpr uint8_t PinRX = GPIO_NUM_18;
1021
constexpr uint8_t PinTX = GPIO_NUM_19;
1122
constexpr uint8_t PinRTS = GPIO_NUM_21;
12-
};
23+
#endif
24+
};
25+
26+
#ifdef LILYGO_BOARD
27+
#define PIN_5V_EN 16
28+
29+
#define CAN_TX_PIN 26
30+
#define CAN_RX_PIN 27
31+
#define CAN_SE_PIN 23
32+
33+
#define RS485_EN_PIN 17 // 17 /RE
34+
#define RS485_TX_PIN 22 // 21
35+
#define RS485_RX_PIN 21 // 22
36+
#define RS485_SE_PIN 19 // 22 /SHDN
37+
38+
#define SD_MISO_PIN 2
39+
#define SD_MOSI_PIN 15
40+
#define SD_SCLK_PIN 14
41+
#define SD_CS_PIN 13
42+
43+
#define WS2812_PIN 4
44+
#endif

0 commit comments

Comments
 (0)