and I can get sensor values from a photocell using the code below. Now I am trying to use the same concept to apply to FSR.
I tried this code but it gave me some weird numbers. When I press on the FSR, it gave me some values from 10k to 100k. when i continue pressing it, it will return me with `0` after showing a large value for once or twice.
Code: Select all
#!/usr/bin/env python # Example for RC timing reading for Raspberry Pi # Must be used with GPIO 0.3.1a or later - earlier verions # are not fast enough! import RPi.GPIO as GPIO, time, os DEBUG = 1 GPIO.setmode(GPIO.BCM) def RCtime (RCpin): reading = 0 GPIO.setup(RCpin, GPIO.OUT) GPIO.output(RCpin, GPIO.LOW) time.sleep(0.1) GPIO.setup(RCpin, GPIO.IN) # This takes about 1 millisecond per loop cycle while (GPIO.input(RCpin) == GPIO.LOW): reading += 1 return reading while True: print RCtime(27) # Read RC timing using pin #27
How can i interpret this? Or what is the proper way of doing it?