Difference between revisions of "SparkFun: 0.5" Force Sensitive Resistor"
|Line 6:||Line 6:|
git/Compiles with make: 0,
git/Compiles with make: 0,
Latest revision as of 11:28, 14 November 2012
Overview: 2 Wiring: 2 Code: 2 git/Compiles with make: 0, No makefile Demo: 2 Total: 8 Comments:
The SparkFun 0.5" Force Sensitive Resistor varies its resistance based on the amount of force applied to it. The larger the force, the lower the resistance of the device. When no force is being applied, the resistance is larger than 1MΩ. Like a regular resistor, it only has two leads. The FSR Integration Guide can be accessed here.
The force-sensitive resistor works well when used with one of the BeagleBone's analog inputs. The images below outline how to hook it up. This schematic on the left is modified and originally from the SparkFun tutorial on the force-sensitive resistor. The example on the right outlines one way to hook-up the resistor to read values from the Bone.
A 27kΩ resistor is used to connect the 3.3V source (pin 3) from the Bone to one pin of the force-sensitive resistor. Then, the other pin of the force-sensitive resistor is connected to ground (pin 1). An analog pin (AIN) on the Bone connects to the node containing both resistors, and values can be read off of that AIN. I'm using AIN5 (pin 36) to read values on the Bone.
Reading values off of the analog input is the same as explained in Exercise 10. You can "cat" ain6, and the value will range from around 0 to 4096. When no force is applied to the force-sensitive resistor, the value is close to 4096. When maximum force is applied, the value is close to 0.
Programmatically, this means that you can read that ain6 value, which is based on how much force is applied, and do anything you want with it. The following code reads the analog value and saves it as an int named analogValue:
FILE* file = fopen("/sys/devices/platform/omap/tsc/ain6", "r"); int analogValue = 0; fscanf(file, "%d", &analogValue); fclose(file);
The example program below uses this idea to light an LED based on how much force is applied to the force-sensitive resistor.
I've written a program which demonstrates usage of the force-sensitive resistor, available here. The input is the force-sensitive resistor on pin 36 (AIN5), and the output is an LED on pin 12 (GPIO1_28). The physical configuration is shown in the image on the right.
The result of this program is that the harder one squeezes on the force-sensitive resistor, the brighter the LED illuminates. It is configured to require quite a bit of force for maximum brightness.
A graphical display is available for the force sensitive resistor in accordance with EBC Mini Project 04. To prepare the BeagleBone, start by running:
beagle$ opkg update beagle$ opkg install nodejs
With nodejs installed, pull the files from my MiniProject 4 repository onto the BeagleBone in a convenient folder. Make sure the force sensitive resistor is connected to ain6 as described above, then run:
beagle$ node buttonBox.js
The graphical interface server is now running. To view it, point your browser to bone:8081/buttonBox.html, where bone is the IP address or alias of your BeagleBone. An example of what you'll see is given below. As you squeeze the force sensitive resistor with alternating force, the line graph with move up and down in real-time.