Posts: 127
Joined: Thu Feb 14, 2013 2:10 am
Contact: Website

Getting values from FSR

Sun Mar 16, 2014 3:38 am

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-sensiti ... ing-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.

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
    def RCtime (RCpin):
        reading = 0
        GPIO.setup(RCpin, GPIO.OUT)
        GPIO.output(RCpin, GPIO.LOW)
        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?
Just started my Raspberry Pi journey >> http://yvonnezoe.wordpress.com

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

Re: Getting values from FSR

Sun Mar 16, 2014 10:11 am

Perhaps the times are too short to reliably measure with that busy loop?

Given the FSR resistance is what you want to measure the only other variable under your control is capacitance. Try a bigger capacitor.

Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Getting values from FSR

Sun Mar 16, 2014 12:47 pm


Check this post.

http://www.raspberrypi.org/phpBB3/viewt ... 70#p519570

The 555 will precisely detect 1/3 and 2/3 VCC threshold and oscillate around it.

I use Joan's pigpio to detect the time between the falling and rising edge of the oscillation.

The timing formula on a 555 is t = 0.7 * R * C ( .693 in theory)

R will be te value the FSR in ohm and C will the value of the capacitor in Farad.
And t will be in second.

Try to set the minimum timing > 2 ms otherwise the python code could miss edge detection.

P.S. if your FSR has resistor impedance lower than 100 ohm, you will have to add a resistor in series.

Precision will be around 1%.

The 555 was the I.C. of choice 20 years ago to create all sort of timing system.

http://schematicsforfree.com/archive/fi ... ations.pdf


Return to “Automation, sensing and robotics”