關於用Python控制pcDuino的ADC 1.咱們這裏用的是電位器作測試
電位器分別鏈接到pcduino的A2,GND,5VCC引腳; 2.下載Python庫文件,
- git clone https://github.com/pcduino/python-pcduino.git
複製代碼
複製下來後,能夠看到pcduino這個文件夾下面,是咱們常常須要用的庫文件, 接下來在Samples下創建adc_test文件夾並開始編寫項目,下面是主程序:
- 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()
-
複製代碼
保存後,進行編譯
顯示輸出,調整電位器,數值變化
源代碼 adc_test.zip |