Reezaro
Posts: 9
Joined: Sat Oct 17, 2020 5:33 am

Problem with Adafruit_CircuitPython_dht and Reading DHT22 Sensor

Sat May 08, 2021 4:34 am

Hi,

I am trying to read temp and humidity from AM2303 (DHT22) by using adafruit_CircuitPython_dht libaratry in RP4.
When I run my code as a main every thing is OK. But when I import the function and call it from another program, it keeps showing the below error regarding pin.py GPIO.setmode.

File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/bcm283x/pin.py", line 4, in <module>
GPIO.setmode(GPIO.BCM) # Use BCM pins D4 = GPIO #4
ValueError: A different mode has already been set!



As I noticed, pin.py is trying to change the GPIO setmode to BCM but apparently it has been set to something different. I checked my whole program and I could not find anywhere to set my GPIO to something.
So, please help me to figure it out what the poblem is and how I should resolve it.

Appreciate you

pcmanbob
Posts: 11141
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Problem with Adafruit_CircuitPython_dht and Reading DHT22 Sensor

Sat May 08, 2021 8:21 am

I am guessing that you have set the GPIO.setmode to board in your program that is using the imported module,

I say guessing because you have not seen fit to post your code, which would have helped us understand the problem.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Reezaro
Posts: 9
Joined: Sat Oct 17, 2020 5:33 am

Re: Problem with Adafruit_CircuitPython_dht and Reading DHT22 Sensor

Sat May 08, 2021 9:30 pm

pcmanbob wrote:
Sat May 08, 2021 8:21 am
I am guessing that you have set the GPIO.setmode to board in your program that is using the imported module,

I say guessing because you have not seen fit to post your code, which would have helped us understand the problem.
Thanks for your reply.
I could not post my codes because they are not in one page and if I copied and pasted them here, it would be a really mess up.
I have checked my own written codes and 100% sure I have never set the GPIO mode to board or bcm.
I forgot to mention that I have never used GPIO #4 in my code and that port is free. I use GPIO #21 to read the sensor data.

User avatar
joan
Posts: 15618
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Problem with Adafruit_CircuitPython_dht and Reading DHT22 Sensor

Sat May 08, 2021 9:43 pm

If you are 100% sure everything is correct why are you asking a question?

If you want help you will have to show the code.

pcmanbob
Posts: 11141
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Problem with Adafruit_CircuitPython_dht and Reading DHT22 Sensor

Sun May 09, 2021 10:09 am

You can post any length of code even pages of it, just use code tags , that will also preserve the indentation that python relies on.

Just copy you code in to your post and add code tags top and bottom like this

Add [code] at the top

for i in range(8):
print "code goes here"
time.sleep(1)

and [/code] at the bottom.

which results in it looking like this

Code: Select all


for i in range(8):
    print "code goes here"
    time.sleep(1) 
    
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Troubleshooting”