Hallo RN,
ich lese so meinen 3D Kompass aus:
Jetzt möchte ich den Winkel nach Norden ausrechnen. Kann mir wer helfen :/Code:#!/usr/bin/env python3 import time import random import smbus import math import serial while True: mitte = 0 bus.write_byte_data(address,0,80) bus.write_byte_data(address,1,32) bus.write_byte_data(address,2,1) time.sleep(0.01) x = y = z = 1.0 x = y = z = 1.0 x1=bus.read_byte_data(address,3) x2=bus.read_byte_data(address,4) z1=bus.read_byte_data(address,5) z2=bus.read_byte_data(address,6) y1=bus.read_byte_data(address,7) y2=bus.read_byte_data(address,8)
Ich würde nun gerne den Winkel unabhängig von der Neigung des Modules berechnen.
LG
Versuch 1:
bringt allerdings nur werte bis 270grad...kann mir wer helfen?Code:#!/usr/bin/env python3 import time import random import smbus import math import serial bus = smbus.SMBus(1) address = 0x1e while True: mitte = 0 bus.write_byte_data(address,0,80) bus.write_byte_data(address,1,32) bus.write_byte_data(address,2,1) time.sleep(0.01) x = y = z = 1.0 x = y = z = 1.0 x1=bus.read_byte_data(address,3) x2=bus.read_byte_data(address,4) x=x1*256.0+x2 if x>32767: x-=65536 z1=bus.read_byte_data(address,5) z2=bus.read_byte_data(address,6) z=z1*256.0+z2 if z>32767: z-=65536 y1=bus.read_byte_data(address,7) y2=bus.read_byte_data(address,8) y=y1*256.0+y2 if y>32767: y-=65536 #print"teyt",x,y,z ang = 180+round(math.atan2(x, y)*(180/math.pi),0) print"winkel",ang







Zitieren

Lesezeichen