Skip to content

Commit acf0a66

Browse files
authored
Merge pull request DavidAntliff#3 from DavidAntliff/ESP-IDF_v3.3
Support Esp idf v3.3
2 parents b8b0295 + d90c111 commit acf0a66

File tree

7 files changed

+59
-44
lines changed

7 files changed

+59
-44
lines changed

.travis.yml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
dist: bionic
2-
env:
3-
global:
4-
# Set Python 3.7.1 as the default python
5-
- PATH=/opt/python/3.7.1/bin:$PATH
6-
- MAKEFLAGS="-j 2"
7-
8-
language: bash
9-
10-
addons:
11-
apt:
12-
packages:
13-
- gperf
14-
- python3
15-
- python3-pip
2+
language: python
3+
python: "3.8"
164

175
before_install:
186
# Save path to the git respository
@@ -37,12 +25,9 @@ install:
3725
# Set the path to ESP-IDF directory
3826
- export IDF_PATH=~/esp/esp-idf
3927
# Install python dependencies
40-
- pip install --user --requirement $IDF_PATH/requirements.txt
28+
- pip install --requirement $IDF_PATH/requirements.txt
4129

4230
script:
43-
# Go back to the git repository
31+
# Build project within the original repository
4432
- cd $PROJECT_PATH
45-
# Update configuration so that kconfig doesn't start interactive mode
46-
- make defconfig
47-
# Build project from the git repository
48-
- make
33+
- $IDF_PATH/tools/idf.py build

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# The following five lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
project(esp32-i2c-lcd1602-example)
7+
8+
# Ignore false clang warnings about `struct foo = { 0 }`
9+
target_compile_options(${IDF_PROJECT_EXECUTABLE} PRIVATE -Wno-missing-braces -Wmissing-field-initializers)

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
This is an example application for the HD4470-compatible LCD1602 device connected via an I2C backpack.
99

10-
It is written and tested for v2.1.1 and v3.0 of the [ESP-IDF](https://github.com/espressif/esp-idf) environment, using the xtensa-esp32-elf toolchain (gcc version 5.2.0).
10+
This application is also usable with an LCD2004 module (20 columns, 4 rows), by uncommenting the `LCD_NUM_ROWS`, `LCD_NUM_COLUMNS`, and `LCD_NUM_VISIBLE_COLUMNS` definitions at the top of `app_main.c`.
11+
12+
It is written and tested for v3.3 of the [ESP-IDF](https://github.com/espressif/esp-idf) environment, using the xtensa-esp32-elf toolchain (gcc version 5.2.0).
1113

1214
Ensure that submodules are cloned:
1315

@@ -16,8 +18,9 @@ Ensure that submodules are cloned:
1618
Build the application with:
1719

1820
$ cd esp32-i2c-lcd1602-example.git
19-
$ make menuconfig # set your serial configuration and the I2C GPIO - see below
20-
$ make flash monitor
21+
$ idf.py menuconfig # set your serial configuration and the I2C GPIO - see below
22+
$ idf.py build
23+
$ idf.py -p (PORT) flash monitor
2124

2225
The program should detect your connected device and display some demonstration text on the LCD.
2326

@@ -32,7 +35,9 @@ This application makes use of the following components (included as submodules):
3235

3336
To run this example, connect one LCD1602 device to two GPIOs on the ESP32 (I2C SDA and SCL). If external pull-up resistors are not provided with the sensor, add a 10 KOhm resistor from each GPIO to the 3.3V supply.
3437

35-
`make menuconfig` can be used to set the I2C GPIOs and LCD1602 device I2C address.
38+
`idf.py menuconfig` can be used to set the I2C GPIOs and LCD1602 device I2C address.
39+
40+
Note that the 3.3V supply may be insufficient to run the display satisfactorily. In this case I suggest using a 5V supply to the LCD display, and using appropriate level shifter circuitry on the I2C SCL and SDA connections.
3641

3742
## Features
3843

main/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set(COMPONENT_SRCDIRS ".")
2+
set(COMPONENT_ADD_INCLUDEDIRS ".")
3+
4+
register_component()
5+

main/app_main.c

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242

4343
#define TAG "app"
4444

45+
// LCD1602
46+
#define LCD_NUM_ROWS 2
47+
#define LCD_NUM_COLUMNS 32
48+
#define LCD_NUM_VISIBLE_COLUMNS 16
49+
50+
// LCD2004
51+
//#define LCD_NUM_ROWS 4
52+
//#define LCD_NUM_COLUMNS 40
53+
//#define LCD_NUM_VISIBLE_COLUMNS 20
54+
4555
// Undefine USE_STDIN if no stdin is available (e.g. no USB UART) - a fixed delay will occur instead of a wait for a keypress.
4656
#define USE_STDIN 1
4757
//#undef USE_STDIN
@@ -69,18 +79,20 @@ static void i2c_master_init(void)
6979
I2C_MASTER_TX_BUF_LEN, 0);
7080
}
7181

