Advertisement
silver2row

ADC_Values_Maybe_Right_But...

Feb 20th, 2025
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. # //////////////////////////////////////
  4. # // ultrasonicRange.py
  5. # // Reads the analog value of the sensor.
  6. # //////////////////////////////////////
  7.  
  8. from time import sleep
  9. import math
  10.  
  11. foot = 12
  12. inch = (1 / 12)
  13. mm   = (inch * 25.4)
  14.  
  15. ms = 550.0  # Time in milliseconds
  16.  
  17. pin = "0"        # sensor, A0, P9_39
  18.  
  19. IIOPATH='/sys/bus/iio/devices/iio:device0/in_voltage'+pin+'_raw'
  20.  
  21. f = open(IIOPATH, "r")
  22.  
  23. ADC = (1.8 / 512) / inch
  24. ADC_mm = (1.8 / 512) / mm
  25.  
  26. try:
  27.  
  28.     print("We are waiting five seconds and then starting")
  29.     sleep(5)
  30.     ADC = str(input("Please type ADC, Thank you!"))
  31.  
  32.     while True:
  33.         if ADC:
  34.             f.seek(1)
  35.             ADC = f.read()[:-1]
  36.             print('data = ' + ADC)
  37.             sleep(ms / 1500)
  38.  
  39.             f.seek(1)
  40.             ADC_mm = f.read()[:-1]
  41.             print('data = ' + ADC_mm)
  42.             sleep(ms / 1500)
  43.  
  44. except KeyboardInterrupt:
  45.     pass
  46.     print("The end...")
  47.  
  48.  
  49. # //  BBB  | Pocket | AIN
  50. # // ----- | ------ | ---
  51. # // P9_39 | P1_19  |  0
  52. # // P9_40 | P1_21  |  1
  53. # // P9_37 | P1_23  |  2
  54. # // P9_38 | P1_25  |  3
  55. # // P9_33 | P1_27  |  4
  56. # // P9_36 | P2_35  |  5
  57. # // P9_35 | P1_02  |  6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement