• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoPythonControl pcDuino’s ADC via Python
Previous Next

Control pcDuino’s ADC via Python

Posted by: Alvin Jin , January 8, 2014

[vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Hardware list” tab_id=”1389153395-1-91″][vc_column_text]1*pcDuino V1

1*Linear/Slide Potentiometer of Linker Kit for pcDuino/Arduino

Some wires[/vc_column_text][/vc_tab][vc_tab title=”Connection diagram” tab_id=”1389153395-2-55″][vc_column_text]

Potentiometer connects to pcDuino’s A2/GND/5VCC pins

[/vc_column_text][/vc_tab][vc_tab title=”Download Python’s library file” tab_id=”1389153906672-2-10″][vc_column_text]

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

Next we creat a adc_test file under Samples folder, and code is as below:

  1. import time
  2. from adc import analog_read
  3. def delay(ms):
  4.     time.sleep(1.0*ms/1000)
  5. def setup():
  6.                 print “read channel ADC2 value ,the V-REF = 3.3V”
  7.                 delay(3000)
  8. def loop():
  9.     while(1):
  10.         value = analog_read(2)
  11.         voltage = (value * 3.3)/4096
  12.         print (“value =  %4d”%value)
  13.         print (“voltage =  %4.3f  V” %voltage)
  14.         delay(100)
  15. def main():
  16.     setup()
  17.     loop()
  18. main()

Save and compile

  1. python adc_test.py

Display output, adjust the potentiometer, the numerical changes.

[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Tags: Python

Share!
Tweet

Alvin Jin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors