Skip to content

Commit 353ec14

Browse files
authored
Support for different boards (ESP32 and Lilygo) (#41)
* Initial commit * Making code compile * Adding board logic * Updating docs
1 parent 680caf9 commit 353ec14

15 files changed

Lines changed: 296 additions & 29 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ jobs:
3434
run: pip install --upgrade platformio
3535

3636
- name: Build HeidelBridge
37-
run: pio run -e heidelberg
37+
run: pio run -e esp32

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ HeidelBridge is a firmware for ESP32 microcontrollers. It allows you to bring yo
2424
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€.
2525

2626
Parts list:
27-
- ESP32 microcontroller*
27+
- ESP32 microcontroller board*
2828
- MAX485 breakout board
2929
- 6 jumper wires
3030
- A breadboard
3131

3232
This should be enough for quickly putting together a fully functioning prototype.
3333
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*.
3434

35-
> *\* This project is currently based on the classic ESP32. It has not been built/tested for newer models, like the S2 and C6.*
35+
> *\* This project supports the classic ESP32. It has not been built/tested for newer models, like the S2 and C6. Additionally the LILYGO T-CAN485 board is supported, which already includes an on-board RS485 transceiver.*
3636
3737
# Getting Started
3838

docs/SoftwareSetup.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,50 @@ Then follow these steps:
5656
- Now connect your ESP32 via USB.
5757
- Upload the file system image.
5858
- Upload the firmware.
59+
60+
61+
## Build Environments
62+
63+
HeidelBridge supports multiple build environments to accommodate different hardware configurations:
64+
65+
### Standard ESP32 + External RS485 Module (`esp32`)
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 esp32
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: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99
; https://docs.platformio.org/page/projectconf.html
1010

1111
[platformio]
12-
default_envs = heidelberg
12+
default_envs = esp32
1313

14+
# Common settings
1415
[env]
15-
platform = espressif32@^6.8.1
16-
board = esp32doit-devkit-v1
17-
upload_protocol = esptool
1816
upload_port = /dev/ttyUSB*
1917
framework = arduino
2018
board_build.partitions = partitions.csv
@@ -31,13 +29,34 @@ lib_deps =
3129
esphome/ESPAsyncWebServer-esphome @^3.3.0
3230
bblanchon/ArduinoJson @ ^7.4.1
3331

34-
[env:heidelberg]
32+
# Build a dummy HeidelBridge with no real wallbox hardware attached.
33+
# This is for testing and simulation only.
34+
[env:dummy]
35+
platform = espressif32@^6.8.1
36+
board = esp32doit-devkit-v1
37+
upload_protocol = esptool
38+
build_flags =
39+
-O2
40+
-D DUMMY_WALLBOX
41+
-D BOARD_ESP32
42+
-D LOGGING_LEVEL_DEBUG
43+
44+
# Default environment for regular ESP32 boards.
45+
[env:esp32]
46+
platform = espressif32@^6.8.1
47+
board = esp32doit-devkit-v1
48+
upload_protocol = esptool
3549
build_flags =
3650
-O2
51+
-D BOARD_ESP32
3752
-D LOGGING_LEVEL_ERROR
3853

39-
[env:dummy]
54+
# LILYGO T-CAN485, ESP32 board with on-board RS485
55+
[env:lilygo]
56+
platform = espressif32@^6.8.1
57+
board = esp32dev
58+
upload_protocol = esptool
4059
build_flags =
4160
-O2
42-
-D DUMMY_WALLBOX
43-
-D LOGGING_LEVEL_DEBUG
61+
-D BOARD_LILYGO
62+
-D LOGGING_LEVEL_ERROR

src/Boards/Board.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <Arduino.h>
2+
#include "Board.h"
3+
4+
// Constructor
5+
Board::Board(uint8_t pinRx, uint8_t pinTx, uint8_t pinRts)
6+
: mPinRx(pinRx), mPinTx(pinTx), mPinRts(pinRts)
7+
{
8+
}
9+
10+
// These functions return the pins used by this board
11+
uint8_t Board::GetPinRx()
12+
{
13+
return mPinRx;
14+
}
15+
16+
// These functions return the pins used by this board
17+
uint8_t Board::GetPinTx()
18+
{
19+
return mPinTx;
20+
}
21+
22+
// These functions return the pins used by this board
23+
uint8_t Board::GetPinRts()
24+
{
25+
return mPinRts;
26+
}

src/Boards/Board.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
class Board
4+
{
5+
protected:
6+
// Constructor
7+
Board(uint8_t pinRx, uint8_t pinTx, uint8_t pinRts);
8+
9+
public:
10+
// Initializes the board
11+
virtual void Init() = 0;
12+
13+
// Logs board name/information
14+
virtual void Print() = 0;
15+
16+
// These functions return the pins used by this board
17+
uint8_t GetPinRx();
18+
uint8_t GetPinTx();
19+
uint8_t GetPinRts();
20+
21+
private:
22+
uint8_t mPinRx, mPinTx, mPinRts;
23+
};

src/Boards/BoardFactory.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <Arduino.h>
2+
#include "Board.h"
3+
#include "BoardFactory.h"
4+
5+
// All supported boards
6+
#include "ESP32/BoardESP32.h"
7+
#include "Lilygo/BoardLilygo.h"
8+
9+
// Factory instance
10+
BoardFactory *BoardFactory::Instance()
11+
{
12+
static BoardFactory factoryInstance;
13+
return &factoryInstance;
14+
}
15+
16+
// Gets the currently used board
17+
Board *BoardFactory::GetBoard()
18+
{
19+
#ifdef BOARD_ESP32
20+
static BoardESP32 boardInstance;
21+
#elif BOARD_LILYGO
22+
static BoardLilygo boardInstance;
23+
#endif
24+
25+
return &boardInstance;
26+
}

src/Boards/BoardFactory.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
// Forward declarations
4+
class Board;
5+
6+
class BoardFactory
7+
{
8+
private:
9+
BoardFactory() {};
10+
11+
public:
12+
// Factory instance
13+
static BoardFactory *Instance();
14+
15+
// Gets the currently used board
16+
static Board *GetBoard();
17+
};

src/Boards/ESP32/BoardESP32.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <Arduino.h>
2+
#include "Components/Logger/Logger.h"
3+
#include "../Board.h"
4+
#include "BoardESP32.h"
5+
6+
// Pin connections:
7+
// ESP32 GPIO18 -> MAXRS485 RO (Receiver Output)
8+
// ESP32 GPIO19 -> MAXRS485 DI (Driver Input)
9+
// ESP32 GPIO21 -> MAXRS485 DE+RE
10+
constexpr uint8_t PinRX = GPIO_NUM_18;
11+
constexpr uint8_t PinTX = GPIO_NUM_19;
12+
constexpr uint8_t PinRTS = GPIO_NUM_21;
13+
14+
// Constructor
15+
BoardESP32::BoardESP32()
16+
: Board(PinRX, PinTX, PinRTS)
17+
{
18+
// Nothing to do
19+
}
20+
21+
// Initializes the board
22+
void BoardESP32::Init()
23+
{
24+
// Nothing to do
25+
}
26+
27+
// Logs board name/information
28+
void BoardESP32::Print()
29+
{
30+
Logger::Print("ESP32");
31+
}

src/Boards/ESP32/BoardESP32.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
class BoardESP32 : public Board
4+
{
5+
public:
6+
// Constructor
7+
BoardESP32();
8+
9+
// Initializes the board
10+
virtual void Init();
11+
12+
// Logs board name/information
13+
virtual void Print();
14+
};

0 commit comments

Comments
 (0)