Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 00:24 17 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Analogue input reading

Author Message
mpep
Newbie

Joined: 09/11/2014
Location: New Zealand
Posts: 29
Posted: 11:45am 29 Dec 2014
Copy link to clipboard 
Print this post

Hi all,

I have used PICAXE before, this is a little different, but nothing I can't handle.

A simple question with, I am certain, an equally simple answer .

I have a miniMaximite, with a potentiometer (old joystick) connected to Pin 2, and 3.


For my test code, I have:

Setpin = 2,1
Setpin = 3,1
volts2 = pin(2)
volts3 = pin(3)
do
print @(150,40) ("Pin2 = "),volts2;
print @(150,80) ("Pin3 = "),volts3;
loop


Only problem is, the values do not change, indicating 1.60046 or there-abouts.
I have verified that the voltage is changing on the board, at the P1.2 and P1.3 locations.

What am I missing?

Must admit, reading analogue values is, IMHO, not well documented.

MPep
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 12:04pm 29 Dec 2014
Copy link to clipboard 
Print this post

Welcome to the forum.

Everything looks OK, programming wise so I suspect that you have the wrong terminals.

pin(2) is connected to pin 4 on CON 1 and
pin(3) is connected to pin 5 on CON 1

Jim
VK7JH
MMedit   MMBasic Help
 
mpep
Newbie

Joined: 09/11/2014
Location: New Zealand
Posts: 29
Posted: 12:21pm 29 Dec 2014
Copy link to clipboard 
Print this post

Hey Jim,

Thanks for the confirmation that my program is correct.
I have got the correct terminals. Just checked again. It was on those pins that i checked the voltage changing.
Hmmmm.......In that case, will have to re-solder the connector strips, just in case.

MPep
 
mpep
Newbie

Joined: 09/11/2014
Location: New Zealand
Posts: 29
Posted: 12:30pm 29 Dec 2014
Copy link to clipboard 
Print this post

Okay, just tried again. No soldering yet.
It appears as though the voltage readings are being done only once. By biasing the joystick over one way, a new, different reading is made, but then doesn't change.
I tried a "pause 200" just before the Loop command with no difference.

Putting the "DO" at the very top, makes it work.
I normally do not re-initialise/setup a pin every time it is needed, but it looks like this is required here.

As in:

Do
Setpin = 2,1
Setpin = 3,1
volts2 = pin(2)
volts3 = pin(3)
'do
print @(150,40) ("Pin2 = "),volts2;
print @(150,80) ("Pin3 = "),volts3;
loop

This code works.Edited by mpep 2014-12-30
 
centrex

Guru

Joined: 13/11/2011
Location: Australia
Posts: 320
Posted: 12:35pm 29 Dec 2014
Copy link to clipboard 
Print this post

mpep
I know you would have, you do have power going to the joystick pots?
Can you measure the outputs with a multimeter.

regards
Cliff
Cliff
 
VK2MCT
Senior Member

Joined: 30/03/2012
Location: Australia
Posts: 120
Posted: 12:39pm 29 Dec 2014
Copy link to clipboard 
Print this post

I would suggest moving the Do:

Setpin = 2,1
Setpin = 3,1
Do
volts2 = pin(2)
volts3 = pin(3)

This allows pins to be set once, and pot 'reads' within the 'loop'

John.
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 12:41pm 29 Dec 2014
Copy link to clipboard 
Print this post

  mpep said  
I normally do not re-initialise/setup a pin every time it is needed, but it looks like this is required here.

As in:

Do
Setpin = 2,1
Setpin = 3,1
volts2 = pin(2)
volts3 = pin(3)
'do
print @(150,40) ("Pin2 = "),volts2;
print @(150,80) ("Pin3 = "),volts3;
loop

This code works.


I would be surprised if you need to continuously initialise the pins but you certainly need to continue to read them when you change the joystick.
 
mpep
Newbie

Joined: 09/11/2014
Location: New Zealand
Posts: 29
Posted: 12:44pm 29 Dec 2014
Copy link to clipboard 
Print this post

Hey Cliff,

Voltage is indeed there,

Hey John,
That is what I thought I had
Just realised what the original problem was. I knew it had an easy solution.
And, now, as per my above post, don't need to re-initialise everytime. That bit bothered me
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9078
Posted: 01:17pm 29 Dec 2014
Copy link to clipboard 
Print this post

  Quote  
do
print @(150,40) ("Pin2 = "),volts2;
print @(150,80) ("Pin3 = "),volts3;
loop


That is your problem.
This will just repeatedly print the last value that was rammed into variables volts2 and volts3.

VK2MCT is correct - your routine should read:


Setpin = 2,1
Setpin = 3,1
Do
volts2 = pin(2)
volts3 = pin(3)
print @(150,40) ("Pin2 = "),volts2;
print @(150,80) ("Pin3 = "),volts3;
loop


This should change the values any time you move the joystick.

Welcome to the forums, BTW, and I also was a big user of PICAXE before the Micromite came along, so I have had to teach myself MMBASIC when PICAXE BASIC was what I knew, so feel free to ask questions here - I am not the only PICAXE user here.

Smoke makes things work. When the smoke gets out, it stops!
 
mpep
Newbie

Joined: 09/11/2014
Location: New Zealand
Posts: 29
Posted: 02:42pm 29 Dec 2014
Copy link to clipboard 
Print this post

Hey Grogster,

Yep I saw the name in both forums All good.
I should have seen my mistake of course, but wanting to see some results, got a bit impatient.

And to BobD, also, all working as expected now.

MPep
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9078
Posted: 03:08pm 29 Dec 2014
Copy link to clipboard 
Print this post

If it makes you feel any better, I had a bit of a hard time doing most things with MMBASIC when coming from PICAXE BASIC. There were certain things that I could take across with me(like DO/LOOP, IF/THEN PRINT etc), but many things were a totally different syntax - which is to be expected. Serial and I2C for example - I had done a lot of serial and dabbled in I2C on the PICAXE, but was lost in MMBASIC for a while!

Hang in there - Micromite really is worth putting in the effort. I have not been over to the PICAXE forums for quite a while, so not sure if they have any new offerings chip-wise over there, but with the Micromite being able to do what it does, I have not needed to look.

...with no disrespect to PICAXE.

I thought I recognised your handle - it must have been from over there!


Smoke makes things work. When the smoke gets out, it stops!
 
mpep
Newbie

Joined: 09/11/2014
Location: New Zealand
Posts: 29
Posted: 04:07pm 30 Dec 2014
Copy link to clipboard 
Print this post

I wasn't going to give up that easily.
I need the mMm for its trig mathematics abilities.

Again, no disrespect, but without SIN/COS and floating point, PICAXE certainly makes things much more difficult. Yes I know of the co-processor chip they offer, the Micromega uM-FPU, but the cost is prohibitive!

Someone just announced they were changing from PICAXE to MM, but the post was deleted! Commercial advertising etc.

I do use MPep on a few forums, it is the PICAXE forum I was most active on.
As I recall, you're in Dunedin.

Happy New Year to you.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9078
Posted: 04:19pm 30 Dec 2014
Copy link to clipboard 
Print this post

Yes, I am a Dunedinite.

  Quote  Someone just announced they were changing from PICAXE to MM, but the post was deleted! Commercial advertising etc.


That's not the first time I have heard of that. The PICAXE forums are quite dramatic with respect to policing and deleting posts about anything non-PICAXE. That is their right, as it is their forum, but it puts many, many people off if they can't even MENTION the competition - some post just want to know if PICAXE can do things BETTER, still fully intending to use said PICAXE, but get deleted.

Ignoring the competition, won't make it go away.......

Now, THESE forums on the other hand - feel free to discuss ANY platform. Members here can talk about anything from raw MIPS and C code, to Arduino, PICAXE and(naturally) the Micromite and/or Maximite.

That is one of the great things about this forum IMHO - you can talk about any platform without fear of being deleted.


Smoke makes things work. When the smoke gets out, it stops!
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024