Picaxe Robotic Arm

bugmenot1234

New Member
Hi there,

I am making this servo operated robot arm, the same one as seen here: http://www.instructables.com/id/Checkers-the-seven-servo-robot-arm/#step1

I want to control each individual servo with a potentiometer, so that the control panel looks like this,

Control.png

I will be using 10K Pots and a 5V Regulated Supply. I am just unsure on how to take a reading from a pot, and then translate it into a servo position. I want the servo to move with the pot, so when the pot is in the centre, then the servo will be in the
same position.

Will be using a 20X2

If someone could demonstrate how this would be done, I would be very appreciative.

Thanks.
 

Jamster

Senior Member
Have a look at the Servo, servopos and readADC commands in Manual 2 :)
Shouldn't be too hard to code so long as you dont exceed the limits of the servo

Jamster
 

tony_g

Senior Member
heres a snippet to start playing with, you would have to adjust any pin descriptions for your outputs from the chip for whichever ones you use.

for now if you hook up a pot and a servo and use this bit of code you should see the servo move from end to end with the pots end to end range.
assuming your servo has the standard pulse range of 75 - 225 which some dont and may either allow a bit more or less servo travel beyond these values.

#picaxe 08m2

main:
readadc 4,b0
w1 = b0*30/51 +75
servopos 4,w1
goto main
 

jinx

Senior Member
I,ve not tested this bit code given my track record tonight :eek: may not work but it passes syntax check
Code:
#picaxe 28x2

symbol servoport0 = B.0           ' pin of the servo  0 base

symbol analogport0 = a.0            ' adc pin value 10k pot 
  
symbol analogvalue0 = w1          ' place your pot reading into a word variable 


symbol base = w4                   


init:


servo servoport0, 150



    do
    
     readadc analogport0, analogvalue0

     analogvalue0 = analogvalue0 *10/17+75      'divide by 1.7



     if analogvalue0 <> base then
     servopos servoport0, analogvalue0
     let base = analogvalue0
     end if
      
    loop
hopeful get you started .
jinx
 

bugmenot1234

New Member
Thanks, for all the replys, it has been very helpful.
I have been able to come up with a program I think will work, it will be controlled by six pots and the corresponding servos will follow the pots.

I would appreciate it if you could check it over for me,

Thanks.



Code:
; GOLD CREST PROJECT ROBOT ARM

;=============================== START ==============================
;====================================================================

; Servo 0

Symbol servoport0 = B.0           ; Pin of Servo 0  

Symbol analogport0 = C.0          ; ADC Pin Value 10k Pot 
  
Symbol analogvalue0 = w1          ; Pot Reading Word Variable

Symbol base0 = w2              	; Last Position of the Pot    


; Servo 1

Symbol servoport1 = B.1           ; Pin of Servo 1  

Symbol analogport1 = C.1          ; ADC Pin Value 10k Pot 
  
Symbol analogvalue1 = w3          ; Pot Reading Word Variable

Symbol base1 = w4              	; Last Position of the Pot   


; Servo 2

Symbol servoport2 = B.2           ; Pin of Servo 2  

Symbol analogport2 = C.2          ; ADC Pin Value 10k Pot 
  
Symbol analogvalue2 = w5          ; Pot Reading Word Variable

Symbol base2 = w6              	; Last Position of the Pot   


; Servo 3

Symbol servoport3 = B.3           ; Pin of Servo 3  

Symbol analogport3 = A.3          ; ADC Pin Value 10k Pot 
  
Symbol analogvalue3 = w7          ; Pot Reading Word Variable

Symbol base3 = w8              	; Last Position of the Pot   


; Servo 4

Symbol servoport4 = B.4           ; Pin of Servo 4  

Symbol analogport4 = A.4          ; ADC Pin Value 10k Pot 
  
Symbol analogvalue4 = w9         ; Pot Reading Word Variable

Symbol base4 = w10              ; Last Position of the Pot   


; Servo 5

Symbol servoport5 = B.5           ; Pin of Servo 5 

Symbol analogport5 = A.5          ; ADC Pin Value 10k Pot 
  
Symbol analogvalue5 = w11          ; Pot Reading Word Variable

Symbol base5 = w12              ; Last Position of the Pot   


;====================================================================


Main:


servo servoport0, 150		; Init Servo 0 - Center
servo servoport1, 150		; Init Servo 1 - Center
servo servoport2, 150		; Init Servo 2 - Center
servo servoport3, 150		; Init Servo 3 - Center
servo servoport4, 150		; Init Servo 4 - Center
servo servoport5, 150		; Init Servo 5 - Center


		goto Servo0


;====================================================================


Servo0:


     readadc analogport0, analogvalue0		; Read Pot Value into Variable W1

     analogvalue0 = analogvalue0 *10/17+75      ; Divide by 1.7 


     if analogvalue0 <> base0 then		; If Pot has Changed Position

     servopos servoport0, analogvalue0		; Servo Position is Modified Pot Reading

     let base = analogvalue0			; Set Servos New Position as Base

     end if
      

			goto Servo1


;====================================================================


Servo1:


     readadc analogport1, analogvalue1		; Read Pot Value into Variable W3

     analogvalue1 = analogvalue1 *10/17+75      ; Divide by 1.7 


     if analogvalue1 <> base1 then		; If Pot has Changed Position

     servopos servoport1, analogvalue1		; Servo Position is Modified Pot Reading

     let base = analogvalue1			; Set Servos New Position as Base

     end if
      

			goto Servo2


;====================================================================


Servo2:


     readadc analogport2, analogvalue2		; Read Pot Value into Variable W5

     analogvalue2 = analogvalue2 *10/17+75      ; Divide by 1.7 


     if analogvalue2 <> base2 then		; If Pot has Changed Position

     servopos servoport2, analogvalue2		; Servo Position is Modified Pot Reading

     let base = analogvalue2			; Set Servos New Position as Base

     end if
      

			goto Servo3


;====================================================================


Servo3:


     readadc analogport3, analogvalue3		; Read Pot Value into Variable W7

     analogvalue3 = analogvalue3 *10/17+75      ; Divide by 1.7 


     if analogvalue3 <> base3 then		; If Pot has Changed Position

     servopos servoport3, analogvalue3		; Servo Position is Modified Pot Reading

     let base = analogvalue3			; Set Servos New Position as Base

     end if
      

			goto Servo4


;====================================================================

Servo4:


     readadc analogport4, analogvalue4		; Read Pot Value into Variable W9

     analogvalue4 = analogvalue4 *10/17+75      ; Divide by 1.7 


     if analogvalue4 <> base4 then		; If Pot has Changed Position

     servopos servoport4, analogvalue4		; Servo Position is Modified Pot Reading

     let base = analogvalue4			; Set Servos New Position as Base

     end if
      

			goto Servo5


;====================================================================

Servo5:


     readadc analogport5, analogvalue5		; Read Pot Value into Variable W11

     analogvalue5 = analogvalue5 *10/17+75      ; Divide by 1.7 


     if analogvalue5 <> base5 then		; If Pot has Changed Position

     servopos servoport5, analogvalue5		; Servo Position is Modified Pot Reading

     let base = analogvalue5			; Set Servos New Position as Base

     end if
      

			goto Servo0

;================================ END ===============================
;====================================================================
 
Last edited:
Top