72-
// WARNING: ESP32 does not support blocking input from stdin yet, so this polls
73-
// the UART and effectively hangs up the SDK.
82+
// uart_rx_one_char_block() causes a watchdog trigger, so use the non-blocking
83+
// uart_rx_one_char() and delay briefly to reset the watchdog.
7484
static uint8_t _wait_for_user(void)
7585
{
7686
uint8_t c = 0;
87+
7788
#ifdef USE_STDIN
7889
while (!c)
7990
{
8091
STATUS s = uart_rx_one_char(&c);
8192
if (s == OK) {
8293
printf("%c", c);
8394
}
95+
vTaskDelay(1);
8496
}
8597
#else
8698
vTaskDelay(1000 / portTICK_RATE_MS);
@@ -97,12 +109,15 @@ void lcd1602_task(void * pvParameter)
97109

98110
// Set up the SMBus
99111
smbus_info_t * smbus_info = smbus_malloc();
100-
smbus_init(smbus_info, i2c_num, address);
101-
smbus_set_timeout(smbus_info, 1000 / portTICK_RATE_MS);
112+
ESP_ERROR_CHECK(smbus_init(smbus_info, i2c_num, address));
113+
ESP_ERROR_CHECK(smbus_set_timeout(smbus_info, 1000 / portTICK_RATE_MS));
102114

103115
// Set up the LCD1602 device with backlight off
104116
i2c_lcd1602_info_t * lcd_info = i2c_lcd1602_malloc();
105-
i2c_lcd1602_init(lcd_info, smbus_info, true);
117+
ESP_ERROR_CHECK(i2c_lcd1602_init(lcd_info, smbus_info, true,
118+
LCD_NUM_ROWS, LCD_NUM_COLUMNS, LCD_NUM_VISIBLE_COLUMNS));
119+
120+
ESP_ERROR_CHECK(i2c_lcd1602_reset(lcd_info));
106121

107122
// turn off backlight
108123
ESP_LOGI(TAG, "backlight off");
@@ -149,7 +164,7 @@ void lcd1602_task(void * pvParameter)
149164
_wait_for_user();
150165
i2c_lcd1602_set_display(lcd_info, false);
151166

152-
ESP_LOGI(TAG, "display F at 7,1");
167+
ESP_LOGI(TAG, "display F at 7,1 (display disabled)");
153168
_wait_for_user();
154169
i2c_lcd1602_move_cursor(lcd_info, 7, 1);
155170
i2c_lcd1602_write_char(lcd_info, 'F');
@@ -166,20 +181,20 @@ void lcd1602_task(void * pvParameter)
166181
_wait_for_user();
167182
i2c_lcd1602_set_cursor(lcd_info, false);
168183

169-
ESP_LOGI(TAG, "display alphabet at 0,0"); // should overflow to second line at "ABC..."
184+
ESP_LOGI(TAG, "display alphabet from 0,0"); // should overflow to second line at "ABC..."
170185
_wait_for_user();
171186
i2c_lcd1602_home(lcd_info);
172187
i2c_lcd1602_write_string(lcd_info, "abcdefghijklmnopqrstuvwxyz0123456789.,-+ABCDEFGHIJKLMNOPQRSTUVWXYZ");
173188

174-
ESP_LOGI(TAG, "scroll left 8 places slowly");
189+
ESP_LOGI(TAG, "scroll display left 8 places slowly");
175190
_wait_for_user();
176191
for (int i = 0; i < 8; ++i)
177192
{
178193
i2c_lcd1602_scroll_display_left(lcd_info);
179194
vTaskDelay(200 / portTICK_RATE_MS);
180195
}
181196

182-
ESP_LOGI(TAG, "scroll right 8 places quickly");
197+
ESP_LOGI(TAG, "scroll display right 8 places quickly");
183198
_wait_for_user();
184199
for (int i = 0; i < 8; ++i)
185200
{
@@ -246,7 +261,7 @@ void lcd1602_task(void * pvParameter)
246261
i2c_lcd1602_clear(lcd_info);
247262
i2c_lcd1602_set_cursor(lcd_info, false);
248263

249-
ESP_LOGI(TAG, "create custom character and display");
264+
ESP_LOGI(TAG, "create and display custom characters");
250265
_wait_for_user();
251266
// https://github.com/agnunez/ESP8266-I2C-LCD1602/blob/master/examples/CustomChars/CustomChars.ino
252267
uint8_t bell[8] = {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4};
@@ -267,9 +282,6 @@ void lcd1602_task(void * pvParameter)
267282
i2c_lcd1602_define_char(lcd_info, I2C_LCD1602_INDEX_CUSTOM_7, retarrow);
268283

269284
// after defining custom characters, DDRAM address must be set by home() or moving the cursor
270-
271-
ESP_LOGI(TAG, "display custom characters");
272-
_wait_for_user();
273285
i2c_lcd1602_move_cursor(lcd_info, 0, 0);
274286
i2c_lcd1602_write_char(lcd_info, I2C_LCD1602_CHARACTER_CUSTOM_0);
275287
i2c_lcd1602_write_char(lcd_info, I2C_LCD1602_CHARACTER_CUSTOM_1);
@@ -298,7 +310,7 @@ void lcd1602_task(void * pvParameter)
298310
i2c_lcd1602_write_char(lcd_info, I2C_LCD1602_CHARACTER_DIVIDE);
299311
i2c_lcd1602_write_char(lcd_info, I2C_LCD1602_CHARACTER_BLOCK);
300312

301-
ESP_LOGI(TAG, "display all characters");
313+
ESP_LOGI(TAG, "display all characters (loop)");
302314
_wait_for_user();
303315
i2c_lcd1602_clear(lcd_info);
304316
i2c_lcd1602_set_cursor(lcd_info, true);
@@ -309,13 +321,13 @@ void lcd1602_task(void * pvParameter)
309321
{
310322
i2c_lcd1602_write_char(lcd_info, c);
311323
vTaskDelay(100 / portTICK_RATE_MS);
312-
ESP_LOGI(TAG, "col %d, row %d, char 0x%02x", col, row, c);
324+
ESP_LOGD(TAG, "col %d, row %d, char 0x%02x", col, row, c);
313325
++c;
314326
++col;
315-
if (col >= I2C_LCD1602_NUM_VISIBLE_COLUMNS)
327+
if (col >= LCD_NUM_VISIBLE_COLUMNS)
316328
{
317329
++row;
318-
if (row >= I2C_LCD1602_NUM_ROWS)
330+
if (row >= LCD_NUM_ROWS)
319331
{
320332
row = 0;
321333
}
@@ -331,4 +343,3 @@ void app_main()
331343
{
332344
xTaskCreate(&lcd1602_task, "lcd1602_task", 4096, NULL, 5, NULL);
333345
}
334-

0 commit comments

Comments
 (0)