daily pastebin goal
65%
SHARE
TWEET

Untitled

a guest Nov 23rd, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rotx = 1.0
  2. roty = 2.0
  3. rotz = 3.0
  4.  
  5. accx = 0.0
  6. accy = 0.0
  7. accz = 0.0
  8.  
  9. rotation = "rot;"
  10. rotation = rotation + (str(rotx))
  11. rotation = rotation + (";")
  12. rotation = rotation + (str(roty))
  13. rotation = rotation + (";")
  14. rotation = rotation + (str(rotz))
  15.  
  16. dataToSend1 = (' '.join(format(ord(x), 'b') for x in rotation))
  17.  
  18.  
  19. import smbus
  20. import socket
  21. import time
  22.  
  23. TCP_IP = '192.168.178.34'
  24. TCP_PORT = 5005
  25. BUFFER_SIZE = 1024
  26. MESSAGE = "Hello, World!"
  27.  
  28. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  29. s.connect((TCP_IP, TCP_PORT))
  30. while True:
  31.  
  32.         s.send(rotation)
  33.         data = s.recv(BUFFER_SIZE)
  34.  
  35.  
  36.         print "received data:", data
  37.         time.sleep(1)
  38.  
  39.         #!/usr/bin/python
  40.         import smbus
  41.         import math
  42.  
  43.         #Register
  44.         power_mgmt_1 = 0x6b
  45.         power_mgmt_2 = 0x6c
  46.  
  47.         def read_byte(reg):
  48.                 return bus.read_byte_data(address, reg)
  49.  
  50.         def read_word(reg):
  51.                 h = bus.read_byte_data(address, reg)
  52.                 l = bus.read_byte_data(address, reg+1)
  53.                 value = (h << 8) + l
  54.                 return value
  55.  
  56.         def read_word_2c(reg):
  57.                 val = read_word(reg)
  58.         if (val >= 0x8000):
  59.         return -((65535 - val) + 1)
  60.         else:
  61.            return val
  62.  
  63.         def dist(a,b):
  64.                 return math.sqrt((a*a)+(b*b))
  65.  
  66.         def get_y_rotation(x,y,z):
  67.                 radians = math.atan2(x, dist(y,z))
  68.                 return -math.degrees(radians)
  69.  
  70.         def get_x_rotation(x,y,z):
  71.                 radians = math.atan2(y, dist(x,z))
  72.                 return math.degrees(radians)
  73.  
  74.         bus = smbus.SMBus(0) # bus = smbus.SMBus(0) fuer Revision 1
  75.         address = 0x68       # via i2cdetect
  76.  
  77.         # Aktivieren, um das Modul ansprechen zu koennen
  78.         bus.write_byte_data(address, power_mgmt_1, 0)
  79.         gyroskop_xout = read_word_2c(0x43)
  80.         gyroskop_yout = read_word_2c(0x45)
  81.         gyroskop_zout = read_word_2c(0x47)
  82.  
  83.  
  84.         rotx = beschleunigung_xout / 16384.0
  85.         roty = beschleunigung_yout / 16384.0
  86.         rotz = beschleunigung_zout / 16384.0
  87.  
  88.         accx = read_word_2c(0x3b)
  89.         accy = read_word_2c(0x3d)
  90.         accz = read_word_2c(0x3f)
RAW Paste Data
Top