I am using the following tutorial to make a moisture sensor using a Raspberry Pi 4: https://www.instructables.com/Measuring-Soil-Moisture-Using-Raspberry-Pi/

When I have run my code, I get the following error:

Traceback (most recent call last): 
   File "/home/pi/project.py", line 5,
      in <module> am = Adafruit_MCP3008.MCP3008(clk = 11, cs = 8, miso = 9, mosi = 10)     
   File "home/pi.......Adafruit_MCP3008/MCP3008.py" line 41, in __init__ 
      gpio = GPIO.get_platform_gpio() 
   File "/home/pi......Adafruit_GPIO/GPIO.py", line 426, in get_platform_gpio
      raise RuntimeError('Could not determine platform.') 
 RuntimeError: could not determine platform.

I understand this has something to do with the code as per each "File" line i.e. the Adafruit code. Seems like the code might be out of date. Does anyone know how to fix this? Or any other good tutorials that use the same components to do the job?

Thank you!

  • 1
    How exactly did you follow the tutorial? Did you use pip, git, or a manual download? Which commands did you run, and which one produces the error? Please edit your question so that it contains a description others can reproduce. Mar 31, 2022 at 8:57

1 Answer 1


Searching for that error in that function would suggest Adafruits library may be deprecated.

I would suggest using gpiozero and the MCP3008 class:

from gpiozero import MCP3008
from time import sleep

am = MCP3008(channel=0)

while True:
  moisture_value = am.value # Get the analog reading from the soil moist sensor
  per = moisture_value * 100 / 1023  # Converting the moisture value to percenta
  print("Recorded moisture value is %s percentage" % per)
  if moisture_value >= 930:
    print(" No water, Can you please water me")
  elif moisture_value < 930 and moisture_value >= 350:
    print(" I'm sufficient ")
  elif moisture_value < 350 :
    print(" Stop drowning me!")
  • 1
    Thank you so much Mike! This is an awesome answer and very happy to have this working! (Sorry I can't quite vote yet as I don't have enough points, but definitely will once I get enough reputation :)
    – ITN00bs
    Apr 1, 2022 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.