Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix analogRead not returning a value #500

Merged
merged 1 commit into from
Jan 19, 2022

Conversation

s2terminal
Copy link
Contributor

Hello.
I have been trying to get light using Grove LightSensor. I have run the following program, but at grovepi.analogRead the program gets stuck like an infinite loop and does not return any value.
I have done the firmware updates and such that have been mentioned in other Issues, but the situation has not improved.

import grovepi
from time import sleep

while True:
    light = grovepi.analogRead(0)
    print(light)
    if light >= 100:
        print("light!")
    sleep(1)

I have modified grovepi.py as per this pull request. The program seems to be working fine. But to be honest, I'm not sure what I fixed. I'm not sure about this pull request.

def read_identified_i2c_block(read_command_id, no_bytes):
        data = [-1]
-       while data[0] != read_command_id[0]:
+       while len(data) <= 1:
                data = read_i2c_block(no_bytes + 1)

        return data[1:]

Related issues

Thanks.

@CleoQc CleoQc merged commit f47d0c8 into DexterInd:master Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants