Converting 14M2 picaxe to 28X2

Gramps

Senior Member
We are attempting to build this joystick servo controller from Ken Anderson's book, Picaxe Project Handbook V.1,Pt1.
How to switch it to 28X2 chip? I tried a number of pin configurations but to no avail.

#picaxe14M2
#no_data

symbol TEMP = b0
symbol servo1pos =w6
symbol servo2pos =w7

symbol VrX=c.0
symbol VrY=c.4
symbol SERV01=b.4
symbol SERV02=b.5

init:
servo SERV01,150
servo SERV02,150
PAUSE 1000

main:
servo1pos=0
servo2pos=0
readadc VrX,temp
servo1pos=150*temp/255+75
readadc VrY,temp
servo2pos=150*temp/255+75
servopos SERV01,servo1pos
servopos SERV02,servo2pos
goto main
end
 

lbenson

Senior Member
What kind of "no avail"? What error messages are you getting? Are your symbols referring to pins which are appropriate for the 28x2? (See manual 1 for pinouts.)
 

inglewoodpete

Senior Member
We are attempting to build this joystick servo controller from Ken Anderson's book, Picaxe Project Handbook V.1,Pt1.
How to switch it to 28X2 chip? I tried a number of pin configurations but to no avail.
Apart from the missing <space> in the #picaxe statement, the code compiles OK for either PICAXE. As lbenson mentions, if the code works on one chip and, as long as the new pin assignment actually matches your wiring, should produce similar results.

Note that download and power pins also all change with the different chip.
 

Gramps

Senior Member
Ah! So changing the chips does not effect the operation of the code!
So the problem is a probably a wiring error. (Sigh)

What error messages are you getting?
Not getting any error messages.

Note that download and power pins also all change with the different chip.
Yes already changed those pins and the program does load to the 28X2.

And don't forget the pull-up resistor on the RESET leg 1.
Yes, installed as required.

Testing so far:

Changed #picaxe notation to 2X28 in the code.
Verified that the servos and pots are connected to the correct pins on the 28X2
Loaded the code.
Results;
On startup (or reset) the servo on B.5 turns CCW 90 degrees. One 1 second later turns CW 90 degrees, then stops.
The position of pots VrX and VrY have no effect on operation.
The servo on B.4 does nothing.
Edit:
Correction;
The servo on B.4 is vibrating a little.
If we swap the servo's leads to B.4 or B.5 we get the same result as above!
 
Last edited:

lbenson

Senior Member
Ah! So changing the chips does not effect the operation of the code!
It certainly can, depending on what you are doing, but many programs will work without changes.

You might put this statement in your loop to assure that you have rational numbers, before "servopos SERV01,servo1pos"

