-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathAnalogReadSerial.py
More file actions
30 lines (26 loc) · 1.01 KB
/
AnalogReadSerial.py
File metadata and controls
30 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
AnalogReadSerial.py
This example reads an analog input on pin 0, prints the result from the ADC buffer and converts it
to a decimal value to represent the voltage in the pin.
This example code is in the public domain.
Revision History
------------------------------------------------
Author Date Description
------------------------------------------------
Carlos Mata 1-29-2015 Example created
"""
import mraa #calls the MRAA library
import time #calls the time library
#Setup of variable and conditions
DecimalValue = 0.0 #Initialization of value converted
ADCValue = 0.0 #Initialization of value to be read
x = mraa.Aio(0) #We are going to use pin A0 in the Arduino Expansion Board
try:
while True:
x.setBit(12) #Use 12 bits of the ADC
ADCValue = x.read()
DecimalValue = ADCValue/819.0 #Conversion to a Decimal Value
print "ADCValue = ", ADCValue,"\t DecimalValue =", DecimalValue
time.sleep(1) #Wait a second and read again the ADC buffer
except KeyboardInterrupt:
print ""