TIPS 2025年4月24日

How to Easily Read Temperature, Humidity, and Air Pressure with a Raspberry Pi and TDSN7200

Introduction

With Tokyo Devices’ USB sensor, the TDSN7200, you can easily measure temperature, humidity, and air pressure. In this guide, we’ll walk through how to set things up on a Raspberry Pi, install the required tools, and use Python to read sensor data—all explained step-by-step.

1. What is the TDSN7200 Sensor?

The TDSN7200 is a compact USB sensor capable of accurately measuring temperature, humidity, and pressure. It’s designed to work seamlessly with Raspberry Pi.

  • Temperature: -40 to 125°C (±0.2°C accuracy)
  • Humidity: 0 to 100%RH (±1.8%RH accuracy)
  • Pressure: 260 to 1,260hPa (±0.1hPa accuracy)

2. What You’ll Need Before Getting Started

  • A Raspberry Pi with Raspberry Pi OS installed
  • Internet connection (Wi-Fi or Ethernet)
  • Python 3 (usually pre-installed)

3. Installing the Required Tools

Run the following commands on your Raspberry Pi to install the necessary tools:

 sudo apt update
 sudo apt install -y git build-essential libusb-dev python3 python3-pip
  • git is used to download the source code.
  • build-essential provides tools to build from source.
  • libusb-dev is the library needed to work with USB devices.

4. Setting USB Permissions

To allow regular users to access the USB sensor, set up the following rule.
Here, 32ee and 177d are the vendor and product IDs for the TDSN7200:

 sudo tee /etc/udev/rules.d/99-usb-tokyodevices.rules <<EOF
 SUBSYSTEM=="usb", ATTR{idVendor}=="32ee", ATTR{idProduct}=="177d", MODE="0666"
 EOF

Apply the rule with:

 sudo udevadm control --reload-rules
 sudo udevadm trigger

5. Building the Sensor Command Tool (td-usb)

Download the td-usb command-line tool from GitHub and build it:

 git clone https://github.com/tokyodevices/td-usb.git
 cd td-usb
 make

Test it to make sure it’s working:

 ./td-usb
 # → If you see version info, it’s working!

6. Getting Sensor Data with Python

Create the following Python script to read sensor data every 10 seconds:

 #!/usr/bin/env python3
 import subprocess
 import time

 def read_sensor():
     result = subprocess.run(['td-usb', 'tdsn7200', 'get'], capture_output=True, text=True)
     if result.returncode != 0:
         print("An error occurred:", result.stderr.strip())
         return

     temp, hum, pres = result.stdout.strip().split(',')
     print(f"Temperature: {temp} °C, Humidity: {hum} %RH, Pressure: {pres} hPa")

 if __name__ == "__main__":
     print("Starting sensor readings. Press Ctrl+C to stop.")
     try:
         while True:
             read_sensor()
             time.sleep(10)
     except KeyboardInterrupt:
         print("\nStopped reading sensor data.")

7. Wrapping Up

Now you know how to easily read temperature, humidity, and pressure using a Raspberry Pi and the TDSN7200 sensor. Try using this setup for experiments, research, or your next DIY project!

この記事に関連する商品

この記事をシェア

最近のTIPS