Skip to content
Stand with Ukraine flag

Raspberry Pi with Grove Base Hat and ThingsBoard

This guide describes how to connect a Raspberry Pi with a Grove Base Hat to ThingsBoard over MQTT, collect data from Grove sensors, and control actuators from a ThingsBoard dashboard.

The Raspberry Pi runs a Python script that reads sensor data, sends telemetry to ThingsBoard, and responds to RPC commands for servo and LED control.

Hardware:

Software:

Connect the Grove modules to the Grove Base Hat using the following ports:

ModulePort on Grove Base Hat
Analog ServoPWM (12)
Mini PIR Motion Sensor v1.0D5
Ultrasonic Ranger v2.0D16
Red LED Button v1.0D18
Moisture Sensor v1.4A0
Light Sensor v1.2A2
Temperature & Humidity Sensor v1.2D22
  1. Follow the Grove Base HAT configuration guide to set up the Raspberry Pi.

  2. Install the ThingsBoard Python client SDK:

    Terminal window
    pip3 install tb-mqtt-client
  3. Clone and install the Seeed-Studio Grove library:

    Terminal window
    git clone https://github.com/Seeed-Studio/grove.py.git
    Terminal window
    pip3 install ./grove.py/
  4. If you are using the Temperature & Humidity Sensor (DHT11/DHT22), install the Seeed DHT library:

    Terminal window
    git clone https://github.com/Seeed-Studio/Seeed_Python_DHT.git
    Terminal window
    sudo python3 ./Seeed_Python_DHT/setup.py install
  1. Log in to ThingsBoard.
  2. Go to Entities ⇾ Devices and add a new device (e.g., name: Grove Main Device, type: grove).
  3. Open the device details and click Copy access token. Save this token — it will be used as ACCESS_TOKEN in the script.

Download the tb_grove.py script or use the code below.

Replace THINGSBOARD_HOST with your ThingsBoard server address. For ThingsBoard Cloud, use mqtt.thingsboard.cloud (North America) or mqtt.eu.thingsboard.cloud (Europe). Replace ACCESS_TOKEN with the token copied in the previous step.

#
# Copyright © 2019-2024 The Thingsboard Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

Download the Grove dashboard JSON and import it into ThingsBoard.
See the dashboard import instructions for details.

After importing, open the dashboard and edit the alias of the Grove widget: set Filter type to Single entity, set Type to Device, and select your grove device from the list.

Run the script on the Raspberry Pi:

Terminal window
python3 tb_grove.py

The script starts sending sensor telemetry to ThingsBoard. Open the dashboard to see live data and use the Servo knob to rotate the servo or the Button Led toggle to control the LED.