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.
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()
Save, and run:
$python adc_test.py
Adjust the slider, we can see the number changes:
Leave a Reply
You must be logged in to post a comment.