Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import board
  2. import busio
  3.  
  4. # Initialize and lock the I2C bus.
  5. i2c = busio.I2C(board.SCL, board.SDA)
  6. while not i2c.try_lock():
  7.     pass
  8.  
  9. # Mimick the DCFURS badge code
  10. try:
  11.   i2c.writeto(0x44, bytes([0x15]), stop=False)
  12.   result = bytearray(5)
  13.   i2c.readfrom_into(0x44, result)
  14.   print(result)
  15. except OSError:
  16.   print('Unknown error')
  17.  
  18. # Unlock the I2C bus when finished.  Ideally put this in a try-finally!
  19. i2c.unlock()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement