Seeed Grove User manual

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
1/29
Grove - Chainable RGB LED is based on P9813 chip which is a full-
color LED driver. It provides 3 constant-current drivers as well as
modulated output of 256 shades of gray. It communicates with a
MCU using 2-wire transmission (Data and Clock). This 2-wire
transmission can be used to cascade additional Grove - Chainable
RGB LED modules. The built-in clock regeneration enhances the
transmission distance. This Grove module is suitable for any
colorful LED based projects.

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
2/29
Version
Revision Descriptions Release How to Buy
v1 Initial public
release
(beta)
May 5,
2011
[https://www.seeedstudio.com/
Chainable-RGB-LED-p-850.html]
v2 Replace
P9813S16
with
P9813S14
and change
Grove
connector
from
Vertical to
horizontal
Apr 19,
2016
[https://www.seeedstudio.com/
%E2%80%93-Chainable-RGB-Le
p-2903.html]
Specications
Operating Voltage: 5V
Operating Current: 20mA
Communication Protocol: Serial
Tip
More details about Grove modules please refer to Grove System
[https://wiki.seeedstudio.com/Grove_System/]

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
3/29
Platforms Supported
Arduino Raspberry
Pi
Usage
Play with Arduino [/Arduino]
When you get Grove - Chainble RGB LED, you may think how I can
light up it. Now we will show you this demo: all colors of RGB cycles
in an uniform way.
To complete this demo, you can use one or more Grove - Chainable
RGB LED. Note that the IN interface of one Grove - Chainable RGB
LED should be connect to D7/D8 of Grove - Base Shield
[/Base_Shield_V2] and its OUT interface connect to IN interface of
another Grove - Chainable RGB LED, chainable more LED in this way.
Caution
The platforms mentioned above as supported is/are an indication of the
module's software or theoritical compatibility. We only provide software
library or code examples for Arduino platform in most cases. It is not
possible to provide software library / demo code for all possible MCU
platforms. Hence, users have to write their own software library.

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
4/29
Download Chainable LED Library
[https://github.com/pjpmarques/ChainableLED] and install it to
Arduino Library. There is the course about how to install
Arduino Library [/How_to_install_Arduino_Library] in wiki page.
Open the example CycleThroughColors by the path:File-
>Examples->ChainableLED_master and upload it to Seeeduino.
1/*
2 * Example of using the ChainableRGB library for control
3 * This code cycles through all the colors in an uniform
4 */
5
6
7#include <ChainableLED.h>
8
9#define NUM_LEDS 5
10
11 ChainableLED leds(7, 8, NUM_LEDS);
12
13 void setup()
14 {
15 leds.init();
16 }
17
18 float hue = 0.0;
19 boolean up = true;
20
21 void loop()
22 {
23 for (byte i=0; i<NUM_LEDS; i++)
24 leds.setColorHSL(i, hue, 1.0, 0.5);
25
26 delay(50);
27
28 if (up)
29 hue+= 0.025;
30 else
31 hue-= 0.025;

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
5/29
You can observe this scene: colors of ve LED will gradient
consistently.
Extended application: Based on Chainable LED Library
[https://github.com/pjpmarques/ChainableLED], we have designed
this demo: RGB color varies with the temperature measured by
Grove - temperature. The RGB color vary from green to red when the
temperature is from 25 to 32. The test code is shown below. Do it if
you are interested in it.
32
33 if (hue>=1.0 && up)
34 up = false;
35 else if (hue<=0.0 && !up)
36 up = true;
37 }
1 // demo of temperature -> rgbLED
2 // temperature form 25 - 32, rgbLed from green -> red
3 // Grove-temperature plu to A0
4 // LED plug to D7,D8
5
6 #include <Streaming.h>
7 #include <ChainableLED.h>
8
9 #define TEMPUP 32
10 #define TEMPDOWN 25
11
12 ChainableLED leds(7, 8, 1); // connect to pin7 and pi
13
14 int getAnalog() // get value from A0
15 {
16 int sum = 0;
17 for(int i=0; i<32; i++)
18 {
19 sum += analogRead(A0);
20 }

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
6/29
21
22 return sum>>5;
23 }
24
25 float getTemp() // get temperature
26 {
27 float temperature = 0.0;
28 float resistance = 0.0;
29 int B = 3975; //B value of the thermistor
30
31 int a = getAnalog();
32
33 resistance = (float)(1023-a)*10000/a; //get the r
34 temperature = 1/(log(resistance/10000)/B+1/298.15
35 return temperature;
36 }
37
38 void ledLight(int dta) // light led
39 {
40
41 dta = dta/4; // 0 - 255
42
43 int colorR = dta;
44 int colorG = 255-dta;
45 int colorB = 0;
46
47 leds.setColorRGB(0, colorR, colorG, colorB);
48 }
49
50 void setup()
51 {
52 Serial.begin(38400);
53 cout << "hello world !" << endl;
54 }
55
56 void loop()
57 {
58 float temp = getTemp();
59 int nTemp = temp*100;
60
61 nTemp = nTemp > TEMPUP*100 ? TEMPUP*100 : (nTemp

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
7/29
Play with Codecraft
Hardware
Step 1. Connect Grove - Chainanle RGB LED to port D7 in a Base
Shield
Step 2. Plug the Base Shield to your Seeeduino/Arduino.
Step 3. Link Seeeduino/Arduino to your PC via an USB cable.
Software
Step 1. Open Codecraft [https://ide.chmakered.com/], add Arduino
support, and drag a main procedure to working area.
Step 2. Drag blocks as picture below or open the cdc le which can
be downloaded at the end of this page.
62 nTemp = map(nTemp, TEMPDOWN*100, TEMPUP*100, 0, 1
63 ledLight(nTemp);
64 delay(100);
65 }
Note
If this is your rst time using Codecraft, see also Guide for Codecraft using
Arduino
[https://wiki.seeedstudio.com/Guide_for_Codecraft_using_Arduino/].

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
8/29
Upload the program to your Arduino/Seeeduino.
Play with Raspberry Pi
1.You should have got a raspberry pi and a grovepi or grovepi+.
2.You should have completed conguring the development
enviroment, otherwise follow here [/GrovePi_Plus].
3.Connection
Success
When the code nishes uploaded, you will see the LED fade in and fade
out.
Attention
If you are using Raspberry Pi with Raspberrypi OS >= Bullseye, you have to
use this command line only with Python3.

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
9/29
Plug the sensor to grovepi socket D7 by using a grove cable.
4.Navigate to the demos' directory:
To see the code
cd yourpath/GrovePi/Software/Python/
nano grove_chainable_rgb_led.py # "Ctrl+x" to exit
1 import time
2 import grovepi
3
4 # Connect first LED in Chainable RGB LED chain
5 # In: CI,DI,VCC,GND
6 # Out: CO,DO,VCC,GND
7 pin = 7
8
9 # I have 10 LEDs connected in series with the f
10 # First LED input socket connected to GrovePi, o
11 numleds = 1
12
13 grovepi.pinMode(pin,"OUTPUT")
14 time.sleep(1)
15
16 # Chainable RGB LED methods
17 # grovepi.storeColor(red, green, blue)
18 # grovepi.chainableRgbLed_init(pin, numLeds)
19 # grovepi.chainableRgbLed_test(pin, numLeds, tes
20 # grovepi.chainableRgbLed_pattern(pin, pattern,
21 # grovepi.chainableRgbLed_modulo(pin, offset, d
22 # grovepi.chainableRgbLed_setLevel(pin, level, r
23
24 # test colors used in grovepi.chainableRgbLed_te
25 testColorBlack = 0 # 0b000 #000000
26 testColorBlue = 1 # 0b001 #0000FF

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
10/29
27 testColorGreen = 2 # 0b010 #00FF00
28 testColorCyan = 3 # 0b011 #00FFFF
29 testColorRed = 4 # 0b100 #FF0000
30 testColorMagenta = 5 # 0b101 #FF00FF
31 testColorYellow = 6 # 0b110 #FFFF00
32 testColorWhite = 7 # 0b111 #FFFFFF
33
34 # patterns used in grovepi.chainableRgbLed_patte
35 thisLedOnly = 0
36 allLedsExceptThis = 1
37 thisLedAndInwards = 2
38 thisLedAndOutwards = 3
39
40 try:
41
42 print "Test 1) Initialise"
43
44 # init chain of leds
45 grovepi.chainableRgbLed_init(pin, numleds)
46 time.sleep(.5)
47
48 # change color to green
49 grovepi.storeColor(0,255,0)
50 time.sleep(.5)
51
52 # set led 1 to green
53 grovepi.chainableRgbLed_pattern(pin, thisLed
54 time.sleep(.5)
55
56 # change color to red
57 grovepi.storeColor(255,0,0)
58 time.sleep(.5)
59
60 # set led 10 to red
61 grovepi.chainableRgbLed_pattern(pin, thisLed
62 time.sleep(.5)
63
64 # pause so you can see what happened
65 time.sleep(2)
66
67 # reset (all off)

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
11/29
68 grovepi.chainableRgbLed_test(pin, numleds, t
69 time.sleep(.5)
70
71
72 print "Test 2a) Test Patterns - black"
73
74 # test pattern 0 - black (all off)
75 grovepi.chainableRgbLed_test(pin, numleds, t
76 time.sleep(1)
77
78
79 print "Test 2b) Test Patterns - blue"
80
81 # test pattern 1 blue
82 grovepi.chainableRgbLed_test(pin, numleds, t
83 time.sleep(1)
84
85
86 print "Test 2c) Test Patterns - green"
87
88 # test pattern 2 green
89 grovepi.chainableRgbLed_test(pin, numleds, t
90 time.sleep(1)
91
92
93 print "Test 2d) Test Patterns - cyan"
94
95 # test pattern 3 cyan
96 grovepi.chainableRgbLed_test(pin, numleds, t
97 time.sleep(1)
98
99
100 print "Test 2e) Test Patterns - red"
101
102 # test pattern 4 red
103 grovepi.chainableRgbLed_test(pin, numleds, t
104 time.sleep(1)
105
106
107 print "Test 2f) Test Patterns - magenta"
108

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
12/29
109 # test pattern 5 magenta
110 grovepi.chainableRgbLed_test(pin, numleds, t
111 time.sleep(1)
112
113
114 print "Test 2g) Test Patterns - yellow"
115
116 # test pattern 6 yellow
117 grovepi.chainableRgbLed_test(pin, numleds, t
118 time.sleep(1)
119
120
121 print "Test 2h) Test Patterns - white"
122
123 # test pattern 7 white
124 grovepi.chainableRgbLed_test(pin, numleds, t
125 time.sleep(1)
126
127
128 # pause so you can see what happened
129 time.sleep(2)
130
131 # reset (all off)
132 grovepi.chainableRgbLed_test(pin, numleds, t
133 time.sleep(.5)
134
135
136 print "Test 3a) Set using pattern - this led
137
138 # change color to red
139 grovepi.storeColor(255,0,0)
140 time.sleep(.5)
141
142 # set led 3 to red
143 grovepi.chainableRgbLed_pattern(pin, thisLed
144 time.sleep(.5)
145
146 # pause so you can see what happened
147 time.sleep(2)
148
149 # reset (all off)

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
13/29
150 grovepi.chainableRgbLed_test(pin, numleds, t
151 time.sleep(.5)
152
153
154 print "Test 3b) Set using pattern - all led
155
156 # change color to blue
157 grovepi.storeColor(0,0,255)
158 time.sleep(.5)
159
160 # set all leds except for 3 to blue
161 grovepi.chainableRgbLed_pattern(pin, allLed
162 time.sleep(.5)
163
164 # pause so you can see what happened
165 time.sleep(2)
166
167 # reset (all off)
168 grovepi.chainableRgbLed_test(pin, numleds, t
169 time.sleep(.5)
170
171
172 print "Test 3c) Set using pattern - this led
173
174 # change color to green
175 grovepi.storeColor(0,255,0)
176 time.sleep(.5)
177
178 # set leds 1-3 to green
179 grovepi.chainableRgbLed_pattern(pin, thisLed
180 time.sleep(.5)
181
182 # pause so you can see what happened
183 time.sleep(2)
184
185 # reset (all off)
186 grovepi.chainableRgbLed_test(pin, numleds, t
187 time.sleep(.5)
188
189
190 print "Test 3d) Set using pattern - this led

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
14/29
191
192 # change color to green
193 grovepi.storeColor(0,255,0)
194 time.sleep(.5)
195
196 # set leds 7-10 to green
197 grovepi.chainableRgbLed_pattern(pin, thisLed
198 time.sleep(.5)
199
200 # pause so you can see what happened
201 time.sleep(2)
202
203 # reset (all off)
204 grovepi.chainableRgbLed_test(pin, numleds, t
205 time.sleep(.5)
206
207
208 print "Test 4a) Set using modulo - all leds
209
210 # change color to black (fully off)
211 grovepi.storeColor(0,0,0)
212 time.sleep(.5)
213
214 # set all leds black
215 # offset 0 means start at first led
216 # divisor 1 means every led
217 grovepi.chainableRgbLed_modulo(pin, 0, 1)
218 time.sleep(.5)
219
220 # change color to white (fully on)
221 grovepi.storeColor(255,255,255)
222 time.sleep(.5)
223
224 # set all leds white
225 grovepi.chainableRgbLed_modulo(pin, 0, 1)
226 time.sleep(.5)
227
228 # pause so you can see what happened
229 time.sleep(2)
230
231 # reset (all off)

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
15/29
232 grovepi.chainableRgbLed_test(pin, numleds, t
233 time.sleep(.5)
234
235
236 print "Test 4b) Set using modulo - every 2"
237
238 # change color to red
239 grovepi.storeColor(255,0,0)
240 time.sleep(.5)
241
242 # set every 2nd led to red
243 grovepi.chainableRgbLed_modulo(pin, 0, 2)
244 time.sleep(.5)
245
246 # pause so you can see what happened
247 time.sleep(2)
248
249
250 print "Test 4c) Set using modulo - every 2,
251
252 # change color to green
253 grovepi.storeColor(0,255,0)
254 time.sleep(.5)
255
256 # set every 2nd led to green, offset 1
257 grovepi.chainableRgbLed_modulo(pin, 1, 2)
258 time.sleep(.5)
259
260 # pause so you can see what happened
261 time.sleep(2)
262
263 # reset (all off)
264 grovepi.chainableRgbLed_test(pin, numleds, t
265 time.sleep(.5)
266
267
268 print "Test 4d) Set using modulo - every 3,
269
270 # change color to red
271 grovepi.storeColor(255,0,0)
272 time.sleep(.5)

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
16/29
273
274 # set every 3nd led to red
275 grovepi.chainableRgbLed_modulo(pin, 0, 3)
276 time.sleep(.5)
277
278 # change color to green
279 grovepi.storeColor(0,255,0)
280 time.sleep(.5)
281
282 # set every 3nd led to green, offset 1
283 grovepi.chainableRgbLed_modulo(pin, 1, 3)
284 time.sleep(.5)
285
286 # change color to blue
287 grovepi.storeColor(0,0,255)
288 time.sleep(.5)
289
290 # set every 3nd led to blue, offset 2
291 grovepi.chainableRgbLed_modulo(pin, 2, 3)
292 time.sleep(.5)
293
294 # pause so you can see what happened
295 time.sleep(2)
296
297 # reset (all off)
298 grovepi.chainableRgbLed_test(pin, numleds, t
299 time.sleep(.5)
300
301
302 print "Test 4e) Set using modulo - every 3,
303
304 # change color to yellow
305 grovepi.storeColor(255,255,0)
306 time.sleep(.5)
307
308 # set every 4nd led to yellow
309 grovepi.chainableRgbLed_modulo(pin, 1, 3)
310 time.sleep(.5)
311
312 # pause so you can see what happened
313 time.sleep(2)

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
17/29
314
315
316 print "Test 4f) Set using modulo - every 3,
317
318 # change color to magenta
319 grovepi.storeColor(255,0,255)
320 time.sleep(.5)
321
322 # set every 4nd led to magenta
323 grovepi.chainableRgbLed_modulo(pin, 2, 3)
324 time.sleep(.5)
325
326 # pause so you can see what happened
327 time.sleep(2)
328
329 # reset (all off)
330 grovepi.chainableRgbLed_test(pin, numleds, t
331 time.sleep(.5)
332
333
334 print "Test 5a) Set level 6"
335
336 # change color to green
337 grovepi.storeColor(0,255,0)
338 time.sleep(.5)
339
340 # set leds 1-6 to green
341 grovepi.write_i2c_block(0x04,[95,pin,6,0])
342 time.sleep(.5)
343
344 # pause so you can see what happened
345 time.sleep(2)
346
347 # reset (all off)
348 grovepi.chainableRgbLed_test(pin, numleds, t
349 time.sleep(.5)
350
351
352 print "Test 5b) Set level 7 - reverse"
353
354 # change color to red

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
18/29
Notice that there's something you have to concern of:
Also all methods you can see in grovepi.py is:
5.Run the demo.
355 grovepi.storeColor(255,0,0)
356 time.sleep(.5)
357
358 # set leds 4-10 to red
359 grovepi.write_i2c_block(0x04,[95,pin,7,1])
360 time.sleep(.5)
361
362
363 except KeyboardInterrupt:
364 # reset (all off)
365 grovepi.chainableRgbLed_test(pin, numleds, t
366 break
367 except IOError:
368 print "Error"
1 pin = 7 #setting up the output pin
2 numleds = 1 #how many leds you plug
1 storeColor(red, green, blue)
2 chainableRgbLed_init(pin, numLeds)
3 chainableRgbLed_test(pin, numLeds, testColor)
4 chainableRgbLed_pattern(pin, pattern, whichLed)
5 chainableRgbLed_modulo(pin, offset, divisor)
6 chainableRgbLed_setLevel(pin, level, reverse)
sudo python3 grove_chainable_rgb_led.py

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
19/29
6.This demo may not work if your grovepi dosen't have the newest
rmware, update the rmware.
With Beaglebone Green
To begin editing programs that live on BBG, you can use the Cloud9
IDE.
As a simple exercise to become familiar with Cloud9 IDE, creating a
simple application to blink one of the 4 user programmable LEDs on
the BeagleBone is a good start.
If this is your rst time to use Cloud9 IDE, please follow this link
[/BeagleBone_Green].
Step1: Set the Grove - UART socket as a Grove - GPIO Socket, just
follow this link [https://www.seeedstudio.com/recipe/362-how-to-
use-the-grove-uart-port-as-a-gpio-on-bbg.html].
Step2: Click the "+" in the top-right to create a new le.
1 cd yourpath/GrovePi/Firmware
2 sudo ./firmware_update.sh

7/23/22, 9:41 PM
Grove - Chainable RGB LED - Seeed Wiki
https://wiki.seeedstudio.com/Grove-Chainable_RGB_LED/
20/29
Step3: Copy and paste the following code into the new tab
1import time
2import Adafruit_BBIO.GPIO as GPIO
3
4CLK_PIN = "P9_22"
5DATA_PIN = "P9_21"
6NUMBER_OF_LEDS = 1
7
8class ChainableLED():
9 def __init__(self, clk_pin, data_pin, number_of_led
10 self.__clk_pin = clk_pin
11 self.__data_pin = data_pin
12 self.__number_of_leds = number_of_leds
13
14 GPIO.setup(self.__clk_pin, GPIO.OUT)
15 GPIO.setup(self.__data_pin, GPIO.OUT)
16
17 for i in range(self.__number_of_leds):
18 self.setColorRGB(i, 0, 0, 0)
19
20 def clk(self):
Other manuals for Grove
14
Table of contents
Other Seeed Microcontroller manuals