Skip to content

Instantly share code, notes, and snippets.

@bruceravel
Created April 3, 2015 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruceravel/207ea6b0a53eb091ba8c to your computer and use it in GitHub Desktop.
Save bruceravel/207ea6b0a53eb091ba8c to your computer and use it in GitHub Desktop.
call bus.read_i2c_block_data with exception handling
def read_i2c_block(address):
number = -1
count = 0
count_max = 10
while True:
count = count + 1
if count > count_max: break
try:
number = bus.read_i2c_block_data(address, 1)
break
except IOError:
time.sleep(0.2)
continue
return number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment