Instable port reading

Hi Karan,

Is there a preferred way to handle these instable port readings?
Although my programming is functioning, it is far from being perfect.
Sometimes, due to this, my program comes in a state where it demands the user to push a button, but if I am not looking at the system, it just remains there idle…

I am using a kind of menu system that is provoked by a button and sometimes the system comes in that state even when it is not demanded by the user.

Thanks for your reply,

Freddy

@cluckers,
We are testing a new firmware and software which is much better at handling the port reading. It is much much faster and should not give IOErrors too. Can you give it a shot and see if help.

First run the DI update to make sure all the software is the latest. The goto the firmware folder here: home/pi/Desktop/GrovePi/Firmware/Source/v1.2/grove_pi_v1_2_7

then install the new firmware:

avrdude -c gpio -p m328p -U flash:w:grove_pi_v1_2_7.cpp.hex

after this, run the firmware check here to make sure that you are running 1.2.7

After this install the newer python library from here by running:

sudo python setup.py install
from the same folder.

Can you try this and let us know if the GrovePi works better for you or if you still face any problems.

Hi Karan,

Thanks for your concern. I just recieved a new raspberry 3 and govepi+ kit. I will use Jessie and install the grovepi software the old fashioned way. After that I will test your 1.2.7 software on this new hardware. I have more and more doubts that my old grovepi has some hardware problems, because with firmware 1.2.6 the temperature and humidity sensor no longer works. I used the white and blue version and could not have any other readings than ‘nan’.
I will test all first on the new hardware. I will do this somewhere next week and will keep you informed about my progressions.
Will 1.2.7 also solve the ‘chainable led’ problem?

Kind regards,

Freddy

Hello,

I’m also facing issues with the analog inputs, as I somethings get 255 as value. I’m using a potentiometer, and if I leave it a 0, it sometimes incorrectly read 255, every 10 minutes.
I’m using firmware 1.2.7.
Any solution for this issue?

Thanks,
Ben

Hi @bben.pub,

Can you check the speed at which the readings are taken. To find out how many readings are taken in a second. You should do the following to your code.

  • Make sure to import time library and comment out any time.sleep() statements.

  • Before the while loop add the following statements
    count=0
    start = time.time()

  • Inside the while condition check for the time like this
    while (time.time()-start)<=1:

  • Increment the count after the printing the sensor reading like
    count=count+1

  • Outside the while loop print the count value
    print("Number of readings per second is %d"%count)

If the count is more than 100 per second then add delays to your program.

Sample code is posted below, this is to count the readings of an analog sensor for 5 seconds:

import time
import grovepi
#Sensor connected to A0 Port
sensor = 15             # Pin 14 is A0 Port.
grovepi.pinMode(sensor,"INPUT")
count=0
start = time.time()
while (time.time()-start)<=5:
    try:
        sensor_value = grovepi.analogRead(sensor)
        print ("sensor_value = %d" %sensor_value)
        #time.sleep(.5)
        count=count+1
    except IOError:
        print ("Error")
print count

Please let us know if this helps,
-Shoban

Thanks @Shoban,

I didn’t test your code yet, but in my code, I have a delay:

time.sleep(0.5)
So it’s not read more than twice per second.

I’ll try you code later and report on this.

Best regards,
Ben