A weird issue I’m having w/ grovePi, raspberry Pi B+… here is:
I’m pulling values from the Analog port A0 (or A1 for that matter, same effect). Everything goes well (it’s a rotary button - values varies from 0 to 1023 consistently with the button rotation).
I now plug a chainable RGB LED (2 of them) on D3 (or D2, tried too) and I output values to the port in a while loop (in order to cycle RGB colors). Suddenly AnalogRead sends back 65535 constantly.
If I stop setting digital ports value, analog reads correctly.
All happens like setting a digital port with
grovepi.chainableRgbLed_pattern(MAIN_LED_PIN, x, y)
disturbs reading on analog ports.
Any help appreciated!
I think the problem might be because you are polling the GrovePi too fast. The GrovePi executes a command and saves the output in a buffer before sending it back. So when you run the RGB command and then ask for the analog value, it is possible that it is reading an old value from the buffer which was put there by the RGB led.
It would be great if you could try these: set a delay after the RGB command and the analog read command to see if that helps. Also try doing multiple analog reads to see if you start getting the correct values after a few readings.
Do let us know how it goes.
Reading Karan’s answer, I’m wondering if I wouldn’t have the same issue:
I have a loop (using Python) polling 3 sensors in a row (DHT, air quality and light sensor) then lighting 3 chainable LEDs according to the read values.
I often get “IOError” messages (like 1-3 times a minute).
Is there a recommended delay to be set between successives reads of the sensors and/or LED writes?
Indeed! slowing things down eliminated the 65535 value from the AO channel readout. Thanks a lot!
However, now, I got IOError 3 or 4 times per minute as Tartiflette described.
IOErrors can be because of a lot of issues both in software and hardware. The easiest way to deal with them is to use a try…except block to catch the error and continue using it.
I’m using try/except. But some hardcoded ‘print “IOError”’ remain in grovepi.py
I’m with Benoît here.
Try/Except everywhere and still IOError.
By the way, not coming from the 3 first hardcoded in the groove.py module as I marked these for identification (print ‘IOError’ --> print ‘IOError from GrovePi.py’ and still got “IOError”
IOError comes from somewhere else.
I try to pinpoint them a bit more with no luck.
Couldn’t find other
print “IOError” than those 3 in grovepi.py plus 2 in grove_oled.py.
I did the same kind of identification but didn’t get any unidentified IOError message after a 20 minutes run. I’ll let it run all night and check my log file.
We just updated the GrovePi library on Github so have added a debug flag in the library so it would only show the error messages when the flag is enabled. The flag is disabled by default so you should not see any error messages.
Please update your local repo and run sudo python setup.py install to install the library.