Continuously reading ADC pins

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Ridley Walker
Posts: 19
Joined: Thu Jun 25, 2015 1:04 am

Continuously reading ADC pins

Post by Ridley Walker » Wed Jun 29, 2016 5:40 pm

As anybody that has seen my posts here can plainly see, I am a complete noob at this stuff.
I bought the Pyboard in the hopes that i could use it to control a small hobby greenhouse,
Temp, ventilation, etc.
I have been through all the "beginners" tutorials and feel that I understand but a minuscule part
of what I need to know to accomplish my goal.

I have been trying to continuously poll ADC pin X19 and print value to screen - or do anything
else for that matter. I can poll the pin in REPL per the tutorial, but cannot make it repeat.

I am acutely aware that i am grotesquely out of place here in that I know nothing and everybody
else here seems to know everything, so please be aware that I have searched, in vain, for a beginners
forum more appropriate to my "noobness"
If someone will be kind enough to post explicit code to poll adc pins I will be very grateful

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Continuously reading ADC pins

Post by deshipu » Wed Jun 29, 2016 6:58 pm

I'm not sure I understand what you need exactly. What's wrong with the code at http://docs.micropython.org/en/latest/p ... conversion ?

Ridley Walker
Posts: 19
Joined: Thu Jun 25, 2015 1:04 am

Re: Continuously reading ADC pins

Post by Ridley Walker » Wed Jun 29, 2016 9:28 pm

indeed it does, but it reads just once, I need continuously polling
rate can be seconds - not critical at all

Edit to add:
My Pyboard is rev. 1
I am running Lenox (latest kernel, whatever that is) and Ubuntu 14.04.1

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Continuously reading ADC pins

Post by deshipu » Wed Jun 29, 2016 10:18 pm

Can't you just call it repeatedly in a loop? What do you want to do with the reading once you have it?

If you don't know about loops, you should first try and do the Python tutorial, available at https://docs.python.org/3/tutorial/
That will solve a lot of your problems, present and future.

Ridley Walker
Posts: 19
Joined: Thu Jun 25, 2015 1:04 am

Re: Continuously reading ADC pins

Post by Ridley Walker » Wed Jun 29, 2016 10:49 pm

as i have said, i have done the tutorials - blink the LEDs, etc> So, that's good
When i try to read the ADC pin and loop similar to blinking an LED it fails...

If my frustration shows, it's because well, I am. It's not easy being this ignorant!

Edit to add:
As i have said elsewhere on this forum, I'm a 76 yr. old retired electrical engineer.
My early career was in D/A, A/d conversion ( google Philbrick Opamps to get an idea).
later career was almost entirely in battery backup systems and low voltage switching
power supplies. All of which amount exactly zero qualifications for this stuff.

Thank you for your patience...

User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: Continuously reading ADC pins

Post by rcolistete » Thu Jun 30, 2016 3:07 am

My Pyboard v1.1 works well with this code :

Code: Select all

import pyb
import math
while True:
    adcint = pyb.ADC(pyb.Pin('X4')).read()
    print("Analog reading of port X4 = %f V" % (adcint*3.3/4095))
    pyb.delay(50)
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Continuously reading ADC pins

Post by deshipu » Thu Jun 30, 2016 7:58 am

Ridley Walker wrote:as i have said, i have done the tutorials - blink the LEDs, etc> So, that's good
When i try to read the ADC pin and loop similar to blinking an LED it fails...
You did the PyBoard tutorials (which are written with an assumption that you already know Python), but what I linked is a Python tutorial -- how to use the Python language itself. Since PyBoard is programmed in Python, it really helps to know this language. Don't worry, it's very easy to learn -- some say it was designed for people who don't know it.

You say it fails. Can you show us your code and the error message you are getting? I'm sure we can massage into working.

Ridley Walker
Posts: 19
Joined: Thu Jun 25, 2015 1:04 am

Re: Continuously reading ADC pins

Post by Ridley Walker » Thu Jun 30, 2016 4:02 pm

Des,
I re-scanned all the general discussion pages and found these two, both of which are as advertised
I have been doing adc.read(). Works great with pot.read()!

pot = pyb.ADC('X1')
while True:
pot.read()
pyb.delay(100)

===============================

import pyb

pot = pyb.ADC('X1')
while True:
x = pot.read()
print(x)
pyb.delay(100)

Now on to other things, like controlling temperature with a small heater based on the results of the pot.read.
Thanks for your prompt replies. Next time i will try to do a little better search.
Thanks also to dhylands who posted, the last response

Post Reply