Skip to content

Instantly share code, notes, and snippets.

@BoKKeR
Created December 3, 2017 17:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BoKKeR/edb7cc967938d57c979d856607eaa658 to your computer and use it in GitHub Desktop.
Save BoKKeR/edb7cc967938d57c979d856607eaa658 to your computer and use it in GitHub Desktop.
Python script that visualises the L3G4200D gyro sensor
import threading
import time
import bpy
import serial
import re
import sys
arduino = serial.Serial('COM4', 115200, timeout=.1)
class RotateCubeThread (threading.Thread):
def __init__(self, threadID, name):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
def get_serial_data(self):
data = arduino.readline()[:-2] #the last bit gets rid of the new-line chars
if data:
print(data)
data = str(data)
result = [float(d) for d in re.findall(r"[-+]?\d*\.\d+|\d+", data)]
print(result)
return result
def run(self):
FPS = 1
is_running = True
tick = time.time()
loop = 0
x = 0
knob = bpy.data.objects["Cube"]
while is_running is True:
rotation_degrees = self.get_serial_data()
knob.rotation_mode = 'XYZ'
knob.rotation_euler = (0,0,0)
print(rotation_degrees)
if not rotation_degrees:
print ("buffer")
else:
knob.rotation_euler = ( rotation_degrees[0] * 0.00875, rotation_degrees[1] * 0.00875, rotation_degrees[2] * 0.00875)
tick = time.time()
loop += 1
x += 1
#Make thread
thread = RotateCubeThread(1, "thread")
thread.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment