Advertisement
Guest User

AstroPi 2018-01-18

a guest
Jan 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. from sense_hat import SenseHat
  2. from time import sleep
  3. import time
  4. sense = SenseHat()
  5.  
  6. def temp_h():
  7. th = sense.get_temperature_from_humidity()
  8. th = round(th, 1)
  9. th = str(th)
  10. loading(0)
  11. return th
  12.  
  13. def temp_p():
  14. tp = sense.get_temperature_from_pressure()
  15. tp = round(tp, 1)
  16. tp = str(tp)
  17. return tp
  18.  
  19. def humidity():
  20. h = int(sense.get_humidity())
  21. h = str(h)
  22. loading(1)
  23. return h
  24.  
  25. def date():
  26. d = time.strftime("%Y-%m-%d; %H:%M:%S")
  27. loading(2)
  28. return d
  29.  
  30. def pressure():
  31.  
  32. p = int(sense.get_pressure())
  33. p = str(p)
  34. loading(3)
  35. return p
  36.  
  37. def compass():
  38. M = sense.get_compass_raw()
  39. X = M['x']
  40. Y = M['y']
  41. Z = M['z']
  42.  
  43. X = round(X, 0)
  44. Y = round(Y, 0)
  45. Z = round(Z, 0)
  46. loading(4)
  47. return "{}; {}; {}".format(X, Y, Z)
  48. def acceleration():
  49. acc = sense.get_accelerometer_raw()
  50. x = round(int(acc['x']), 8)
  51. y = round(int(acc['y']), 8)
  52. z = round(int(acc['z']), 8)
  53. loading(5)
  54. return "{}; {}; {}".format(x, y, z)
  55.  
  56. def gyroscope():
  57. gyro_only = sense.get_gyroscope()
  58. p = round(gyro_only['pitch'], 8)
  59. r = round(gyro_only['roll'], 8)
  60. y = round(gyro_only['yaw'], 8)
  61. loading(6)
  62. return "{}; {}; {}".format(p,r,y)
  63.  
  64. def loading(n):
  65. for i in range(8):
  66. sense.set_pixel(n,i, 250, 0, 0)
  67.  
  68. with open( "team_data.csv" , "w" ) as f:
  69. row = "Date; Time; Temperature_hum; Temperature_pres; Humidity; Pressure; Acceleration X; Acceleration Y; Acceleration Z; Gyroscope P; Gyroscope R; Gyroscope Y; Magnetometer X; Magnetometer Y; Magnetometer Z\r\n"
  70. f.write(row)
  71.  
  72. while True:
  73. row = "{}; {}; {}; {}; {}; {}; {}; {}\r\n".format(date(), temp_h(), temp_p(), humidity(), pressure(), acceleration(), gyroscope(), compass())
  74. with open( "team_data.csv" , "a" ) as f:
  75. f.write(row)
  76. loading(7)
  77. sleep(2)
  78. sense.clear()
  79. sleep(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement