Slow read GPIO on rock pi -how to speedup?

hello
I’m trying to read data from dht22 modified (use libmraa not wiring) software from http://www.uugear.com/portfolio/read-dht1122-temperature-humidity-sensor-from-raspberry-pi/ but i found that is very hard to read correct data.
After some resarch I found that reading data from GPIO on rock pi via libmraa lasts 13+ us - on raspberry pi it’s only 2-3us. Besides very often data is returned after 100us+ which cause data to be bad.
example:
min 12 max 77 d[0]=1 d[1]=247 d[2]=0 d[3]=236 d[4]=228 Humidity = 50.3 % Temperature = 23.6 *C (74.5 *F)
min 13 max 164 d[0]=1 d[1]=230 d[2]=1 d[3]=217 d[4]=96 Data not good, skip
min 12 max 166 d[0]=1 d[1]=243 d[2]=0 d[3]=217 d[4]=96 Data not good, skip
min 12 max 156 d[0]=7 d[1]=204 d[2]=3 d[3]=175 d[4]=29 Data not good, skip
min 12 max 179 d[0]=1 d[1]=244 d[2]=3 d[3]=179 d[4]=33 Data not good, skip
min 12 max 71 d[0]=1 d[1]=243 d[2]=0 d[3]=236 d[4]=96 Data not good, skip
min 12 max 177 d[0]=1 d[1]=230 d[2]=1 d[3]=217 d[4]=96 Data not good, skip
min 14 max 138 d[0]=3 d[1]=230 d[2]=3 d[3]=175 d[4]=31 Data not good, skip
min 14 max 71 d[0]=1 d[1]=245 d[2]=0 d[3]=236 d[4]=226 Humidity = 50.1 % Temperature = 23.6 *C (74.5 *F)
min 14 max 191 d[0]=2 d[1]=164 d[2]=3 d[3]=179 d[4]=22 Data not good, skip
min 14 max 188 d[0]=3 d[1]=236 d[2]=1 d[3]=179 d[4]=35 Data not good, skip

min - minimum read in us, max- maximum read in us in each series.
Very often first read (after switch from write to read) is after 100-200us
Is there any way to speedup reading or other library to use? or maybe onther way to use dht22?

regards

1 Like

Were you able to fix this issue ?

No, I temporary abandoned Rock PI, and moved to Raspberry PI in my project ;(

This is because the libmraa uses /sys for the GPIO control while wiringPi directly read/write the hardware register which is faster.

I was able to get some GPIO code working that is based on the Orange Pi RK3399 Wiring Pi Implementation. (Which uses mmap, instead of writing to the sys/ filesystem

The Github page for this can be found here
wiringOP_rk3399

This Wiring Pi implementation compiles and runs fine, however the wPI Pin mapping is completely incorrect for the radxa RockPi.
I think the PIN mapping could be corrected by modifying the wiringPi/OrangePi.c file found here
RK3399 Orange Pi PIN Enumeration

If you wanted to give this library a try, you just need to map the actual PIN you want to use, to the Orange Pi RK3399 Wiring Pi Pin definition.

Eg If you wanted to play around with GPIO2_B3 (Physical Pin 7) on the Radxa Rock Pi…

  1. Calculate whats its GPIO number is (eg for GPIO2_B3 - Its Calculated GPIO Number is (2 x 32 + 1 x 8 + 3) = 75)

  2. Using WiringPi compiled on your RockPI, Lookup what the Wiring Pi wPI Pin number is for GPIO 75. - Using gpio readall (For me, the Wiring Pi Pin number is 27)

  3. Use Wiring Pi to Set the Pin type, and its state, using the FUDGED Wiring Pi Pin number.

Some NOTES:
Using this method, there are a lot of Wiring Pi equivalent Pin numbers that are missing,
hence the reason why the above OrangePi.c file would require some modifications.
The C functions that I am currently using cut out the WiringPi Pin mapping all together.
Which is currently working for me perfectly.

I hope this helps someone.

I’m trying to use wiringPi for rk3399 and your post has been very usefull for me.
I write successfully to the Output PIN (GPIO2_B3 alias WPi 27 works well)
setting ON and OFF a simple LED,
but I can’t read the status HIGH or LOW of the
same PIN (I have used pinMode( 27, INPUT) as I have used pinMode( 27, OUTPUT)
to turn on and off the LED).
If I try to read with
cat /sys/class/gpio/gpio75/value,
I’m seeing correctly values 0 (on LOW voltage level) and 1 (on HIGH voltage level - 3V).
But if I read with digitalRead I can’t see the right values (always 0 = LOW).
Here my reading code:

int main( void )
{
int val = LOW;
printf( “Read digital Input %d\n”, DHT_PIN );

if ( wiringPiSetup() == -1 )
exit( 1 );

pinMode( DHT_PIN, INPUT );
while ( 1 )
{
printf(“Reading data…\n”);
val = digitalRead(DHT_PIN);
printf(“Read PIN status: %d\n”, val);
delay( 2000 ); /* wait 2 seconds before next read */
}

return(0);
}

I checked OrangePi_digitalRead function and all mmap stuff seems good (the pin is
read from address 0xff780000 that is bank 2).
I need mmap reading since I use the DHT22 sensor and other gpio speed sensible devices.
Anyone can figure out where the problem is?

Sorry, I’m using RockPi 4 SE

1 Like

holds the right response, handling correctly digitalRead.

1 Like