Difference between revisions of "SparkFun: SoftPot Variable Potentiometer"

From eLinux.org
Jump to: navigation, search
(Sample C Code: Updated to loop and inserted git repository)
m (Updated grading comments)
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
  
 
<pre style="color:red">
 
<pre style="color:red">
Overview:  1, show a picture
+
Overview:  2
Wiring:   1, give specific example.  Suggest which pin to connect to AIN.  Which header are you using?  P8, P9?
+
Wiring:   1, which header are the pins attached to?
Code:     1, make the code loop and continually display the value.
+
Code:     2
git/Compiles with make: 0, put in git
+
git/Compiles with make: 2
Demo:     0
+
Demo:     2
Total:   3
+
Total:     9
Comments:  More details are neededPlease supply and I'll regrade.
+
Comments:  Much betterThanks...
 
</pre>
 
</pre>
  
Line 33: Line 33:
 
<pre>
 
<pre>
  
/** Demonstrates simple usage of the SoftPot variable potentiometer
+
/** demonstrates usage of the SoftPot variable potentiometer
 +
* prints percent value once every second
 +
* Author: Christopher Good
 
*/
 
*/
  

Latest revision as of 20:51, 17 October 2012


Overview:  2
Wiring:    1, which header are the pins attached to?
Code:      2
git/Compiles with make: 2
Demo:      2
Total:     9
Comments:  Much better.  Thanks...

Overview

The softpot is a thin potentiometer that can be used by just touching along the strip. The following is an excerpt from the SparkFun web site: These are very thin variable potentiometers. By pressing on various positions along the strip, you vary the resistance.

SoftPot on breadboard hooked to power and signal line

Inputs and Outputs

The potentiometer has a variable resistance between 100 and 10,000 Ohms that changes linearly with location pressed. When either pin 1 or 3 is connected to ground and the other is connected to VCC the location of the touch can be calculated by reading the voltage on pin 2.


Bone Usage

Hook up pin 1 on the SoftPot to GNDA_ADC (pin 34) and pin 3 on the SoftPot to VDD_ADC(1.8V) (pin 32). Pin 2 on the SoftPot can be connected to any remaining AIN channels. This voltage can then be read as any normal analog in reading.

Sample C Code

This code will give a simple readout of the current position the SoftPot is being touched. The value will be printed once every second. Software AIN3, header P9 pin 37 (hardware AIN2), is being used as the input. This sample code can be downloaded at this git repository


/** demonstrates usage of the SoftPot variable potentiometer
* prints percent value once every second
* Author: Christopher Good
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv, char **envp)
{
	FILE *fp;
	char buf[64];
	
	//open file
	fp = fopen("/sys/devices/platform/omap/tsc/ain3", "r");
	if(fp == NULL){
		printf("error with opening analog in file\n");
		fflush(stdout);
		exit(1);
	}
	while(1){ //will run forever
		rewind(fp);
		//read value
		fgets(buf, 64, fp);
		//format for printing
		printf("The SoftPot was touched at %d%\n", 101*atoi(buf)/4095); //101 for 0-100
		sleep(1); //will update once every second
	}	
	//close file pointer
	fclose(fp);
	return 0;
}