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 ZealandPosts: 29 |
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: AustraliaPosts: 5923 |
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 ZealandPosts: 29 |
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 ZealandPosts: 29 |
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. |
||||
centrex Guru Joined: 13/11/2011 Location: AustraliaPosts: 320 |
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: AustraliaPosts: 120 |
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: AustraliaPosts: 935 |
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 ZealandPosts: 29 |
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 ZealandPosts: 9078 |
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 ZealandPosts: 29 |
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 ZealandPosts: 9078 |
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 ZealandPosts: 29 |
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 ZealandPosts: 9078 |
Yes, I am a Dunedinite. 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 |