Grove Base Kit for Raspberry Pi
SKU 110020169
The Grove Base Kit for Raspberry Pi is one of the best kits for beginners to get started with
Raspberry Pi. No troublesome soldering and no complicated wiring. You can focus on learning
Raspberry Pi. This kit includes a Grove Base Hat for Raspberry Pi and 10 Grove modules, which
covering sensor, actuator and display. All you need to do is following the demo, plug the
module into the Grove Base Hat, truly plug and play.
On top of that, we have provided you with detailed instructions on the use of Raspberry Pi and
the use of each module, which including 8 lessons for module. Just click the LEARN tab to view
this user manual. Also you can check the Vedio Guide here, which will tell you how to use this
kit step by step.
All in all, whether you are a student, teacher, artist, hardware enthusiast, and so on, with the
help of the Grove Base Kit for Raspberry Pi, you will get to know Raspberry Pi quickly and
comprehensively.
Part List
Grove Base Hat for Raspberry Pi
Grove ‐ Red LED Button
Grove ‐ Buzzer
Grove ‐ Moisture Sensor
Grove ‐ Temperature & Humidity Sensor (DHT11)
Grove ‐ Light Sensor
Grove ‐ mini PIR motion sensor
Grove ‐ Ultrasonic Ranger
Grove ‐ Relay
Grove ‐ Servo
Grove ‐ 16 x 2 LCD (White on Blue)
ECCN/HTS
ECCN
EAR99
HSCODE
9023009000
UPC
Grove Base Kit for Raspberry Pi
GROVE SYSTEM
Grove is a modular prototyping system consist of a base unit and various modules with
standardized connector. The base unit is generally a microprocessor which allows for
communicates, processes and controls the input or output from the Grove modules.
Every single Grove module typically addresses a single function, range from a simple
button to a more complex heart rate sensor. the standardised Grove connector allows
user to assemble Grove units with building block approach, compared to the jumper or
solder based system it is much easier to assemble or disassemble, which simplifies the
learning system for experimenting, building and prototyping. We also provide Grove to
Pin Header Converter or Grove Base HAT available for variety developing platforms for
those who wants to use grove sensor and actuator modules without Grove System
Development Board.
Grove system users need to have at least some basic electronic knowledge
background, otherwise you need go through this basic tutorial to learn some basic
operations on the Grove system, the first part of this tutorial consists a list of basic
information on the components included in the starter kit, followed by the basic setup of
the Arduino IDE for Seeeduino Lotus. Then, the 11 tutorial sessions provide the basic
operation on each individual components in the starter kit and the applications by
combine multiple modules together, which gives learner some insight and basic
knowledge on hooking up and coding with the Grove system.
GROVE BASE KIT FOR RASPBERRY PI
Grove start kit contains one Grove Base Hat(for Raspberry Pi ) and 10 Grove modules.
The detailed information is listed below.
Product Detail
Grove Base Hat
Grove Base Hat for Raspberry Pi
Today, the grove series of sensors, actuators, and displays have grown into a large
family. More and more grove modules will join the Grove ecosystem in the future. We
see the Grove helps makers, engineers, teachers, students and even artists to build, to
make, to create...We always feel it is our responsibility to make the Grove module
compatible with more platforms. Now we bring you the Grove Base Hat for Raspberry Pi
and Grove Base Hat for Raspberry Pi Zero, in another word, we bring the Raspberry Pi
the Grove System.
The Grove Base Hat for Raspberry Pi provide Digital/Analog/I2C/PWM/UART port to
meet all your needs. With the help of build-in MCU, a 12-bit 8 channel ADC is also
available for Raspberry Pi.
Features
Support Raspberry ⅔B/3B+/Zero
build-in MCU
12-bit ADC
Multi-type Grove port
Hardware Overview
GPIO:The same pin out as the raspberry pi.
PWM:The Grove PWM Port connect to GPIO/BCM pin12(PWM0) and GPIO/BCM
pin13(PWM1), which is the hardware PWM pin of Raspberry Pi, in addition, you can use
all the GPIO pin as the soft PWM pin.
Note
All the silkscreen layer pin number besides the Grove port is the BCM pin number.
The difference between BCM pins and the physical pins please refer to here
Compared with hardware PWM, the software PWM isn't so accurate and will have
trouble at high frequencies.
The GPIO/BCM pin18 is also marked as PWM0, actually the GPIO/BCM 12 and the
GPIO/BCM 18 share the same PWM channel, so they can't set to different rate.
The audio jack output also uses PWM 0 and PWM 1, so you can't have audio
output on that socket and use the PWMs at the same time.
UART: The Grove UART port connect to the GPIO14(UART0 TX) and GPIO15(UART0
RX). UART is commonly used on the Pi as a convenient way to control it over the GPIO,
or access the kernel boot messages from the serial console (enabled by default).It can
also be used as a way to interface an Arduino, bootloaded ATmega, ESP8266, etc with
your Pi.
Digital:There are 6 digital Grove sockets in this board, normally the yellow wire(which
connect to the top pin of the 4 pins Grove socket as) of Grove cable is the signal wire,
so we name the digital Grove port D5/D16/D18/D22/D24/D26.
Analog:As we know, there is no ADC in the Raspberry Pi, so it can not work with
analog sensor directly. Now with the help of the build-in MCU STM32, the Grove base
hat can work as an external 12-bit ADC, which means you can use analog sensor with
your Raspberry Pi. Even more pleasing is that not one but four analog Grove sockets
are available. The analog sensor inputs the analog voltage into the 12-bit ADC. After the
ADC convert the analog data to digital data, it input the digital data to the Raspberry Pi
through the I2C interface.
I2C:There are three I2C port available in this board, they all connect to the I2C pin of
the raspberry directly. You can consider this part as an I2C hub. Most of seeed's new
grove modules have I2C interface, you may find those three port is extremely useful.
SWD: We use SWD port to burn the firmware to this hat. In addition, you can see 3
GPIO pins in this section, i.e., pin 9/pin 10/pin 11. Those three pins do not used by any
Grove port, you are free to use them without worrying about pin conflicts.
Grove Modules
Grove - Buzzer
This module uses piezo buzzer as the main component, it can produce high pitch tone
while it is connected to digital output and logic level set to High, otherwise it can
produce various tones according to the frequencies generated from the Analog PWM
output that connected to it. (note: the frequency range that normal human ear can
distinguish is between 20 Hz and 20kHz.)
Grove - Red LED Button
The Grove - LED Button is composed of Grove - Yellow Button, Grove - Blue LED
Button and Grove - Red LED Button. This button is stable and reliable with a 100 000
times long life. With the build-in LED, you can apply it to many interesting projects, it is
really useful to use the LED to show the status of the button.
Grove - Light Sensor
The Grove - Light sensor integrates a photo-resistor(light dependent resistor) to detect
the intensity of light. The resistance of photo-resistor decreases when the intensity of
light increases. A dual OpAmp chip LM358 on board produces voltage corresponding to
intensity of light(i.e. based on resistance value). The output signal is analog value, the
brighter the light is, the larger the value.
Grove - Moisture Sensor
This Moisture Senor can be used for detecting the moisture of soil or judge if there is
water around the sensor, let the plant in your garden able to reach out for human's help
when they are thirsty. This sensor is very easy to use, you can just simply insert in into
the soil and read the data. With this sensor, you can make a small project that can let
the plant send a message to you like " I am thirsty now, please feed me some water."
Grove - mini PIR motion sensor
Grove - mini PIR motion sensorallows you to sense motion, usually human movement in
its range. Simply connect it to Grove - Base shield and program it, when anyone moves
in its detecting range, the sensor will output HIGH on its SIG pin.
Grove - Servo
Grove - Servo is DC motor with gearing and feedback system. It is used in driving
mechanism of robots. The module is a bonus product for Grove lovers. We regulated
the three-wire servo into a Grove standard connector. You can plug and play it as a
typical Grove module now, without jumper wires clutter.
Grove - Temperature & Humidity Sensor (DHT11)
This temperature & humidity sensor provides a pre-calibrated digital output. A unique
capacitive sensor element measures relative humidity and the temperature is measured
by a negative temperature coefficient (NTC) thermistor. It has excellent reliability and
long term stability. Please note that this sensor will not work for temperatures below 0
degree.
Grove - Relay
The Grove-Relay module is a digital normally-open switch. Through it, you can control
circuit of high voltage with low voltage, say 5V on the controller. There is an indicator
LED on the board, which will light up when the controlled terminals get closed.
Grove - Ultrasonic Ranger
This Grove - Ultrasonic ranger is a non-contact distance measurement module which
works at 40KHz. When we provide a pulse trigger signal with more than 10uS through
singal pin, the Grove_Ultrasonic_Ranger will issue 8 cycles of 40kHz cycle level and
detect the echo. The pulse width of the echo signal is proportional to the measured
distance. Here is the formula: Distance = echo signal high time * Sound speed
(340M/S)/2. Grove_Ultrasonic_Ranger's trig and echo singal share 1 SIG pin.
Grove - 16 x 2 LCD (White on Blue)
This Grove – 162 LCD module is a 16 Characters 2 Lines LCD display, it uses I2C bus
interface to communicate with the development board, thus these will reduce the pin
header from 10 to 2 which is very convenient for the Grove system. This LCD display
module also supports customise characters, you can create and display heart symbol or
stick-man on this LCD module through a simple coding configuration.
GETTING STARTED
Minimum Requirement
micro USB cable
Raspberry Pi
SD card
Grove Base Kit for Raspberry Pi
Basic Tutorial
Arduino IDE basic setup
How to burn a Raspbian image
1. Raspbian Stretch download
Download Raspbian Stretch from Raspberry Pi official website and select “with desktop
and recommended software” version.
2. Win32 Disk Imager
Download the Win32 Disk Imager from the Sourceforge Project page as an installer
file, and run it to install the software.
Insert the SD card into your SD card reader and connect to your PC.
Run the Win32DiskImager utility from your desktop or menu.
In the device box, select the corresponding drive letter of the SD card. Be careful to
select the correct drive: if you choose the wrong drive you could destroy the data on
your computer's hard disk! If you are using an SD card slot in your computer, and
can't see the drive in the Win32DiskImager window, try using an external SD
adapter.
Click 'Write' and wait for the write to complete.
Complete.
Exit the imager and eject the SD card.
Basic Configuration
Wireless connection and SSH
1. Create a file called "wpa_supplicant.conf" into the /boot folder, and copy the following
code.
1country=CN
2ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
3update_config=1
4
5network={
6ssid="WiFi-name"
7psk="WiFi-password"
8key_mgmt=WPA-PSK
9priority=1
10}
Note
The Wi-Fi name and password should be the same as your local Wi-Fi which your PC
connected to(make sure your PC and Raspberry Pi are in the same LAN).
2. Create a blank file called "ssh" into the /boot folder.
3. Insert the SD Card with Raspbian into the Raspberry Pi
4. Connect the Raspberry Pi to the power source and power it up.
5. Open putty to connect PC to Raspberry Pi.
Download putty: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
Raspberry Pi Default username : pi Default password : raspberry
VNC Configuration
1. Open raspi-config by typing following command in terminal.
1sudo raspi-config
Arrow down to 5 interfacing Options and press "enter" to select.
Arrow down to P3 VNC and press "enter" to select.
Select "Yes" to enable it.
Select "Ok".
**2. ** Install VNC Viewer
Downloadr VNC Viewe
Open VNC Viewer and enter the IP address of Raspberry Pi. You can find the IP
address by typing ++ifconfig++ command in the terminal of Raspberry Pi (or you can
enter raspberrypi.local).
Note
If you use raspberrypi.local to login your Pi, you should make sure there is only one
Raspberry Pi in use in your LAN.
Enter the default user name and password, and now you can enter the Raspberry Pi's
remote desktop!
Success!
Base Hat Configuration
1. Shutdown the Raspberry Pi
1sudo shutdown -h now
Plug the Grove Base Hat for Raspberry Pi into the Raspberry Pi.
**2. **Power up the Raspberry Pi with micro-usb cable to enable I2C
Open raspi-config by typing following command in terminal.
1sudo raspi-config
Arrow down to 5 interfacing Options and press "enter" to select.
Arrow down to P5 I2C and press "enter" to select.
Select "Yes" to enable it.
Select "Ok".
Select "Finish" to save the changes.
3. One-click installation, quick start, what ever you call, with the single command below.
1curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh |
sudo bash -s -
if everything goes well, you will see the following notice.
1Successfully installed grove.py-0.6
2#######################################################
!!!!!
3Lastest Grove.py from github install complete
4#######################################################
4. Besides the one-click installation, you can also install all the dependencies).
5. Clone the latest python.py repository library.
1git clone https://github.com/Seeed-Studio/grove.py
Grove – LED button demo
After all the basic set up of Raspberry Pi, we can now run the LED demo code. Note:
You should complete the steps above first in order to continue the following.
Hardware Connection
Step 1: Connect the Grove - Red LED Button to D5 port of Base Hat
Step 2: Insert Base Hat into Raspberry Pi
Step 3: Connect Raspberry Pi to the power source by a micro USB cable.
Upload Code
Step 1: Run the following commands to create a python file
1cd grove.py
2nano example.py
Step 2: Copy following code in python file
Caution
Please make sure the text editor is under unix format.
1#!/usr/bin/env python
2
3import time
4from grove.grove_ryb_led_button import GroveLedButton
5
6def main():
ledbtn = GroveLedButton(5)
7
8
while True:
9
ledbtn.led.light(True)
10
time.sleep(1)
11
12
ledbtn.led.light(False)
13
time.sleep(1)
14
15
16if __name__ == '__main__':
main()
17
Step 3:run the program
1sudo chmod +x
example.py
2sudo ./example.py
When you single click the LED button, LED will change to "ON" mode, "OFF" if you long
press it. If you double click the LED button, the LED will bink.
1pi@raspberrypi:~/grove.py $ sudo ./example.py
2turn on LED
3turn on LED
4turn off LED
5turn on LED
LED
6blink
7^CTraceback (most recent call last):
8 File "./example.py", line 17, in
main()
9
10 File "./example.py", line 14, in main
time.sleep(1)
11
12KeyboardInterrupt
13pi@raspberrypi:~/grove.py $
Explanation of the blink code
In python, as modules are referenced to each other, different modules may have
different "main" definition, and there can only be one entry program each time. The
selection of the entry program depends on the value of name. "if__name__=='main'" is
equal, it means it is the entry of the python emulation.
1if __name__ == '__main__':
main()
2
Grove Base Kit for Raspberry Pi
Now, are you ready to explore the Grove system? We have designed 8 tutorials for you
to start with some basic Grove modules. This section introduces you how modules can
be combined and applied in real-life applications.
Prerequisite
To start on the Grove tutorial, you are required the fundamental knowledge of
Raspberry Pi and Python programming language. Please make sure you have
completed the basic setup tutorial above successfully and finished the LED Blink demo
and ensure it is fully working with your Raspberry Pi with the Grove Base Hat.
Learning outcome
Be able to use Grove Base Hat to build applications with Grove modules.
Be able to demonstrate each components of Grove Starter Kit and utilise the relevant
module to your own projects after this tutorial
Be able to identify the type of modules include in this Kit and their applications.
Understand the difference between the analog and digital signal.
Lesson 1: Buzzer
Objective
Using buzzer to generate some noise and also setting specific frequency to produce
some tones.
Hardware requirement
Self-prepare
micro-USB cable
Raspberry Pi 3 Model B
Computer
Included in the kit
Grove Base Hat
Grove cable
Grove – Buzzer
Hardware connection
Step 1. Use Grove cable to connect Grove - Buzzer to PWM port of Base Hat and insert
the Hat to the Raspberry Pi.
Step 2. Connect Raspberry Pi to the power source by a micro USB cable.
Software programming
Note
Please make sure you have cloned the python.py repository library to your Raspberry
Pi.
Step 1: Run the following commands to create a python file
1cd grove.py
2nano lesson_1.py
Step 2: Copy following code
1#!/usr/bin/env python
2import time
3from mraa import getGpioLookup
4from upm import pyupm_buzzer as upmBuzzer
5
6def main():
# Grove - Buzzer connected to PWM port
7
buzzer = upmBuzzer.Buzzer(getGpioLookup('GPIO12'))
8
9
CHORDS = [upmBuzzer.BUZZER_DO, upmBuzzer.BUZZER_RE,
10
11upmBuzzer.BUZZER_MI,
upmBuzzer.BUZZER_FA, upmBuzzer.BUZZER_SOL, upmBuzzer.BUZZER_LA,
12
upmBuzzer.BUZZER_SI]
13
for i in range(0, len(CHORDS)):
14
buzzer.playSound(CHORDS[i], 500000)
15
time.sleep(0.1)
16
17
del buzzer
18
print('application exiting...')
19
20
21if __name__ == '__main__':
main()
Step 3:run the program
1sudo chmod +x lesson_1.py
2sudo ./lesson_1.py
If everything goes well, you should notice the buzzer is making “Do Re Mi Fa So La Si”
sound.
Lesson 2: Red LED Button
Objective
Use Grove - Red LED Button to control the blinking of LEDs and let Grove - Buzzer to
make different sound effects.
Hardware requirement
Self-prepare
micro-USB cable
Raspberry Pi 3 Model B
Computer
Included in the kit
Grove Base Hat
Grove cable
Grove - Red LED Button
Grove – Buzzer
Hardware connection
Step 1. Use Grove cable to connect Grove - Buzzer to PWM port and Grove - Red LED
Button to D5 of Base Hat and insert the Hat to the Raspberry Pi.
Step 2. Connect Raspberry Pi to the power source by a micro USB cable.
Software programming
Note
Please make sure you have cloned the python.py repository library to your Raspberry
Pi.
Step 1: Run the following commands to create a python file
1cd grove.py
2nano lesson_2.py
Step 2: Copy following code
1#!/usr/bin/env python
2
3import time
4from mraa import getGpioLookup
5from upm import pyupm_buzzer as upmBuzzer
6
7from grove.button import Button
8from grove.grove_ryb_led_button import GroveLedButton
9
10def main():
# Grove - LED Button connected to port D5
11
button = GroveLedButton(5)
12
13
# Grove - Buzzer connected to PWM port
14
buzzer = upmBuzzer.Buzzer(getGpioLookup('GPIO12'))
15
16
def on_event(index, event, tm):
17
if event & Button.EV_SINGLE_CLICK:
18
print('single click')
19
button.led.light(True)
20
buzzer.playSound(upmBuzzer.BUZZER_DO, 500000)
21
22
elif event & Button.EV_LONG_PRESS:
23
print('long press')
24
button.led.light(False)
25
buzzer.playSound(upmBuzzer.BUZZER_DO, 1000000)
26
27
button.on_event = on_event
28
29
while True:
30
time.sleep(1)
31
32
33if __name__ == '__main__':
main()
34
Step 3:run the program
1sudo chmod +x lesson_2.py
2sudo ./lesson_2.py
Success
If everthing goes well, you will find that when you long press the LED button, the LED
will go off and the buzzer will emit a long "Do" sound. However, when you single press
it, the LED will light up and the buzzer will make a short "Do" sound.
1pi@raspberrypi:~/grove.py $
2single click
3single click
4single click
5long press
6single click
7long press
8long press
9Traceback (most recent call
10 File "./lesson2.py", line
main()
11
12 File "./lesson2.py", line
time.sleep(1)
13
14KeyboardInterrupt
15^Cpi@raspberrypi:~/grove.py
sudo ./lesson_2.py
last):
34, in
31, in main
$
Lesson 3: Light Sensor
Objective
In this lesson, we will show you how to use Grove - Light Sensor to control Grove Servo. In this case, servo roration angle varies with light intensity.
Hardware requirement
Self-prepare
micro-USB cable
Raspberry Pi 3 Model B
Computer
Included in the kit
Grove Base Hat
Grove cable
Grove - Light Sensor
Grove – Servo
Hardware connection
Step 1 Connect Grove - Light Sensor to port A0,Grove - Servo to PWM port.
Step 2 Insert Base Hat into Raspberry Pi.
Step 3 Connect Raspberry Pi to the power source by a micro USB cable.
Software programming
Note
Please make sure you have cloned the python.py repository library to your Raspberry
Pi.
Step 1: Run the following commands to create a python file
1cd grove.py
2nano lesson_3.py
Step 2: Copy following code
1#!/usr/bin/env python
2
3import time
4
5from grove.grove_servo import GroveServo
6from grove.grove_light_sensor_v1_2 import GroveLightSensor
7
8def main():
# Grove - Servo connected to PWM port
9
servo = GroveServo(12)
10
11
# Grove - Light Sensor connected to port A0
12
sensor = GroveLightSensor(0)
13
14
while True:
15
angle = sensor.light * 180 / 1000
16
print('light value {}, turn to {} degree.'.format(sensor.light,
17
18angle))
servo.setAngle(angle)
19
20
time.sleep(1)
21
22
23if __name__ == '__main__':
main()
Step 3:run the program
1sudo chmod +x lesson_3.py
2sudo ./lesson_3.py
If everything goes well, the change of light intensity will result in different rotation angle
of servo.
1pi@raspberrypi:~/grove.py $ sudo ./lesson_3.py
2light value 300, turn to 113 degree.
3light value 80, turn to 80 degree.
4light value 166, turn to 165 degree.
5light value 498, turn to 132 degree.
6light value 601, turn to 60 degree.
7light value 200, turn to 21 degree.
8light value 459, turn to 99 degree.
9light value 172, turn to 173 degree.
10light value 319, turn to 138 degree.
11^CTraceback (most recent call last):
12 File "./lesson3.py", line 23, in
main()
13
14 File "./lesson3.py", line 20, in main
time.sleep(1)
15
16KeyboardInterrupt
17pi@raspberrypi:~/grove.py $
Lesson 4: Motion Sensor & Relay
Objective
Use Grove - mini PIR motion sensor to detect the motion, light on if people come.
Hardware requirement
Self-prepare
micro-USB cable
Raspberry Pi 3 Model B
Computer
Included in the kit
Grove Base Hat
Grove cable
Grove - mini PIR motion sensor
Grove - Relay
Hardware Connection
Step 1 Connect Grove - mini PIR motion sensor to port D5, Grove - Relay to port D16 of
Base Hat.
Step 2 Insert Base Hat into Raspberry Pi
Step 3 Connect Raspberry Pi to the power source by a micro USB cable.
Software programming
Note
Please make sure you have cloned the python.py repository library to your Raspberry
Pi.
Step 1: Run the following commands to create a python file
1cd grove.py
2nano lesson_4.py
Step 2: Copy following code
1#!/usr/bin/env python
2
3import time
4
5from grove.grove_mini_pir_motion_sensor import GroveMiniPIRMotionSensor
6from grove.grove_relay import GroveRelay
7
8def main():
# Grove - mini PIR motion sensor connected to port D5
9
sensor = GroveMiniPIRMotionSensor(5)
10
11
# Grove - Relay connected to port D16
12
relay = GroveRelay(16)
13
14
def on_detect():
15
print('motion detected')
16
17
relay.on()
18
print('relay on')
19
20
time.sleep(1)
21
22
relay.off()
23
print('relay off')
24
25
sensor.on_detect = on_detect
26
27
while True:
28
time.sleep(1)
29
30
31if __name__ == '__main__':
main()
32
Step 3:run the program
1sudo chmod +x lesson_4.py
2sudo ./lesson_4.py
If everything goes well, you should see the relay on/off once it detect a motion.
1pi@raspberrypi:~/grove.py $ sudo ./lesson_4.py
2motion detected
3relay on
4relay off
5motion detected
6relay on
7relay off
8^CTraceback (most recent call last):
9 File "./lesson_4.py", line 33, in
main()
10
11 File "./lesson_4.py", line 30, in main
time.sleep(1)
12
13KeyboardInterrupt
14pi@raspberrypi:~/grove.py $
Lesson 5: Ultrasonic Sensor & Relay
Objective
In this lesson, we use Grove - Ultrasonic Ranger to detect the distance, once someone
getting closer, the light on the Grove - Relay should be "ON".
Hardware requirement
Self-prepare
micro-USB cable
Raspberry Pi 3 Model B
Computer
Included in the kit
Grove Base Hat
Grove cable
Grove - Ultrasonic Ranger
Grove - Relay
Hardware connection
Step 1 Connect Grove - Ultrasonic Ranger to port D5, Grove - Relay to port D16 of
Base Hat.
Step 2 Insert Base Hat into Raspberry Pi
Step 3 Connect Raspberry Pi to the power source by a micro USB cable.
Software programming
Note
Please make sure you have cloned the python.py repository library to your Raspberry
Pi.
Step 1: Run the following commands to create a python file
1cd grove.py
2nano lesson_5.py
Step 2: Copy following code
1#!/usr/bin/env python
2
3import time
4
5from grove.grove_relay import GroveRelay
6from grove.grove_ultrasonic_ranger import GroveUltrasonicRanger
7
8def main():
# Grove - Ultrasonic Ranger connected to port D5
9
sensor = GroveUltrasonicRanger(5)
10
11
# Grove - Relay connected to port D16
12
relay = GroveRelay(16)
13
14
while True:
15
distance = sensor.get_distance()
16
print('{} cm'.format(distance))
17
18
if distance < 20:
19
relay.on()
20
print('relay on')
21
22
time.sleep(1)
23
24
relay.off()
25
print('relay off')
26
27
continue
28
29
time.sleep(1)
30
31
32if __name__ == '__main__':
main()
33
Step 3:run the program
1sudo chmod +x lesson_5.py
2sudo ./lesson_5.py
If everything goes well, the change of light intensity will result in different rotation angle
of servo.
1pi@raspberrypi:~/grove.py $ sudo ./lesson_5.py
2253.722585481 cm
3253.739028141 cm
4252.896341784 cm
51.20442489098 cm
6relay on
7relay off
84.51762100746 cm
9relay on
10relay off
11253.985668051 cm
12^CTraceback (most recent call last):
13 File "./lesson_5.py", line 34, in
main()
14
15 File "./lesson_5.py", line 31, in main
time.sleep(1)
16
17KeyboardInterrupt
18pi@raspberrypi:~/grove.py $
Now, compare the result from lesson four and lesson five, are you able to list the
advantages and disadvantages of Grove - mini PIR motion sensor and Grove Ultrasonic
Ranger?
Lesson 6: LCD
Objective
Uses Grove - 16*2 LCD screen to display “Hello World”.
Hardware requirement
Self-prepare
micro-USB cable
Raspberry Pi 3 Model B
Computer
Included in the kit
Grove Base Hat
Grove cable
Grove - 16*2 LCD
Hardware connection
Step 1 Connect Grove - 16*2 LCD to I2C port of Base Hat.
Step 2 Insert Base Hat into Raspberry Pi.
Step 3 Connect Raspberry Pi to the power source by a micro USB cable.
Software programming
Note
Please make sure you have cloned the python.py repository library to your Raspberry
Pi.
Step 1: Run the following commands to create a python file
1cd grove.py
2nano lesson_6.py
Step 2: Copy following code
1#!/usr/bin/env python
2
3import time
4
5from grove.display.jhd1802 import JHD1802
6
7def main():
# Grove - 16x2 LCD(White on Blue) connected to I2C port
8
lcd = JHD1802()
9
10
lcd.setCursor(0, 0)
11
lcd.write('hello, world!!!')
12
13
print('application exiting...')
14
15
16if __name__ == '__main__':
main()
17
Step 3:run the program
1sudo chmod +x lesson_6.py
2sudo ./lesson_6.py
You should see “hello, world!!!” displayed on the LCD screen.
If you want to use the Grove - 16*2 LCD screen to display some other charaters, you
can simply change ++ lcd.write('hello, world!!!')++ in the code.
Lesson 7: LCD & Temperature and Humidity Sensor
Objective
Uses Grove - 16*2 LCD screen to display data(temperature and humidity) from Grove Temperature and Humidity Sensor
Hardware requirement
Self-prepare
micro-USB cable
Raspberry Pi 3 Model B
Computer
Included in the kit
Grove Base Hat
Grove cable
Grove - 16*2 LCD
Grove - Temperature and Humidity Sensor
Hardware connection
Step 1 Connect Grove - 16*2 LCD to I2C port,Grove - Temperature and Humidity
Sensor to port D5.
Step 2 Insert Base Hat into Raspberry Pi.
Step 3 Connect Raspberry Pi to the power source by a micro USB cable.
Software programming
Note
Please make sure you have cloned the python.py repository library to your Raspberry
Pi.
Step 1: Run the following commands to create a python file
1cd grove.py
2nano lesson_7.py
Step 2: Copy following code
1#!/usr/bin/env python
2
3import time
4
5from grove.grove_temperature_humidity_sensor import DHT
6from grove.display.jhd1802 import JHD1802
7
8def main():
# Grove - 16x2 LCD(White on Blue) connected to I2C port
9
lcd = JHD1802()
10
11
# Grove - Temperature&Humidity Sensor connected to port D5
12
sensor = DHT('11', 5)
13
14
while True:
15
humi, temp = sensor.read()
16
print('temperature {}C, humidity {}%'.format(temp, humi))
17
18
lcd.setCursor(0, 0)
19
lcd.write('temperature: {0:2}C'.format(temp))
20
21
lcd.setCursor(1, 0)
22
lcd.write('humidity: {0:5}%'.format(humi))
23
24
time.sleep(1)
25
26
27if __name__ == '__main__':
main()
28
Step 3:run the program
1sudo chmod +x lesson_7.py
2sudo ./lesson_7.py
If everthing goes well, you should see current temperature and humidity values display
on the LCD screen
1pi@raspberrypi:~/grove.py
2temperature 23C, humidity
3temperature 22C, humidity
4temperature 22C, humidity
$ sudo ./lesson_7.py
16%
17%
17%
5^CTraceback (most recent call last):
6 File "./lesson_7.py", line 28, in
main()
7
8 File "./lesson_7.py", line 25, in main
time.sleep(1)
9
10KeyboardInterrupt
11pi@raspberrypi:~/grove.py $
Lesson 8: LCD & Moisture Sensor & Buzzer
Objective
Use Grove - 16 * 2 LCD to display the current moisture level. When the moisture status
is "wet", the Grove - Buzzer should alert you.
Hardware requirement
Self-prepare
micro-USB cable
Raspberry Pi 3 Model B
Computer
Included in the kit
Grove Base Hat
Grove cable
Grove - 16*2 LCD
Grove - Moisture Sensor
Grove - Buzzer
Hardware Connection
Step 1 Connect Grove - 16*2 LCD to I2C port, Grove - Moisture Sensor to A0 port and
Grove - Buzzer to PWM port of Grove Base Hat.
Step 2 Insert Base Hat to Raspberry Pi.
Step 3 Use micro USB to connect Raspberry Pi with PC.
Software programming
Note
Please make sure you have cloned the python.py repository library to your Raspberry
Pi.
Step 1: Run the following commands to create a python file
1cd grove.py
2nano lesson_8.py
Step 2: Copy following code
1#!/usr/bin/env python
2
3import time
4from mraa import getGpioLookup
5from upm import pyupm_buzzer as upmBuzzer
6
7from grove.grove_moisture_sensor import GroveMoistureSensor
8from grove.lcd.sh1107g import JHD1802
9
10def main():
# Grove - 16x2 LCD(White on Blue) connected to I2C port
11
lcd = JHD1802()
12
13
# Grove - Moisture Sensor connected to port A0
14
sensor = GroveMoistureSensor(0)
15
16
# Grove - Buzzer connected to port PWM
17
buzzer = upmBuzzer.Buzzer(getGpioLookup('GPIO12'))
18
19
while True:
20
mois = sensor.moisture
21
if 0