readadc problems on 08M

pippofjk

Member
hi, i have 2 joystick like these:
http://www.robot-italy.com/product_info.php?cPath=15_141&products_id=1172
and i have connected them to my picaxe 08M and used the commands readadc and debug for testing them.
i'm using only one of the two potentiometers available for each joystick.
the code is:
Code:
begin:
 pause 100
 low 0,2
 input 4,1
 let b0=0 
 let b2=0
main:
 readadc 4, b2
 readadc 1, b0
 debug b2
 debug b0

goto main
The problem is that when i move one joystick all up and the other all down, i would expect that the b2 and b0 value should be 255 and 0, instead the values are 131 and 17.
i have measured the voltage value on the chip pin leg and are 5 volt for all up and 0 volt for all down, so there is no wrong wiring connections...
So, what could be the problem?

Thanks for your help! (sorry for my english that could be not correct at all)
 

hippy

Technical Support
Staff member
This is quite common. The pots in the joystick may not have full travel and the 'centre point' may not have value 128 either.

The values you get will depend on the circuit within the joystick and how you have wired it to the PICAXE - Do you have circuit diagrams of each ?

If you want to use 0 to 255 values, with 128 representing the 'centre point' you will need to measure the READADC values for each extreme and the 'centre point' you will then need either one or two calculations which translate the joystick pot values to the values desired.

To determine the calculation, draw a graph of pot values against desired values for each pot. Converting one to the other will be a case of 'gradiants' and transforming 'similar triangles'.
 

pippofjk

Member
i have take the board with the joysticks from a trusthmaster pc-gamepad, and the board have this connection: (v+,gnd,x1,y1,x2,y2)
the fact is that: if my code have only 1 readadc command the joystic works very well (255 all up, 0 all down, and 125 to the center), but if have 2 readadc commands i have the problem previously posted.
 

hippy

Technical Support
Staff member
It looks like you have a circuit wiring error or the joysticks are not wired how one would expect them to be. Please post circuit diagrams and perhaps photos of the joystick and your hardware.

If there is 5V to Pin 4 and and 5V to Pin 2 then both READADC should be returning 255.

Are you sure you are not confusing PICAXE "pin" with chip "leg" ?

Input pin 4 is leg 3, input pin 1 is leg 6 on an 08M.
 

pippofjk

Member
wiring is:
green = +5v
white/green= gnd
orange = y1
white/orange =x1
blu = y2
blue/white =x1

the other grey strip is only for the buttons.
yes, if they ar both up or down returns 255 or 0, for both variables, but if one is all up and the other is all down the variables give strange value
 

Attachments

Haku

Senior Member
One problem with those control sticks is that the stick can only move within a circular boundary.

Say you push the stick fully upwards and you get 255 on the vertical reading and 127 on the horizontal, then you push it it right and get 255 on the horizonal reading and 127 on the vertical reading, but if you push it up and right you cannot get 255 on both the horizontal and vertical reading because the stick is stuck in a circular boundary.

You'll either have to get a control stick which has a square boundary so you can get full readings from the horizontal and vertical when the stick is moved diagonally, or do some fancy coding to compensate for the horizontal & vertical readings you're getting when the stick is moved diagonally.
 
Last edited:

SAborn

Senior Member
Not that it should matter, but in your code you have a few lines that dont appear to be required.

Input 4,1 ...not really needed as you next use it as a ADC 4 input.

let b0=0 ... these will already be value 0 at start up
let b2=0

debug b2
debug b0... it is not required to define Debug with b2,b0, and just 1 "Debug" statement would be enough.


That should help to make your code a little shorter to.
 

pippofjk

Member
with picaxe 18x all work great!
when one joystick is all up and the other all down, values are 255 and 0.
instead with picaxe 08M values are 131 and 17.

using "debug" command i have notice than with picaxe 08M when i move only one joystick, the variable (b0) of the first one change (moving up, increasing value) but also the variable associate to the second joystick (b2) increase (with no move of the second joystick)!
infact measuring the voltage to chip leg confirm that there aren't wrong wiring connectionts.
(voltage value are 5 volt for all up, and for center position are 3 volt).
so if i move both joystick, the variable values are combined togheter, so for the case with one joystick all up and the other all down, variable value are 131 (5 volt measured to chip leg) and 17 (0volt).

This fact it happens only with picaxe 08M.
With picaxe 18x all work very well!

Could be a problem with the chip? i've tried two 08M (firmware 9.0), and they have the same problem!
 
Last edited:

BeanieBots

Moderator
Could be a problem with the chip? i've tried two 08M (firmware 9.0), and they have the same problem!
YES, there IS a problem with that VERY OLD version of the 08M firmware.

The internal multiplexer does not switch when the ReadADC command is called but is switched AFTER the call. The workaround is to read the input twice in succession.

Code:
begin:
 pause 100
 low 0,2
 input 4,1
main:
 readadc 4, b2
 readadc 4, b2
 readadc 1, b0
 readadc 1, b0
 debug

goto main
The issue was fixed in version 9.1
 
Last edited:
Top