SERTXD(#servo1pos," ",#servo2pos," ",#temp,cr,lf)

Your loop has no pauses, so you are entering a new SERVOPOS command with each loop iteration--many times a second. See what a PAUSE 2000 does before GOTO MAIN:.

You might also want to do the servopos command only when the position is different from the current one.

The servo on B.4 is vibrating a little.
Some servos can be very dependent on their supplies--what is your circuit?

You might try a sample program as in Manual 3 to assure that each servo works separately. That manual 3 text also notes supply issues.
 

Gramps

Senior Member
like this? Not sure what you are doing......
But no change.

main:
SERTXD(#servo1pos," ",#servo2pos," ",#temp,cr,lf)
servo1pos=0
servo2pos=0
readadc VrX,temp

See what a PAUSE 2000 does before GOTO MAIN:.
It takes a second longer to reverse direction on startup.

Some servos can be very dependent on their supplies--what is your circuit?
Using our 6 volt battery as a supply to the servo.
edit:
Now the servo on B.4 is responding at startup the same way as the other servo.
 
Last edited:

lbenson

Senior Member
SERTXD within the loop before "servopos SERV01,servo1pos". This will show you the value you are getting with the second READADC, and the values you have computed for the SERVOPOS commands.
 

hippy

Senior Member
Sorry Lance, you have lost me.
What lance was suggesting is something like this, slightly re-coded so it's easier to do what has been suggested -
Code:
#Picaxe 28X2
#Terminal 9600
#No_Data

symbol potX      = b0
symbol potY      = b1
symbol servo1pos = b2
symbol servo2pos = b3

symbol VrX       = ?
symbol VrY       = ?
symbol SERV01    = B.4
symbol SERV02    = B.5

Init:
  Servo SERV01,150
  Servo SERV02,150
  Pause 1000

Main:
  Do
    ReadAdc VrX, potX
    ReadAdc VrY, potY
    servo1pos = 150 * potX / 255 + 75
    servo2pos = 150 * potY / 255 + 75
    SerTxd( "PotX=", #potX, TAB, "PotY=", #potY, CR, LF )
    ServoPos SERV01, servo1pos
    ServoPos SERV02, servo2pos
    Pause 100
  Loop
That will allow you to see what values are being read into 'potX' and 'potY'.

If those stubbornly remain at zero or some other value when you twiddle the pots it indicates there is a wiring error with the pots somewhere.

If the values match pot movement but the servos do not move then that suggests there is a wiring error with the servos.
 
Last edited:

hippy

Senior Member
check pot input pins support ADC
Good point. On a 28X2, C.0 does not support ADC.

And there is a second issue; that the X2 chips use ADC channel numbers. The READADC command or SYMBOL statement has to specify the ADC channel number, not the pin name.
 

Gramps

Senior Member
We put the pots on B.0 (ADC12) and B.1(ADC10) VrX bounces to 10 or 12 and VrY to 6-8 in the serial terminal.
Edit:
Disconnected servos and pots are working correctly!
 
Last edited:

Gramps

Senior Member
23541

Seems to be working now!!! :)
Edit:
Regular servos run fine but when we connect the MD20A motor driver, the motor rotates slow and hums.
What code changes are needed to get the motor running a little faster and stop humming?
 
Last edited:

Gramps

Senior Member
23542

Now it's not working again!
Shifting the joystick does not change the numbers!
We reloaded the program. Did a hard reset.
The data stream is not changing???
 

lbenson

Senior Member
Should we have a resister between the pots and the pins?
How do you have your pots wired--wiper to the picaxe pin and 5V (or 3V3) and 0V to the other pins?

No chance of having made picaxe pin an output low (with pot at minimum resistance from 5V) or output high (with pot at minimum resistance from 0V), either of which could cause the maximum picaxe pin current to be exceeded. (That would seem not likely to be your problem, but could be--that is what a series resistor between wiper and picaxe pin would protect against, say 1K.)

Is your circuit on a breadboard? If so, how are the pots connected? It can be hard to get good contact, and sometimes you might need to solder legs onto the pot pins--does wiggling or pressing down on the pot make a difference? Photo?
 
Last edited:

Gramps

Senior Member
On the chance that B.0 and B.1 were burnt, we changed to B.2 and B.3.
Joystick still not effecting the serial terminal.
 

inglewoodpete

Senior Member
Do you have 0v and +5v strips on the left connected to the power source? The red and blue lines indicate that the breadboard strips are broken in the middle and you have not included the whole board in the photo.

Also, you should add a 100nF/0.1uF capacitor as close as you can to the PICAXE chip for the best stability.
 

lbenson

Senior Member
It didn't appear in the tread because I edited it out upon consideration.

Assuming you are talking about the pot partially shown in the lower left, try putting your digital volt meter at every point where there is a junction in the circuit leading to the 28X2--on the pot itself at the yellow wire, at the end of the yellow wire, at the end of the resistor, and on the picaxe pin. Do you get the same reading, or close, at every point?
 

Gramps

Senior Member
"It didn't appear in the tread because I edited it out upon consideration."
Oops! sorry! it's gone now.........

The Joystick in the lower right is connected to the 28X2.
This morning I replaced the 28X2 with a spare. Reloaded the code. Joystick still not responding.
Will check the wiring with the meter as suggested.

Pot in the lower left is connected to an 08M2 which is a separate setup,
(varying the intensity of an LED with a pot using PWM. )
 

Gramps

Senior Member
235451580572796534.png

Both pots on the joystick are reading 5k to 25 ohms when moved. Reloaded the code did a fresh serial terminal. shot posted above.
Connected the volt meter to B.0 and B.1. respectively (and ground). Moving the joystick, voltmeter is reading 0 through 5 volts at both pins.
 

lbenson

Senior Member
If you make more screen shots, could you move the terminal window to the right so we can see more of the code?

As per hippy's suggestion, and Manual 1, are you using ADC12 and ADC10 respectively for the READADC commands for B.0 and B.1 on the 28x2?

Like so in simulation:
28x2_readadc.jpg
 

Gramps

Senior Member
23548

This is the code running . Shifted the joystick to all 4 extreme positions. No change in the serial terminal.
 

Gramps

Senior Member
The READADC command or SYMBOL statement has to specify the ADC channel number, not the pin name.
Yes I wondered what that means but forgot to follow up on his comment.
 

westaust55

Moderator
Looking at the photo at Post 24, the AXE029 breadboard programming adapter is not well seated, it seems to be skewed and pins may be partly out of the breadboard.
Unless there is contact to ground, via resistance, for the SerialIn (programming) pin,then the PICAXE firmware will be awaiting a new program download and the current program will not run.
 

Gramps

Senior Member
Some progress.!
Running hippy's code from post 10 with lbenson's three added statements from post 31.
Joystick movement on Y axis is 0 to 79. X axis is not changing and staying around 100.

1580605776789.png
 
Last edited:

Gramps

Senior Member
Here is the code. Looks like we have an extra sertxd statement?

Code:
#Picaxe 28X2
#Terminal 9600
#No_Data

symbol potX = b0
symbol potY = b1
symbol servo1pos = b2
symbol servo2pos = b3

symbol VrX = B.0
symbol VrY = B.1
symbol SERV01 = B.4
symbol SERV02 = B.5

Init:
Servo SERV01,150
Servo SERV02,150
Pause 1000

Main:
Do
readadc 12,b1
readadc 10,b2

ReadAdc VrX, potX
ReadAdc VrY, potY
servo1pos = 150 * potX / 255 + 75
servo2pos = 150 * potY / 255 + 75

sertxd (#b1," ",#b2, cr,Lf )
SerTxd( "PotX=", #potX, TAB, "PotY=", #potY, CR, LF )

ServoPos SERV01, servo1pos
ServoPos SERV02, servo2pos
Pause 1000
Loop
;readadc 12,b1
;readadc 10,b2
;sertxd (#b1," ",#b2, cr,1f
 

lbenson

Senior Member
Note that b2 from the READADC command is overwritten with the following servo1pos assignment before the SERTXD command, since servo1pos has been defined as a symbol for b2. (I just used b1 and b2 as quick and dirty available variables for the short simulation demonstration program--with no reference or applicability to your code.)

Your code will be easier for people to attend to if you follow the forum convention of enclosing it in the tags, "[ code]" and "[ /code]" (without the spaces).

What you want to do is define your symbols for the READADC channels correctly:

symbol VrX = 12 ' ADC channel number for B.0
symbol VrY = 10 ' ADC channel number for B.1

PotX and PotY do not have values which reflect voltage on B.0 and B.1, because the correct channel numbers are not being used in the READADC commands (because VrX and VrY have not been defined with the correct channel numbers).
 
Last edited:

lbenson

Senior Member
Try this (NOTE: Modified to move servos only when position has changed--untested except works in simulation):
Code:
#Picaxe 28X2
#Terminal 9600
#No_Data

symbol potX = b0
symbol potY = b1
symbol servo1pos = b2
symbol servo2pos = b3
symbol lastPotX = b4
symbol lastPotY = 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
  if potX <> lastPotX then
    lastPotx = potX
    servo1pos = 150 * potX / 255 + 75
  endif
  if potY <> lastPotY then
    lastPotY = potY
    servo2pos = 150 * potY / 255 + 75
  endif

  SerTxd("PotX=",#potX," PotY=",#potY," servo1pos =",#servo1pos ," servo2pos =",#servo2pos,CR,LF)

  ServoPos SERV01, servo1pos
  ServoPos SERV02, servo2pos
  Pause 2000
Loop
 
Last edited:
Top