title: How do I fix this, Raspberry Pi
body: <p>I'm making a raspberry pi project where I press a button and a distance sensor tells me the distance of where I point the sensor.</p>
  
  <p>When I click the button, I get the distance, then I get this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/pi/Desktop/ButtonTestingWithDistanceSensor.py", line 18, 
  in &lt;module&gt;
      input_state = GPIO.input(buttonPin)
  RuntimeError: You must setup() the GPIO channel first
  </code></pre>
  
  <p>and here's my code:</p>
  
  <pre><code>import RPi.GPIO as GPIO
  import time
  
  buttonPin = 17
  TRIG = 4
  ECHO = 27
  
  GPIO.setmode(GPIO.BCM)
  
  GPIO.setwarnings(False)
  
  GPIO.setup(TRIG, GPIO.OUT)
  GPIO.setup(ECHO, GPIO.IN)
  GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  
  while True:
  GPIO.setmode(GPIO.BCM)
  input_state = GPIO.input(buttonPin)
  GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  if input_state == False:
      GPIO.output(TRIG, True)
      time.sleep(0.00001)
      GPIO.output(TRIG, False)
  
      while GPIO.input(ECHO) == False:
          start = time.time()
  
      while GPIO.input(ECHO) == True:
          end = time.time()
  
      sig_time = end-start
  
      #Center Meters
  
      distance = sig_time / 0.000058 # inches: 0.000148
  
      print("Distance: {} cm".format(distance))
  
      GPIO.cleanup()
      time.sleep(0.2)
  </code></pre>
  
  <p>Any help is much appreciated, thanks.</p>