I am trying to get values from a force sensitive resistor with Raspberry Pi. I saw an example using Arduino such as this http://learn.adafruit.com/force-sensitive-resistor-fsr/using-an-fsr 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.
#!/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
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.
How can i interpret this? Or what is the proper way of doing it?