0% found this document useful (0 votes)
56 views13 pages

Practical 5B - Grove Base HAT

Uploaded by

black hello
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views13 pages

Practical 5B - Grove Base HAT

Uploaded by

black hello
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

BAIT2123 INTERNET OF THINGS Jul 2024

Practical 5 B - Grove Base HAT

Objective
Understand Raspberry Pi, Grove Pi module and sensor features.

PART 1: Getting know more about Raspberry Pi

Difference between Raspberry Pi version 3B and 4:

Raspberry Pi 3B / 3B+ Raspberry Pi 4


1.2GHz Cortex-A53 64-bits quad core 1.5GHz Cortex-A72 64-bits quad core
1GB LPDDR2 SDRAM 2 / 4 / 8GB LPDDR4 SDRAM
HDMI Port 2 Micro HDMI Ports
Power supply using 2.5A micro-USB (Type B) Port Power supply using 3A+ USB Type-C Port
4 USB 2.0 Ports 2 USB 3.0 Ports, 2 USB 2.0 Ports

There are two ways of setting up the Raspberry Pi: Using microSD card OR USB pendrive with
OS (Legacy) Full Debian Bullseye with desktop environment and pre-installed libraries

Students will be given a microSD card OR USB pendrive (Either One Only)
- Insert microSD card into the Raspberry Pi microSD card slot /
USB pendrive to USB3.0 (blue) top port.
- Connect the macro HDMI (or HDMI) to the monitor using a converter.
- Connect the USB keyboard and mouse
- Connect the Pi power supply to the power socket and turn on
BAIT2123 INTERNET OF THINGS Jul 2024

Beware when using Raspberry Pi 4 microSD card:

Issue: After inserting the micro SD card into the Pi 4 (with casing) board’s card slot, DO NOT
tend to move the board out from its casing for GrovePi board installation (currently the board is
glued / screwed on the casing). At the same time, the Pi 4 sd card slot can be “spilled off /
spoiled” due to the weak design of the official Pi 4 casing.

Pi 4 Board with casing microSD card inserted

[RIGHT] microSD card slot spoiled when Pi 4 Board is removed from casing

Please go through the Practical 0 Precaution document and make sure you have fully
understood the content. Execute the rest of the practical work based on the learned
content in the Precaution document.
BAIT2123 INTERNET OF THINGS Jul 2024

PART 2: Getting Know the Grove Base Kit

The starter kit bundles the most popular sensors for education and hobbyists, and lets you start
playing and prototyping hardware with Raspberry Pi. The Grove Base Kit package includes:

● Grove Base Hat Board


● Grove cables for connecting the sensors and modules to the Grove Base Hat Board.
● Grove sensors and modules (Please request from lab assistant when it is required)

Sensors and modules include

Grove Base Hat Board Grove - Red LED Button

Grove Digital Humidity and


Grove Light Sensor
Temperature (DHT) Sensor

Grove Relay Grove Ultrasonic Ranger

Grove Buzzer Grove Moisture sensor

Grove LCD (White on Blue) Grove Servo

And more … please consult lab assistant for


Grove - Mini PIR Motion Sensor
sensor’s availability

Getting started with the GrovePi for the first time is easy:
● Check out our Quickstart guide to Grove Base Kit here.
● Check out our Quickstart guide to Grove Base Hat Board here.

Connected Grove Base Hat Board on the Raspberry Pi

First, identify the mounted Grove Base Hat Board on the Raspberry Pi. The Grove Base Hat
Board has a black plastic piece on the bottom, which fits perfectly with the 40 metal pins sticking
out of the Raspberry Pi. Slide the Grove Base Hat Board onto the pins on the Raspberry Pi as
shown in the pictures below. The Grove Base Hat Board fits both the Raspberry Pi 3, 4 and 5.

Ensure that the pins are properly aligned when stacking the GrovePi, and pushed down until
they go in all the way.
BAIT2123 INTERNET OF THINGS Jul 2024

INCORRECT installation will cause the


Raspberry Pi / Grove Base Hat Board spoil.

Raspberry Pi Board (Left) Grove Base Hat Board (Right)

Gently fix all the 40 pins on the Raspberry Pi Board.


Ensure the pins are fully “Push In” completely (not hanging halfway).

An installed Grove Base Hat Board on the Raspberry Pi Board.


BAIT2123 INTERNET OF THINGS Jul 2024

PART 3: Installing the Grove Base Kit Library in Raspbian Bullseye


(* not applicable in Bookworm)

* IF the microSD card / USB Pendrive obtained from the lab, please skip this PART 3.
* This part is for new Pi users with a new microSD card.

If Grove Base Kit software has not been installed.


- Connected Grove Base Hat Board on the Raspberry Pi
- In a terminal, run

