RobotRebels.org

Odds and Ends => Code Snippets => Topic started by: jinx on November 11, 2015, 03:33:12 AM

Title: 10 K potentiometer
Post by: jinx on November 11, 2015, 03:33:12 AM
10k main.PNG
*10k main.PNG (169.46 kB . 703x257 - viewed 295 times)
  potentiometers come in all shapes and sizes and the 10k is the defacto pot for controlling servo's once you conquered the scaling, it's easy to identify it have the  value written on it which means that we can vary its resistance from 10 to 0 Ohm . A movable wiper is rotated clockwise or anticlockwise direction that changes the resistance of the potentiometer. .

  wiring:
pot wiring.PNG
*pot wiring.PNG (40.14 kB . 323x444 - viewed 314 times)

example #1 nothing more than what's in the manual except here am displaying data in the terminal window
Code: [Select]
'10K pot scaling
'3.3V
#picaxe 28x2
#no_data
#no_table
#freq m4

'########## pots #############################
symbol pot1   = S.A1             'center pin of the pot to picaxe
symbol potval = w0               'place the reading into a word variable
symbol delay    = 100

 main:
    do
  readadc10  S.A1,potval                  ' reads and places the pot value 
  pause 10
  sertxd(" Pot value",#potval,13,10)
  pause delay
 
       loop

example #2 replace the main section of code from example one  give the pot  31 steps, turns one input into thirty and possibly  used in conjunction with the case select  command
Code: [Select]
main:
  do
  readadc10  S.A1,potval                    ' reads and places the pot value 
   potval = potval / 5 * 23 / 150                 '
  pause 10
  sertxd(" Pot value",#potval,13,10)
  pause delay
 
loop

example #3 scales the pot for servo control through the range 80-219 should prevent you hitting the endstops.
Code: [Select]

'10K servo control
'3.3V shield
#picaxe 28x2
#no_data
#no_table
#freq m4



symbol pot1   = S.A1             'center pin of the pot to picaxe
symbol potval = w0               'place the reading into a word variable


symbol pan = b.7
symbol lft = 80
symbol rgt = 200
symbol cen = 130

symbol MINS   = 80               '-+ minium travel
symbol MaxS   = 22               '-+ for max travel

int:
    servo pan,cen
    pause 30
 main:
  do
  readadc10  S.A1,potval                  ' reads and places the pot value 
  potval= potval*3/MaxS+MINS                  ' scales the pot range between 219-80
  servopos pan,potval
  pause 30
  sertxd(" Pot value",#potval,13,10)
  loop

  but I need more servo control not a problem just duplicate what you done  and remember to add the symbols for the second servo.
Code: [Select]
do
  readadc10  S.A1,potval                  ' reads and places the pot value 
  readadc10  S.A2,potval1                  ' reads and places the pot value 
  potval= potval*3/MaxS+MINS                  ' scales the pot range between 219-80
  potval1= potval1*3/MaxS+MINS                  ' scales the pot range between 219-80
  servopos pan,potval
  servopos tilt,potval1
  pause 30
  sertxd(" Potpan ",#potval," pottilt ",#potval1,13,10)
  loop


 test vid:

links:
erco fun :http://www.picaxeforum.co.uk/showthread.php?27489-Servo-Record-amp-Playback&highlight=servopos

http://www.geofex.com/article_folders/potsecrets/potscret.htm
Title: Re: 10 K potentiometer
Post by: erco on November 12, 2015, 11:23:10 AM
Beautimous pan/tilt, jinx!

I posted this video on pots & servo control last month.


Title: Re: 10 K potentiometer
Post by: erco on November 12, 2015, 01:32:18 PM
Another fun fact about servos & pots. Having hacked numerous servos for continuous rotation, I can say that all or most of them use 5K pots internally for position feedback. I normally replace the pot electrically with a voltage divider made from a pair of 2.7K fixed resistors, keeping the overall value around 5K. But I used 100K resistors in the last pair of HXT900 servos I modified, and they worked just the same. In fact, they were the best-matched pair of servos I have ever seen, in terms of null point, which is obviously not adjustable using fixed resistors.