Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #
  3. # Copyright (c) 2014 OpenElectrons.com
  4. # Explorer example script.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License version 2 as
  8. # published by the Free Software Foundation.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. #
  19. # History:
  20. # Date Author Comments
  21. # 04/15/14 Michael Initial authoring.
  22. #
  23.  
  24. import time
  25. import os, sys
  26. import explorerlib
  27.  
  28. print "Connect I2C device..."
  29. time.sleep(3)
  30. addr = 0x0 # DO NOT change this address!!!
  31. i2c = explorerlib.Explorer(addr)
  32. found = i2c.ping(0x00)
  33.  
  34. # Checks for connection on all I2C addresses until connection is found
  35. while found == -1:
  36. if (addr < 0xef):
  37. addr = addr + 1
  38. i2c = explorerlib.Explorer(addr)
  39. found = i2c.ping(0x00)
  40. else:
  41. addr = 0x00
  42.  
  43. print "--------------------"
  44. print "7 bit address: " + str(hex(addr/2)) # RaspberryPi will find device at this address
  45. print "8 bit address: " + str(hex(addr)) # Use this address for use with OpenElectrons_i2c.py
  46. print i2c.GetFirmwareVersion()
  47. print i2c.GetVendorName()
  48. print i2c.GetDeviceId()
  49. print "--------------------"
  50.  
  51. #Press Pause/Break button on your keyboard to stop the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement