B3RN0UT Posted August 16, 2017 Posted August 16, 2017 Hi, I'm trying to run a DHT22 Temperature & Humidity sensor on my Cubieboard2 but I seem to fail at the beginning on how to use the GPIO Pins correctly What I have: Cubieboard2 Armbian Linux version 4.11.6-sunxi (root@devel) (gcc version 7.1.1 20170510 (Linaro GCC 7.1-2017.05) DHT22 (worked on a Raspberry Pi3 before) What I've done so far: According to this Overview (http://docs.cubieboard.org/cubieboard1_and_cubieboard2_gpio_pin) I connected the sensor on 3v3, GND and on PD25 (LCDDE). As far as I understood the LCD pins can be also used for other things. Followed "Accessing the GPIO pins through sysfs with mainline kernel" (http://linux-sunxi.org/GPIO) => (position of letter in alphabet - 1) * 32 + pin number (4 - 1)*32 + 25 = 121 The example says I have to add again +25 to the example "E.g for PH18 this would be ( 8 - 1) * 32 + 18 = 224 + 18 = 242 (since 'h' is the 8th letter)." => So 121+25 = 146 should be my correct value Since it's a sensor I guess I've to use "in" as direction. root@cubieboard2:/sys/class/gpio# echo 146 > /sys/class/gpio/export root@cubieboard2:/sys/class/gpio# echo "in" > /sys/class/gpio/gpio146/direction bash: echo: write error: Unknown error 517 Tried it also with the 121 value as the formula mentioned it (no error), expected here another value than 1 root@cubieboard2:/sys/class/gpio# echo 121 > /sys/class/gpio/export root@cubieboard2:/sys/class/gpio# echo "in" > /sys/class/gpio/gpio121/direction root@cubieboard2:/sys/class/gpio# cat /sys/class/gpio/gpio121/value 1 Besides this I've seen that there are a lot of posts about attach DHT22 to Orange Pi or to BananaPi. Tried some of those but I'm completly lost to adapt those instructions with 1-wire or wiringpi to the cubieboard2. I know that on Raspberri Pi it's necessary to load the library for the Adafruit modules which where supported for BeagleBone black & RasPi. Does someone have some clues how to get this working or tried this by himself? Thanks in advance.
martinayotte Posted August 16, 2017 Posted August 16, 2017 2 hours ago, B3RN0UT said: I have to add again +25 Why ? This is not true ... Rely only on the linux-sunxi formula ...
B3RN0UT Posted August 16, 2017 Author Posted August 16, 2017 Quote E.g for PH18 this would be ( 8 - 1) * 32 + 18 = 224 + 18 = 242 (since 'h' is the 8th letter). In this example they add to the result again +18 so adapted to pin PD25: E.g for PD25 this would be ( 4 - 1) * 32 + 25 = 121 + 25 = 146 (since 'd' is the 4th letter). Did I missunderstood something at the example? Anyhow I've tried it without adding the additional +25, result see above. Thanks so far. Edit: Since I'm unsure what exactly is the mentioned Pin for the formular at the Cubieboard2 I've tried it also with using 32 as Pin. In the GPIO Overview PD25 is located at 32 => (4-1) * 32 + 32 = 128 root@cubieboard2:/home/monkey# echo 128 > /sys/class/gpio/export root@cubieboard2:/home/monkey# echo "in" > /sys/class/gpio/gpio128/direction root@cubieboard2:/home/monkey# cat /sys/class/gpio/gpio128/value 0
martinayotte Posted August 16, 2017 Posted August 16, 2017 1 hour ago, B3RN0UT said: E.g for PD25 this would be ( 4 - 1) * 32 + 25 = 121 + 25 = 146 (since 'd' is the 4th letter). Nope ! it should be read as : PD25 this would be ( 4 - 1) * 32 + 25 = 96 + 25 = 121 1 hour ago, B3RN0UT said: I'm unsure what exactly is the mentioned Pin No, it is not header pin number but GPIO name
B3RN0UT Posted August 16, 2017 Author Posted August 16, 2017 Oops, I just went forward through the formular didn't validate the interim result Thanks for clear the ment GPIO Pin, so I have to use 121 root@cubieboard2:/sys/class/gpio# echo 121 > /sys/class/gpio/export root@cubieboard2:/sys/class/gpio# echo "in" > /sys/class/gpio/gpio121/direction root@cubieboard2:/sys/class/gpio# cat /sys/class/gpio/gpio121/value 1 If I unplug the sensor I got the following: root@cubieboard2:/sys/class/gpio# cat /sys/class/gpio/gpio121/value 0 So it seems that I'm talking with the correct Pin Next step is how to get correct values of the sensor?
martinayotte Posted August 16, 2017 Posted August 16, 2017 Maybe using this library : https://github.com/adafruit/Adafruit_Python_DHT
B3RN0UT Posted August 16, 2017 Author Posted August 16, 2017 I tried the following dht22.py #!/usr/bin/env python import Adafruit_DHT sensor = Adafruit_DHT.DHT22 gpio = gpio121 humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio) print 'Temperature: {0:0.1f}*C Humidity: {1:0.1f}%'.format(temperature,humidity) Quote ./dht22.py Traceback (most recent call last): File "./dht22.py", line 7, in <module> gpio = gpio121 NameError: name 'gpio121' is not defined gpio121 is the name of the GPIO-Pin to which I want to talk right? Do I have to import some sort of GPIO map first?
martinayotte Posted August 16, 2017 Posted August 16, 2017 Looking more deeply to the library, I found that it is a bit more complex than I thought to make it run on a A20 board. Doing a bit more search, I found out something easier : https://github.com/AiratNig/DHT22-DHT11_Orange-Pi_Python installed on top of the PyA20 library from : https://github.com/OLIMEX/OLINUXINO/tree/master/SOFTWARE/Python/pyA20/pyA20 EDIT : I found also that one, again on top of pyA20 : https://github.com/ionutpi/DHT22-Python-library-Orange-PI
B3RN0UT Posted August 16, 2017 Author Posted August 16, 2017 3 minutes ago, martinayotte said: installed on top of the PyA20 library from : https://github.com/OLIMEX/OLINUXINO/tree/master/SOFTWARE/Python/pyA20/pyA20 Sorry to asking that, but how is it meant to do that? Does this also works for the cubieboard2?
martinayotte Posted August 16, 2017 Posted August 16, 2017 CubieBoard2 is based on AllWinner A20 SoC, so it should work, although you maybe need to check/tweak the header pinout accordingly in pyA20/gpio/mapping.h, although the PD25 is already present. So, simply grab a ZIP snapshot, unzip it, and install it using "cd pyA20-master ; sudo python setup.py install" ...
B3RN0UT Posted August 16, 2017 Author Posted August 16, 2017 DHT22-Python-library-Orange-PI/pyA20# ls -l total 40 drwxr-xr-x 4 root root 4096 Aug 17 00:09 build -rwxr-xr-x 1 root root 330 Jul 14 15:53 CHANGES.txt drwxr-xr-x 2 root root 4096 Aug 17 00:09 examples -rwxr-xr-x 1 root root 283 Jul 14 15:53 __init__.py -rwxr-xr-x 1 root root 591 Jul 14 15:53 MANIFEST -rwxr-xr-x 1 root root 40 Jul 14 15:53 MANIFEST.in drwxr-xr-x 6 root root 4096 Aug 17 00:09 pyA20 -rwxr-xr-x 1 root root 4345 Jul 14 15:53 README.txt -rwxr-xr-x 1 root root 3038 Jul 14 15:53 setup.py DHT22-Python-library-Orange-PI/pyA20# python setup.py install running install running build running build_py running build_ext Detected processor: Allwinner sun7i (A20) Family (Probably Allwinner A20) building 'pyA20.i2c' extension arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c pyA20/i2c/i2c_lib.c -o build/temp.linux-armv7l-2.7/pyA20/i2c/i2c_lib.o In file included from pyA20/i2c/i2c_lib.c:34:0: /usr/include/linux/i2c-dev.h:37:8: error: redefinition of ‘struct i2c_msg’ struct i2c_msg { ^ In file included from pyA20/i2c/i2c_lib.c:33:0: /usr/include/linux/i2c.h:68:8: note: originally defined here struct i2c_msg { ^ In file included from pyA20/i2c/i2c_lib.c:34:0: /usr/include/linux/i2c-dev.h:89:7: error: redefinition of ‘union i2c_smbus_data’ union i2c_smbus_data { ^ In file included from pyA20/i2c/i2c_lib.c:33:0: /usr/include/linux/i2c.h:128:7: note: originally defined here union i2c_smbus_data { ^ error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1 DHT22-Python-library-Orange-PI# ls -l total 24 -rwxr-xr-x 1 root root 620 Aug 17 00:29 dht22_example.py -rwxr-xr-x 1 root root 6153 Aug 17 00:22 dht22.py -rw-r--r-- 1 root root 1 Aug 17 00:13 __init__.py drwxr-xr-x 5 root root 4096 Aug 17 00:31 pyA20 -rw-r--r-- 1 root root 819 Aug 17 00:13 README.md DHT22-Python-library-Orange-PI# ./dht22_example.py Traceback (most recent call last): File "./dht22_example.py", line 3, in <module> from pyA20.gpio import gpio File "DHT22-Python-library-Orange-PI/pyA20/__init__.py", line 5 import < Something > ^ SyntaxError: invalid syntax DHT22-Python-library-Orange-PI/pyA20/__init__.py #!/usr/bin/env python """<Some description> """ import < Something > __author__ = "Stefan Mavrodiev" __copyright__ = "Copyright 2014, Olimex LTD" __credits__ = ["Stefan Mavrodiev"] __license__ = "GPL" __version__ = "2.0" __maintainer__ = __author__ __email__ = "support@olimex.com" ./dht22_example.py #!/usr/bin/env python from pyA20.gpio import gpio from pyA20.gpio import port from pyA20.gpio import connector #import RPi.GPIO as GPIO import dht22 import time import datetime # initialize GPIO #gpio.setwarnings(False) #gpio.setmode(GPIO.BCM) PIN2 = port.PA6 gpio.init() #gpio.cleanup() # read data using pin 14 instance = dht22.DHT22(pin=gpio121) while True: result = instance.read() if result.is_valid(): print("Last valid input: " + str(datetime.datetime.now())) print("Temperature: %.2f C" % result.temperature) print("Humidity: %.2f %%" % result.humidity) time.sleep(1) What does " < something >" expect?
martinayotte Posted August 17, 2017 Posted August 17, 2017 Well ! you first need to figure out about pyA20 library, don't try the other libraries until you get the fist one done ! On my OLIMEX board (I don't have any Cubieboard ...) both include coming from the same kernel tree, so they should have the same timestamp. If your are not the same timestamp, you have done ugly kernel updates ... Maybe a fresh images could help ! root@micro:~# ll /usr/include/linux/i2c* -rw-r--r-- 1 root root 2427 Jun 26 16:14 /usr/include/linux/i2c-dev.h -rw-r--r-- 1 root root 6772 Jun 26 16:14 /usr/include/linux/i2c.h
Recommended Posts