Temperature and humidity sensor on the Orange Pi

Connect the sensor to the Pi

Time for some physical computing on the Orange Pi Plus 2e! We will connect a temperature and humidity sensor to the Orange Pi and write and compile a C code snippet to display the sensor readings. Additionally, you will learn about the GPIO pins.

So for this idea we will use the GPIO pins. The Orange Pi Plus 2e has 40 pins, located on the side with the double USB and power inputs. The acronym GPIO stands for general purpose input-output. We can use these pins for a variety of physical computing and Internet of Things applications. For example, one can use the GPIO pins to communicate and send power to leds, sensors, motors, and even other micro-controllers, such as the Arduino. The pin layout for the Orange Pi Plus 2e is of the CON3 type, described in more detail here.

The DHT22 has 4 pins coming out of it, out of which only 3 are usable. One is for power in (VCC), another one is for data coming out (DATA) and one is a ground pin (GND).

First of all power off your Orange Pi when connecting the sensors. Using the female to female jumper wires connect the following pins (sensor to Pi):

DATA to PIN 7 (GPCLK)

GND to PIN 6 (GND)

VCC to PIN 1 (VCC-3.3V)

Here is the diagram:

And an actual picture:

For this project you can use the an identical setup to connect the DHT22 sensor to the Raspberry Pi 2 or Raspberry Pi 3, because the pins used in this example are in the same location as on the Orange Pi Plus 2e. Having set up the hardware we need to configure the software part.

Write the C code for the GPIO pins

To read the data sent by the sensor we can write a C program. Python is also an option and it would probably be quicker to write, but from what I gather the quality of the measurements are better in C. In order to do that we need to install a C library that will help us access the GPIO pins. For the Raspberry Pi’s we can get WiringPi. For the Orange Pi the corresponding library is called WiringOP. Install it by running this command in your home folder:

git clone https://github.com/zhaolei/WiringOP.git -b h3

Then, following the instructions on Github, run:

cd WiringOP
chmod +x ./build
sudo ./build

You can confirm the layout of the pins by running this command, that will output the GPIO table layout:

gpio readall

Now you are ready to write and compile a C script that reads data from the sensor. Change back to the home folder and open create a new C file called dht with nano:

Hi, thanks for your great example.
I used your dht.h/cpp files as the basis for a C++ application that can be run from crontab to output to a CSV file at regular intervals:https://github.com/pilkch/climbatize