cd Desktop

git clone https://github.com/Seeed-Studio/grove.py


cd grove.py

According to the update on Seeed Studio Forum:


https://forum.seeedstudio.com/t/problems-running-modules-on-a-grove-raspberry-pi-hat/
259377/7
After the pandemic, due to a shortage of certain programmable chip, the Grove Base
Hat board was changed from using STM32F030F4P6TR (by year 2019, using i2c
address 0x04) to MM32F031F6P6 (beyond 2019, using i2c address 0x08), our
laboratory’s Grove Base Hat board is the earlier batch (i.e., i2c address 0x04).

Hence we use Thonny software, to change this ./Desktop/grove.pi/grove/adc.py file >


class ADC(object): def __init__(self, address = 0x08)to
class ADC(object): def __init__(self, address = 0x04)
Then only we install the grove library using the following command.

sudo pip3 install .

For bookworm Raspbian OS (due to error: externally-managed-environment), use the


following command:

sudo pip3 install . --break-system-packages


BAIT2123 INTERNET OF THINGS Jul 2024

- These steps are copying the grove library to the Desktop/grove.py folder and
installing it in the Raspbian Bullseye OS.

sudo apt remove python-rpi.gpio


sudo apt install python-rpi-lgpio

- The Raspbian Bookworm OS original gpio does not support digital read features
with responsive functions. A modified version of python-rpi.gpio, that is :
python-rpi-lgpio can be utilized to support the grove push-on button sensor.

If everything goes well, proceed to the next steps.

- Take note that: there are several example python codes that use the MRAA (pronounced
em-rah) and UPM (Useful Packages and Modules) libraries, not available for Bullseye
and above versions of Raspbian. For instance, grove/factory are not runnable in
Bullseyes and above versions of Raspbian.
BAIT2123 INTERNET OF THINGS Jul 2024

PART 4: Understanding on Grove Base Kit communication for reading data from sensors
and sending data to actuators / indicators

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 provides Digital/Analog/I2C/PWM/UART port to meet all
your needs. With the help of a built-in MCU, a 12-bit 8 channel ADC is also available for
Raspberry Pi.

Hardware Architecture

Grove Base Kit - Port Description

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
BAIT2123 INTERNET OF THINGS Jul 2024

● 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 be set to different rates.

● 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 connects 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, bootload 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 the 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 are not used by any Grove port,
you are free to use them without worrying about pin conflicts.
BAIT2123 INTERNET OF THINGS Jul 2024

Step 1: Create a folder under Linux Debian Operating system.

1. Launch the terminal and key in the following command line.


* or you can choose to use mouse, right click at the Desktop to create new folder

2. Set the permission of the test folder to be accessible and writable by anyone.
* Important step when you want to create / save files in any folder.

In Raspbian, we commonly use sudo (superuser do) to execute commands, especially


deal with file system modification.

Step 2: Create a new python file

* Python programming is very concerned with character spacing and case sensitive.

* There are minor errors on the provided codes throughout the practical notes as a part of

students’ assessment, that requires students to identify it based on logical programming skills.

1. Go to Menu > Programming and launch Thonny Python (IDE)

2. Save the untitled file to /Pi/Desktop/[YOUR_NAME]/ to create a new python file with a new
name: test01b.py
BAIT2123 INTERNET OF THINGS Jul 2024

* If you cannot save the file, maybe you have missed Step 1 for permission setting.

* Please always use Ctrl + C or Ctrl + Z is always the best way to stop the execution by
initiating KeyboardInterrupt.
BAIT2123 INTERNET OF THINGS Jul 2024

Step 3: Test on a LED Blink

- Connect the Grove - Red LED Button to D5 port of Base Hat

- Type the following code in your test01b.py

- Run the program

Task 1: Find a way to allow the program code to run and two ways to stop the program.

Task 2: Modify the program code for LED to blink faster or slower.
BAIT2123 INTERNET OF THINGS Jul 2024

Step 4: Test on Rotary Angle Sensor (Potentiometer)

- Connect the Grove - Rotary Angle Sensor to A0 (Analog) port of Base Hat

- In Thonny IDE, create a new python file, named “test02b.py”. Type the following code in
your test02b.py

- Run the program

Task 1: Set the LED light will be turn on only when light brightness is > 127
BAIT2123 INTERNET OF THINGS Jul 2024

Step 5: Test Button and Buzzer

- Connect Grove - Button to port D24,Grove - Buzzer to PWM port.

- In Thonny IDE, create a new python file, named “test03b.py”. Type the following code in
your test03b.py

- Run the program

Task 1: Modify the code to make the buzzer sound like SOS.

* Clue: explore how to make 3 long and 3 short buzzer sounds.

You might also like