Skip to content

tof10120 code issue #2

Description

@sohilbhr

when i try to run this code in my Rpi the sensor can't give me reads every time sometimes move to except what can i do to fix the code?
and sorry for the code itried to put it in code tag but it still appear like this
code:

`import smbus
import time

i2c_ch = 1
i2c_address = 0x52

bus = smbus. SMBus ( i2c_ch )

while True :

try :

    bus. write_byte ( i2c_address , 0 )
    time . sleep ( 0.01 )
   
    b1 = bus. read_byte_data ( i2c_address , 0 )
    b2 = bus. read_byte_data (i2c_address , 1 )
           
    word = ( b1 << 8 ) + b2
    print ( word )

    time . sleep ( 1 )

except OSError :
    print ( 'error' )`

best regards
sohil

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions