Converting 14M2 picaxe to 28X2

Gramps

Senior Member
servo1pos <> lastPos1
..........................^
We are getting a syntax error here...........
Edit;
and one here
servo2pos <> lastPos2

Second edit:
When we commented these two statements out, the errors cleared and the code works perfectly in the serial terminal.
Please show us how to get the servos to respond.
Thank you sir! Your patience and kindness to me is greatly appreciated!!!
Gramps
 
Last edited:

lbenson

Senior Member
We are getting a syntax error here...........
Cut and paste error on my part. You're too quick for me, Gramps ;-} I posted several changes after I actually tried it in the simulator. Here's my latest play.
Code:
'readadc 12,b1
'readadc 10,b2
'sertxd(#b1," ",#b2,cr,lf)
#Picaxe 28X2
#Terminal 9600
#No_Data

symbol potX = b0
symbol potY = b1
symbol servo1pos = b2
symbol servo2pos = b3
symbol lastPos1 = b4
symbol lastPos2 = b5

symbol VrX = 12 ' ADC channel number for B.0
symbol VrY = 10 ' ADC channel number for B.1
symbol SERV01 = B.4
symbol SERV02 = B.5

Init:
Servo SERV01,75 ' check servo range of travel
Servo SERV02,75
Pause 1000
Servo SERV01,225
Servo SERV02,225
Pause 1000
Servo SERV01,150 ' center servos
Servo SERV02,150
Pause 1000

Main:
Do
  ReadAdc VrX, potX
  ReadAdc VrY, potY
  servo1pos = 150 * potX / 255 + 75
  servo2pos = 150 * potY / 255 + 75
  if lastPos1 <> servo1pos then
    lastPos1 = servo1pos
    ServoPos SERV01, servo1pos
    SerTxd("PotX=",#potX," servo1pos =",#servo1pos,CR,LF)
  endif
  if lastPos2 <> servo2pos then
    lastPos2 = servo2pos
    ServoPos SERV02, servo2pos
    SerTxd("PotY=",#potY," servo2pos =",#servo2pos,CR,LF)
  endif
Loop
It's possible that in practice, more code would be needed to prevent dithering depending on how stable the READADC is. You might need to assure that the difference between, say, lastPos1 and servo1pos is greater than 1, or greater than some other number.
 

Gramps

Senior Member
The servos are responding to the pots! Even the 20 HG servo is working!
The code is jamming somehow. In the serial terminal you can see the code stopping and then seems to start again.
 

hippy

Technical Support
Staff member
The code is jamming somehow. In the serial terminal you can see the code stopping and then seems to start again.
For the 20 HG servo or both ?

I would guess it's excess current demand when a servo moves, collapsing the power supply, causing the PICAXE to reset. You can determine if it's resetting by adding a SERTXD immediately after your "Main:" label ...
Code:
Main:
SerTxd( "Reset", CR, LF )
 

Gramps

Senior Member
My error. When the servos are moving, the terminal records. When the servo stops, the terminal stops till we move the joystick again. So it appears to be correctly operating.
 

Gramps

Senior Member
For the 20 HG servo or both ?
No, the big servo will not respond. If we switch the small servo to either of the output pins it works fine on both pins..
We are using a 6 volt battery to power the servos.
Added "
SerTxd( "Reset", CR, LF )
That does not seem to make a difference. Should it change the serial terminal readout?
 

lbenson

Senior Member
When the servos are moving, the terminal records. When the servo stops, the terminal stops till we move the joystick again. So it appears to be correctly operating.
The IF statements are such that the SERTXD output to the terminal only happens if the servo should move based on the joystick. You could put the SERTXD statements outside the IF constructs, but you would be swamped with seldom-changing readings. You can see this clearly if you step through the code in the simulator, occasionally changing the ADC values for B.0 and B.1.

Can you post a link to the big servo so we can see what its requirements are, and also a photo of it as connected to the breadboard?

SerTxd( "Reset", CR, LF )
That does not seem to make a difference. Should it change the serial terminal readout?
That will only output to the terminal upon first powerup or subsequent restarting of the PICAXE after a collapse of the power supply, as can be caused by servos and some other gear. You probably need a PAUSE 2000 before that first SERTXD statement in order to allow time for the terminal to be connected so the message can be shown upon initial powerup (probably not on a fault-caused restart).
 
Last edited:

hippy

Technical Support
Staff member
Added "
SerTxd( "Reset", CR, LF )
That does not seem to make a difference. Should it change the serial terminal readout?
Not if it's not resetting, which it probably isn't now the nature of the terminal stopping has been identified and it's actually expected behaviour.
 

Gramps

Senior Member
When wiggling the joystick around we get it working sometimes. Acting like a loose wire.
 

lbenson

Senior Member
Does the servo do the turn to the limits and then center in accordance with the initial code before main:?

If it does, and then never reports a change in position, it would indicate that the joystick is not working reliably--though why that would happen only with the bigger servo is puzzling. Make sure you have in place the SERTXD statement indicating a reset, and that it is preceded with PAUSE 2000 (or more than 2000 if you are not seeing the "Reset" line).
 

Gramps

Senior Member
Does the servo do the turn to the limits and then center in accordance with the initial code before main:?
Yes. Small servo works that way if we connect it to B.4 or B.5. Joystick operated front to back or left to right respectively.
 

Gramps

Senior Member
Now have two small servos responding correctly!
Large servo sometimes works and sometimes no.
Put the 6 volt battery on the charger................
Edit:
No change in large servo with battery charged.
Servo runs consistently on the servo tester........
 
Last edited:

lbenson

Senior Member
What is the reset line?
The one you referred to in post 46. It's important to have that so that you can see if the picaxe is restarting when trying to run the large servo. You should see "Reset" in the terminal. If you see it repeatedly, the power supply is insufficient (or something else is wrong). The question about the servo moving upon initial power up was intended to determine the behavior of the large servo--does it move when attached to B.4 or B.5 when power is applied to the picaxe?
 

Gramps

Senior Member
You should see "Reset" in the terminal.
Each time we restart the picaxe Rreset" appears in the terminal. Same exact behavior with 2 small servos or one small and one big servo.
Edit:
After starting the picaxe and fiddling with the joystick a bit, the big servo will move in a strong manner but then seems to drop out again.
Edit:
There is a sweet spot in the joystick where the big servo will move up and back.
Edit:
Another new discovery! Substituted a 5k pot for the "Y" side of the joystick. Big servo is responding correctly!
Edit:
Big servo does nothing on startup but will track the 5k pot.
I'm concluding the joystick is faulty.
 
Last edited:

lbenson

Senior Member
With the big servo attached, are the SERTXD lines showing the changes in the joystick appearing--just with no movement of the big servo?

Please provide a photo showing the wiring of the breadboard and the servo, with the differing 5V and 6.6V supplies for the picaxe and the servo respectively.
 

Gramps

Senior Member
It just started working with the joystick!!! big servo and small servo are cycling now on startup. Left right and center.
I'm totaling mystified.
OH! the 6 volt power must be on first before doing a reset!20200203_191624.jpg
 

lbenson

Senior Member
The joystick is erratic.
Bummer. Faulty gear providing erratic outputs can be very hard to debug. Hope replacing it will fix the problem.

I have a joystick which looks similar to the one you have. I can't say it's erratic, but it has proven so coarse that fine adjustments are impossible.
 

Gramps

Senior Member
Replacement 5k pot works flawlessly.
Now that we have a working servo controller hoping to go forward with this project!
It 's a robot arm that uses two power window motors to give motion to the shoulder.
Two MD20A 20 amp DC motor drivers that accept PWM signals are to utilized.
I have a short demo of what is working so far but do not remember how to post a video link. (this old age thing is terrible!)
 

lbenson

Senior Member
do not remember how to post a video link
Upload to youtube, copy the link address from your browser, click the link icon to the left of the image icon, type your descriptive text for the video, paste in the youtube address.
 
Top