silver2row

1-2-3, Testing, 1-2-3

Feb 14th, 2025 (edited)
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. # Mostly from docs.beagleboard.org
  4.  
  5. # //////////////////////////////////////
  6. # // ultrasonicRange.py
  7. # // Reads the analog value of the sensor.
  8. # //////////////////////////////////////
  9.  
  10. from time import sleep
  11. import math
  12.  
  13. ms = 550  # Time in milliseconds
  14.  
  15. pin = "0"        # sensor, A0, P9_39
  16.  
  17. IIOPATH='/sys/bus/iio/devices/iio:device0/in_voltage'+pin+'_raw'
  18.  
  19. f = open(IIOPATH, "r")
  20.  
  21. data = ((pow(2, 12) / 3.3) * (1.45) * 0.001)
  22.  
  23. volt = (1.45 * (1.8 / pow(2, 12)))
  24.  
  25. try:
  26.     while True:
  27.         f.seek(0)
  28.         data = f.read()[:-1]
  29.         print('data = ' + data)
  30.         sleep(ms / 1500)
  31.         f.seek(1)
  32.         volt = f.read()[:-1]
  33.         print('More Data = ' + volt)
  34.         sleep(ms / 1500)
  35. except KeyboardInterrupt:
  36.     pass
  37.     print("The end...")
Advertisement
Add Comment
Please, Sign In to add comment