DoubleHP Posted March 2, 2022 Posted March 2, 2022 Hello. First, I have an LTS board that provides only 3.05 on the 3.3 pins. Is it normal ? Anyway, in case this was the issue, I have built a new voltage regulator, and now supply the DHT22 and pullup resistor with 3.60V My issue is simple: when plugged on normal 1W bus, the DHT22 kills the bus, and makes other devices non working. I have moved all other devices on a new bus, leaving the DHT on a bus I know works fine. Some people mentionned the DHT is not compliant with official 1W libraries, and can not be recognised with normal timings, so, special libs are required. I have removed param_w1_pin=PA06 for the hysical pin 7, and installed new software. I have a very bad experience with python, and I have never been able to make any python lib/project, on any board of any brand; I always get some error at some point. The only non python lib/app for DHT22 I have found is https://github.com/pilkch/climbatize but after heavily patching it (to fix various bugs), the app still seems unable to communicate with the probe. I have checked more than 12 times the sensor is connected to the so called pin 7 (PA06), pin 2 in WiringPi, and changed the physical sensor (paid for a new item). Who can help reading this probe ? I am just running out of ideas. The only issue that bothers me is that I am not physically 100% certain that Climbatize manipulates pin7. I have entered the loop that manipulates some pin, but at some point it's calling wiringPi, and my multimeter always shows 3.6V on the pin; I don't have a scope to check the pin goes down, and applying a LED on a pulledup pin will not produce a perceptible OFF time. I would need to solder an inverted gate to transform the logic, but even then, the light pulses may be too short for my eyes. I really dont think 3.60V could burn the oPi board; and 3.05 could be a huge reason for the DHT22 to refuse to work. I could plug a lab regulated supply, but I think it would be overkill. I do have spare/new/unused boards; but all my LTS boards deliver 3.05. (yes I have some boards left in 2022; I had bought *MANY* spare ones years ago). 0 Quote
DoubleHP Posted March 2, 2022 Author Posted March 2, 2022 For example, I see a /lib/modules/./4.13.16-sunxi/kernel/drivers/iio/humidity/dht11.ko , how can I try using this ? 0 Quote
DoubleHP Posted March 3, 2022 Author Posted March 3, 2022 WORKS FOR ME It was my VERY LAST try before giving up completely: https://www.uugear.com/portfolio/read-dht1122-temperature-humidity-sensor-from-raspberry-pi/ fix the ping to 7 (instead of 3 in the source), compile with cc -Wall dht.c -o dht -lwiringPi -pthread and it does the job: Quote ./dht Raspberry Pi DHT11/DHT22 temperature/humidity test Humidity = 46.0 % Temperature = 23.5 *C (74.3 *F) Humidity = 37.9 % Temperature = 27.4 *C (81.3 *F) Data not good, skip Data not good, skip Data not good, skip Data not good, skip Humidity = 37.5 % Temperature = 27.2 *C (81.0 *F) Data not good, skip Data not good, skip Humidity = 37.7 % Temperature = 27.2 *C (81.0 *F) Data not good, skip Humidity = 37.6 % Temperature = 27.2 *C (81.0 *F) Humidity = 37.6 % Temperature = 27.2 *C (81.0 *F) Data not good, skip Data not good, skip Data not good, skip Data not good, skip Humidity = 37.6 % Temperature = 27.2 *C (81.0 *F) Data not good, skip Humidity = 37.7 % Temperature = 27.2 *C (81.0 *F) Humidity = 37.6 % Temperature = 27.3 *C (81.1 *F) Data not good, skip Humidity = 37.7 % Temperature = 27.3 *C (81.1 *F) Data not good, skip Data not good, skip Data not good, skip Humidity = 37.6 % Temperature = 27.2 *C (81.0 *F) Humidity = 37.6 % Temperature = 27.3 *C (81.1 *F) Data not good, skip Data not good, skip Data not good, skip Humidity = 37.7 % Temperature = 27.3 *C (81.1 *F) Humidity = 37.6 % Temperature = 27.3 *C (81.1 *F) Data not good, skip According to other forums, 60% misses is ordinary for this probe. Note that the very first value is completely wrong; I did not read anything about this, but I am not surprised. CO2 probes need 15 pre heat; and this is the very first successfull read of the probe, so some miss-configuration or badly initialised variable are likely. So, on production line, I will take care to ignore the first 3 values after service start/reboot. 0 Quote
DoubleHP Posted March 3, 2022 Author Posted March 3, 2022 In case the other website goes down, I will duplicate their original code here. Don't forget to fix your PIN number. My WiringPi lib is probably https://github.com/zhaolei/WiringOP (not 100% certain). /* * dht.c: * read temperature and humidity from DHT11 or DHT22 sensor */ #include <wiringPi.h> #include <stdio.h> #include <stdlib.h> #include <stdint.h> #define MAX_TIMINGS 85 #define DHT_PIN 3 /* GPIO-22 */ int data[5] = { 0, 0, 0, 0, 0 }; void read_dht_data() { uint8_t laststate = HIGH; uint8_t counter = 0; uint8_t j = 0, i; data[0] = data[1] = data[2] = data[3] = data[4] = 0; /* pull pin down for 18 milliseconds */ pinMode( DHT_PIN, OUTPUT ); digitalWrite( DHT_PIN, LOW ); delay( 18 ); /* prepare to read the pin */ pinMode( DHT_PIN, INPUT ); /* detect change and read data */ for ( i = 0; i < MAX_TIMINGS; i++ ) { counter = 0; while ( digitalRead( DHT_PIN ) == laststate ) { counter++; delayMicroseconds( 1 ); if ( counter == 255 ) { break; } } laststate = digitalRead( DHT_PIN ); if ( counter == 255 ) break; /* ignore first 3 transitions */ if ( (i >= 4) && (i % 2 == 0) ) { /* shove each bit into the storage bytes */ data[j / 8] <<= 1; if ( counter > 16 ) data[j / 8] |= 1; j++; } } /* * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte * print it out if data is good */ if ( (j >= 40) && (data[4] == ( (data[0] + data[1] + data[2] + data[3]) & 0xFF) ) ) { float h = (float)((data[0] << 8) + data[1]) / 10; if ( h > 100 ) { h = data[0]; // for DHT11 } float c = (float)(((data[2] & 0x7F) << 8) + data[3]) / 10; if ( c > 125 ) { c = data[2]; // for DHT11 } if ( data[2] & 0x80 ) { c = -c; } float f = c * 1.8f + 32; printf( "Humidity = %.1f %% Temperature = %.1f *C (%.1f *F)\n", h, c, f ); }else { printf( "Data not good, skip\n" ); } } int main( void ) { printf( "Raspberry Pi DHT11/DHT22 temperature/humidity test\n" ); if ( wiringPiSetup() == -1 ) exit( 1 ); while ( 1 ) { read_dht_data(); delay( 2000 ); /* wait 2 seconds before next read */ } return(0); } 1 Quote
atomic77 Posted April 14, 2023 Posted April 14, 2023 Thank you for sharing this! I have a DHT22 that i've been trying to get working with an OrangePi Lite and I've had terrible results with all of the python-based libraries i've tried. I'm getting about 25-30% of the readings with this every 2s, which is good enough for my purposes. FWIW, my opi lite is showing about 5.2 and 3.8v for the 5V and 3.3V pins 0 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.