Skip to content

Commit 687cfe4

Browse files
authored
Merge pull request #6 from ubidefeo/dev
Auto-detect of RGB Display.
2 parents aa0edc3 + 30a10fe commit 687cfe4

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This library is designed to support a MicroPython interface for i2c LCD characte
66

77
![RGB](assets/LCDRGB.jpg)
88

9-
[Grove LCD RGB Backlight v2.0, v3.0, v4.0](https://wiki.seeedstudio.com/Grove-LCD_RGB_Backlight/)
9+
[Grove LCD RGB Backlight v2.0, v3.0, v4.0, v5.0](https://wiki.seeedstudio.com/Grove-LCD_RGB_Backlight/)
1010

1111
![RGB](assets/LCDMONO.jpg)
1212

@@ -60,8 +60,8 @@ Changes the color of the LCD Backlight to (r,g,b)
6060
Examples are provided in the _examples_ folder.
6161

6262
**Note:**
63-
To use Grove RGB Display versions older than V5.0 you will need to initialize the Display object supplying the model
63+
Grove RGB Display initialisation is auto-detected, hence just supply the bus.
6464

6565
```Python
66-
my_display = RGBDisplay(i2c_bus, 0x3e, RGBDisplay.GROVE_RGB_V4)
66+
my_display = RGBDisplay(i2c_bus)
6767
```

examples/color_cycle.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
# This example only works with Grove RGB Backlight i2c LCD Displays
2-
#
3-
# Version 5.0 replaced the LED controller, requiring some changes.
4-
# Please specify which version you use
2+
# https://wiki.seeedstudio.com/Grove-LCD_RGB_Backlight/
53

64
from i2c_lcd import RGBDisplay
75
from machine import I2C
86

97
i2c = I2C(0)
108

11-
# Defaults to Grove RGB LCD Display v5.0
12-
# for versions until V4.0 use
13-
# d = RGBDisplay(i2c, RGBDisplay.GROVE_RGB_V4)
149
d = RGBDisplay(i2c)
1510

16-
1711
d.home()
1812
d.write('Hello World')
1913

examples/helloworld.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# This example works with both Grove i2c LCD Displays:
2-
# - Black on Yellow
3-
# - RGB Backlight
1+
# This example works with both Multiple i2c LCD Displays, including the following from Seeed Studio:
2+
# - Grove LCD RGB Backlight
3+
# - Grove LCD 16x2 (single color backlight)
44

55
import i2c_lcd
66
from machine import I2C

i2c_lcd/i2c_lcd.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ def move(self, col, row):
5151

5252
class RGBDisplay(Display):
5353
# Grove RGB Display versions
54-
GROVE_RGB_V4 = (4, 0x62) # version 3-4
55-
GROVE_RGB_V5 = (5, 0x30) # version 5 replaced the LED controller
54+
GROVE_RGB_V4_ADDRESS = 0x62 # version 3-4
55+
GROVE_RGB_V5_ADDRESS = 0x30 # version 5 replaced the LED controller
5656

5757
backlight = None
5858

59-
def __init__(self, i2c, lcd_addr=0x3e, display_version = GROVE_RGB_V5):
60-
rgb_addr = display_version[1]
59+
def __init__(self, i2c, lcd_addr=0x3e):
60+
i2c_devices = i2c.scan()
61+
display_version = self.GROVE_RGB_V5_ADDRESS if self.GROVE_RGB_V5_ADDRESS in i2c_devices else self.GROVE_RGB_V4_ADDRESS
62+
rgb_addr = display_version
6163
self.backlight = Backlight(i2c, rgb_addr)
6264
super().__init__(i2c, lcd_addr)
6365

0 commit comments

Comments
 (0)