Page 1 of 1

analog sensors give the same value

Posted: Wed Jul 25, 2018 7:33 am
by gstraath
I have the grovepi light sensor on A0 and the sound sensor on A2. When I read the sensors and print I get the same value for both.

this seems … odd...

Re: analog sensors give the same value

Posted: Wed Jul 25, 2018 9:58 am
by hong.jiang
Hi there, please provide the code and we can talk a look. thanks.

Seeed techsupport team
Bill

Re: analog sensors give the same value

Posted: Thu Jul 26, 2018 11:29 pm
by gstraath
it turns out I was reading the analog sensors after reading a temperature/humidity sensor on D4. putting the codeto read the analog sensors BEFORE the temp/humidity sensor solved the problem.

this specific order for accessing analog/digital sensors should possibly be mentioned somewhere in the documentation.

The complete code can be found here: https://github.com/nosarious/curiousity ... sensors.py

The specific code for the sensor values is here:

this code works, giving distinct values for analog sensors:

Code: Select all

            sensor_value0 = grovepi.analogRead(sensor0)
            sensor_value1 = grovepi.analogRead(sensor1)
            sensor_value2 = grovepi.analogRead(sensor2)
            #these analog sensor values will be distinct

            #temperature sensor data
            temperatureV = 0
            humidityV = 0            

            [temp,humidity] = grovepi.dht(temp_hum_sensor,0)
            if math.isnan(temp) == False and math.isnan(humidity) == False:
                #print("temp = %.02f C humidity = %.02f%%" %(temp, humidity))
                temperatureV = temp
                humidityV = humidity
what doesn't work:

Code: Select all

            #temperature sensor data
            temperatureV = 0
            humidityV = 0

            [temp,humidity] = grovepi.dht(temp_hum_sensor,blue)

            if math.isnan(temp) == False and math.isnan(humidity) == False:
                #print("temp = %.02f C humidity = %.02f%%" %(temp, humidity))
                temperatureV = temp
                humidityV = humidity
                              
            sensor_value0 = grovepi.analogRead(sensor0)
            sensor_value1 = grovepi.analogRead(sensor1)
            sensor_value2 = grovepi.analogRead(sensor2)
            
            #these analog sensor values will be the same
            
I am still having trouble getting information from the GPS, but I shall post that problem in a different post.

Re: analog sensors give the same value

Posted: Mon Jul 30, 2018 11:18 am
by bill.yu
Hi, thanks for the sharing. please post GPS as another issue. thanks.
Bill

Re: analog sensors give the same value

Posted: Sun Mar 10, 2019 12:13 am
by salmanfarisvp
Hu, You are Using the Analog sensor directly with Raspberry Pi...?

Re: analog sensors give the same value

Posted: Thu Mar 28, 2019 12:30 pm
by bill.yu
Hi there,

it uses the Grovepi+, it includes the atmel chip to turn the analog signal to I2C signal. thanks.