Read SHTC3 Data
This section describes how to use VisionFive 2 or VisionFive 2 Lite's I2C to read SHTC3 data through an example program with Python.
Hardware Setup
Connect Sense HAT to the 40-pin header as follows.
| Sense HAT (B) | 40-Pin GPIO Header | |
|---|---|---|
| Pin Number | Pin Name | |
| 3V3 | 1 | 3.3V Power |
| GND | 9 | GND |
| SDA | 3 | GPIO58 (I2C SDA) |
| SCL | 5 | GPIO57 (I2C SCL) |
Run Demo Code
Perform the following steps on Debian of VisionFive 2 or VisionFive 2 Lite.
-
Locate the directory where the test code,
I2C_Sense_Hat.py, exists.-
Source into the PYthon3 Virtual Environment.
source ./myvenv/bin/activate -
Install the dependency.
python3 -m pip install pillow -
Get the directory where
VisionFive.gpioexists.python3 -m pip show VisionFive.gpioNote: The output depends on how the application is installed. -
Enter the
VisionFive.gpiodirectory.cd <VisionFive.gpiodirectory> -
Enter the
sample-codedirectory.cd ./VisionFive/sample-code/
-
Under the
sample-codedirectory, execute the following command to run the demo code.
Alternatively, you can also run the following command.sudo python I2C_Sense_Hat.py
The temperature and humidity data are displayed as follows.sudo python3 I2C_Sense_Hat.py[riscv@fedora-starfive sample-code]$ sudo python3 I2C_Sense_Hat.py i2c_dev: /dev/i2c-1 Temperature = 27.85°C , Humidity = 56.59 % Temperature = 27.83°C , Humidity = 56.60 % Temperature = 27.85°C , Humidity = 56.61 % Temperature = 27.86°C , Humidity = 56.60 % Temperature = 27.86°C , Humidity = 56.60 % Temperature = 27.80°C , Humidity = 56.60 % Temperature = 27.87°C , Humidity = 56.60 %Note: For details about the source code, see-
(Optional) Exit the Python3 Virtual Environment.
deactivate