• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoArduino-ish ProgramADCUse Python to read ADC of pcDunio
Previous Next

Use Python to read ADC of pcDunio

Posted by: admin , November 28, 2014

In this post,we are going to use Linker Slide Potentiometer to show how to use Python to read ADC of pcDuino.

1. We install Linker slide potentiometer on pcDuino. It is connected to [A2 GND, 5V] of pcDuino.

connect

 

2. Download Python library:

 

$git clone https://github.com/pcduino/python-pcduino.git

After that, we will see the library files under pcduino. Create a directory named ‘adc_test’ under directory ‘Samples’, the following is the code:

 

import time
from adc import analog_read
 
def delay(ms):
    time.sleep(1.0*ms/1000)
 
def setup():
                print "read channel ADC2 value ,the V-REF = 3.3V"
                delay(3000)
 
def loop():
    while(1):
        value = analog_read(2)
        voltage = (value * 3.3)/4096
        print ("value =  %4d"%value)
        print ("voltage =  %4.3f  V" %voltage)
        delay(100)
 
def main():
    setup()
    loop()
 
main()

223020yfzssgufq4chguhs

 

Save, and run:

$python adc_test.py

Adjust the slider, we can see the number changes:

 

223338m8ty2q6kbyp33zax

 

adc_test

Share!
Tweet

admin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors