Slow read GPIO on rock pi -how to speedup?

I’m trying to read data from dht22 modified (use libmraa not wiring) software from 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.
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?


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

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.

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.