Hello,
There are still serious issues with the analog ports and reading them. I was doing some testing where I am using all three (A0, A1, A2) with different sensors on each. A0 has the potentiometer (Rotary Angle Sensor), A1 has the Air Quality v1.3 sensor, and A2 has the HCHO sensor.
If I run each of the sample apps by themselves, they appear to work.
If I run the following program - which queries each one by one - the values are duplicated and overwritten in a way that they are not accurate, and each is reporting back random numbers from the other ports.
I finally nailed this down by running the potentiometer example, and it consistently outputs:
('sensor_value =', 424, ' voltage =', 2.07, ' degrees =', 124.2, ' brightness =', 105)
('sensor_value =', 424, ' voltage =', 2.07, ' degrees =', 124.2, ' brightness =', 105)
('sensor_value =', 424, ' voltage =', 2.07, ' degrees =', 124.2, ' brightness =', 105)
('sensor_value =', 424, ' voltage =', 2.07, ' degrees =', 124.2, ' brightness =', 105)
('sensor_value =', 424, ' voltage =', 2.07, ' degrees =', 124.2, ' brightness =', 105)
('sensor_value =', 424, ' voltage =', 2.07, ' degrees =', 124.2, ' brightness =', 105)
('sensor_value =', 424, ' voltage =', 2.07, ' degrees =', 124.2, ' brightness =', 105)
('sensor_value =', 424, ' voltage =', 2.07, ' degrees =', 124.2, ' brightness =', 105)
('sensor_value =', 424, ' voltage =', 2.07, ' degrees =', 124.2, ' brightness =', 105)
Without touching it at all … I then run my program, and get the following:
pi@raspberrypi ~/GrovePi/Software/Python $ sudo python wovyn_air_quality.py
Beginning main sensor loop ...
pot_value = 424 pot_voltage = 2.07
Low pollution
Air Quality = 424
HCHO = 424 voltage = 2.0703
PM Concentration = 143.36
Error Count = 0
pot_value = 56 pot_voltage = 0.27
Air fresh
Air Quality = 69
HCHO = 69 voltage = 0.3369
PM Concentration = 143.36
Error Count = 0
pot_value = 22927 pot_voltage = 112.06
Air fresh
Air Quality = 70
HCHO = 70 voltage = 0.3418
PM Concentration = 143.36
Error Count = 0
pot_value = 56 pot_voltage = 0.27
Note that I am NOT touching the potentiometer at all!! It should be a steady 424 at all times. This occurs with ALL analog sensors if I try to read more than one in the same loop … no matter the combination of analog sensors.
In my program I am simply trying to read each sensor in a main loop, within try/exception blocks, and print the outputs. I have found the ADC values often are complete corrupt (jumping into the 20,000-40,000 range) and the values for all of the sensors will come back identical.
Something is VERY wrong … or my program is VERY broken.
My program:
#!/usr/bin/env python
#
# USAGE
#
# Connect the dust sensor to Port 8 on the GrovePi. The dust sensor only works on that port
# Connect the Grove Rotary Angle Sensor to analog port A0
# Connect the Grove Air Quality Sensor v1.3 to analog port A1
# Connect the Grove HCHO Sensor to analog port A2
#
import time
import grovepi
# Set-up the Rotary Angle Sensor to analog port A0
potentiometer = 0
grovepi.pinMode(potentiometer,"INPUT")
# Set up the Air Quality Sensor - on port A1
air_sensor = 1
grovepi.pinMode(air_sensor,"INPUT")
# Set up the HCHO Sensor to analog port A2
hcho_sensor = 2
grovepi.pinMode(hcho_sensor,"INPUT")
# Vcc of the grove interface is normally 5v
grove_vcc = 5
adc_ref = 5
# initialize the error counter
errorCount = 0
# initialize PM Concentration
pmConc = 0
print "Beginning main sensor loop ..."
while True:
try:
# Read sensor value from potentiometer
pot_value = grovepi.analogRead(potentiometer)
# Calculate voltage
pot_voltage = round((float)(pot_value) * adc_ref / 1023, 2)
print "pot_value = ", pot_value, " pot_voltage =", pot_voltage
except IOError:
# print ("Error")
errorCount += 1
try:
# Get AQ sensor value
air_quality = grovepi.analogRead(air_sensor)
if air_quality > 700:
print ("High pollution")
elif air_quality > 300:
print ("Low pollution")
else:
print ("Air fresh")
print " Air Quality = ", air_quality
time.sleep(1)
except IOError:
# print ("Error")
errorCount += 1
try:
# Get HCHO sensor value
hcho = grovepi.analogRead(hcho_sensor)
# Calculate voltage
voltage = (hcho * grove_vcc * 1.0) / 1024
print " HCHO = ", hcho, "voltage = %.4f" % voltage
time.sleep(1)
except IOError:
# print ("Error")
errorCount += 1
try:
# Get PM sensor value
[new_val,conc] = grovepi.dustSensorRead()
if new_val and conc > 1:
pmConc = conc
print " PM Concentration = ", pmConc
time.sleep(1)
except IOError:
# print ("Error")
errorCount += 1
print " Error Count = ", errorCount
time.sleep(1)
Let me know what you are thinking?