Abend,
ich habe zwei Kompasssensoren (verschiedene) und einen guten alten Kompass hier liegen.
Wenn ich mir den normalen Kompass nehme und den drehe zeigt die Nadel immer nach Norden (ist klar dafür ist das Ding ja da).
Die Bewegung der Nadel ist linear (auch klar sie kann ja nicht rumspringen)
So nun zu den Sensoren:
Meine Erwartung war jetzt das sich die Ausgabe linear verhällt (also bei 0/4095 Norden, bei ungefähr 2048 Süden usw...)
Habe ich da irgendwas falsch verstanden?
zwei Unterschiedliche Module an unterschiedlichen PI's angesprochen mit zwei komplett verschiedenen Programmen zeigen mir im Norden und Süden das gleiche und dazwischen nur Müll ...
ich habe mir schon einen Magnet geschnappt und damit versucht lineare Werte zu erzwingen ... ohne echten Erfolg
hat jemand Erfahrung mit dem Mist?
HDMM01:
import smbus
import time
import math
bus = smbus.SMBus (1) # Rev 2 Pi 1
a = ""
x = 4096
y = 4096
mygrad = ""
rXMSB = 255
rXLSB = 255
rYMSB = 16
rYLSB = 16
DEVICE = 0x30 # Geraete Adresse 1D (30)
CONTROL = 0x00 # Steuerregister
XMSB = 0x01
XLSB = 0x02
YMSB = 0x03
YLSB = 0x04
print ("START")
time.sleep(1)
print ("start measurment on i2c")
bus.write_byte_data (DEVICE,CONTROL,2) # Reset des Geraetes
time.sleep(0.1)
while 1:
bus.write_byte_data (DEVICE,CONTROL,1) # set des Geraetes
time.sleep(0.1)
bus.write_byte_data (DEVICE,CONTROL,0) # TM (take mesurement)
time.sleep(0.1)
a = bus.read_byte_data (DEVICE,CONTROL)
rXMSB = bus.read_byte_data (DEVICE,XMSB)
rXLSB = bus.read_byte_data (DEVICE,XLSB)
rYMSB = bus.read_byte_data (DEVICE,YMSB)
rYLSB = bus.read_byte_data (DEVICE,YLSB)
x = (rXMSB << 8) + rXLSB
y = (rYMSB << 8) + rYLSB
print ("x")
print x
print (bin(rXMSB)," ",bin(rXLSB))
print (bin(x))
print ("y")
print y
print (bin(rYMSB)," ",bin(rYLSB))
print (bin(y))
Alles anzeigen
LSM303:
# Embedded file name: /home/pi/gamedata/lsm303.py
# Leonard Ries
# nach Datenverlust dekompiliert 02.01.2015
import smbus
import time
x_data_a = 0
y_data_a = 0
z_data_a = 0
x_data_m = 0
y_data_m = 0
z_data_m = 0
device_a = 25
device_m = 30
out_x_l_a = 40
out_x_h_a = 41
out_y_l_a = 42
out_y_h_a = 43
out_z_l_a = 44
out_z_h_a = 45
out_x_h_m = 3
out_x_l_m = 4
out_z_h_m = 5
out_z_l_m = 6
out_y_h_m = 7
out_y_l_m = 8
i = 0
bus = smbus.SMBus(1)
ctrl_reg1_a = 32
ctrl_reg2_a = 33
ctrl_reg3_a = 34
ctrl_reg4_a = 35
ctrl_reg5_a = 36
ctrl_reg6_a = 37
reference_a = 38
status_reg_a = 39
fifo_ctrl_reg_a = 46
fifo_source_reg_a = 47
int1_cfg_a = 48
int1_src_a = 49
int1_ths_a = 50
int1_duration_a = 51
int2_cfg_a = 52
int2_src_a = 53
int2_ths_a = 54
int2_duration_a = 55
click_cfg_a = 56
click_src_a = 57
click_ths_a = 58
time_limit_a = 59
time_latency_a = 60
time_window_a = 61
cra_reg_m = 0
crb_reg_m = 1
mr_reg_m = 2
sr_reg_m = 9
ira_reg_m = 10
irb_reg_m = 11
irc_reg_m = 12
temp_out_h_m = 49
temp_out_l_m = 50
bus.write_byte_data(device_a, ctrl_reg1_a, 71)
time.sleep(0.01)
bus.write_byte_data(device_a, ctrl_reg4_a, 8)
time.sleep(0.01)
bus.write_byte_data(device_m, cra_reg_m, 140)
time.sleep(0.01)
bus.write_byte_data(device_m, crb_reg_m, 32)
time.sleep(0.01)
bus.write_byte_data(device_m, mr_reg_m, 0)
time.sleep(0.01)
def read():
val_out_x_h_m = bus.read_byte_data(device_m, out_x_h_m)
val_out_x_l_m = bus.read_byte_data(device_m, out_x_l_m)
val_out_z_h_m = bus.read_byte_data(device_m, out_z_h_m)
val_out_z_l_m = bus.read_byte_data(device_m, out_z_l_m)
val_out_y_h_m = bus.read_byte_data(device_m, out_y_h_m)
val_out_y_l_m = bus.read_byte_data(device_m, out_y_l_m)
val_out_x_l_a = bus.read_byte_data(device_a, out_x_l_a)
val_out_x_h_a = bus.read_byte_data(device_a, out_x_h_a)
val_out_y_l_a = bus.read_byte_data(device_a, out_y_l_a)
val_out_y_h_a = bus.read_byte_data(device_a, out_y_h_a)
val_out_z_l_a = bus.read_byte_data(device_a, out_z_l_a)
val_out_z_h_a = bus.read_byte_data(device_a, out_z_h_a)
# x_data_m = ((val_out_x_h_m & 15) << 8) + val_out_x_l_m
# y_data_m = ((val_out_y_h_m & 15) << 8) + val_out_y_l_m
# z_data_m = ((val_out_z_h_m & 15) << 8) + val_out_z_l_m
x_data_m = (val_out_x_h_m << 8) + val_out_x_l_m
y_data_m = (val_out_y_h_m << 8) + val_out_y_l_m
z_data_m = (val_out_z_h_m << 8) + val_out_z_l_m
# x_data_a = (val_out_x_h_a << 8) + val_out_x_l_a >> 4
# y_data_a = (val_out_y_h_a << 8) + val_out_y_l_a >> 4
# z_data_a = (val_out_z_h_a << 8) + val_out_z_l_a >> 4
x_data_a = (val_out_x_h_a << 8) + val_out_x_l_a
y_data_a = (val_out_y_h_a << 8) + val_out_y_l_a
z_data_a = (val_out_z_h_a << 8) + val_out_z_l_a
#schiebe MSB 8 stellen nach links
#kombiniere mit LSB; 8 stellen nach rechts
#ergebnis: MSBLSB
data = [x_data_a,y_data_a,z_data_a,x_data_m,y_data_m,z_data_m]
return data
Alles anzeigen
Bin für jeden Tipp dankbar
Grüße
Leo
Automatisch zusammengefügt:
Ergänzung 0:36
Ich habe grade gemerkt das auch der Analoge Kompass hier spinnt....
Was ist hier bloß los?