analog sensors give the same value

Applications/questions using Raspberry Pi with Seeed products, please post it here.

Moderators: lily.li, violet, salmanfarisvp

Post Reply
gstraath
Pre-kindergarten
Pre-kindergarten
Posts: 6
Joined: Wed Jul 25, 2018 7:13 am

analog sensors give the same value

Post by gstraath » Wed Jul 25, 2018 7:33 am

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...

hong.jiang
Staff
Staff
Posts: 200
Joined: Tue Apr 17, 2018 11:03 am

Re: analog sensors give the same value

Post by hong.jiang » Wed Jul 25, 2018 9:58 am

Hi there, please provide the code and we can talk a look. thanks.

Seeed techsupport team
Bill

gstraath
Pre-kindergarten
Pre-kindergarten
Posts: 6
Joined: Wed Jul 25, 2018 7:13 am

Re: analog sensors give the same value

Post by gstraath » Thu Jul 26, 2018 11:29 pm

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.

bill.yu
Junior-6
Junior-6
Posts: 638
Joined: Mon Apr 02, 2018 11:05 am

Re: analog sensors give the same value

Post by bill.yu » Mon Jul 30, 2018 11:18 am

Hi, thanks for the sharing. please post GPS as another issue. thanks.
Bill

User avatar
salmanfarisvp
Pre-kindergarten
Pre-kindergarten
Posts: 22
Joined: Sun May 20, 2018 2:02 am
Are you a staff member of seeedstudio?: no
Which products/projects are your favorite?: Linklt One , BeagleBone Green , ReSpaker
Contact:

Re: analog sensors give the same value

Post by salmanfarisvp » Sun Mar 10, 2019 12:13 am

Hu, You are Using the Analog sensor directly with Raspberry Pi...?

bill.yu
Junior-6
Junior-6
Posts: 638
Joined: Mon Apr 02, 2018 11:05 am

Re: analog sensors give the same value

Post by bill.yu » Thu Mar 28, 2019 12:30 pm

Hi there,

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

Post Reply