Modifications

Sauter à la navigation Sauter à la recherche
1 109 octets ajoutés ,  18 novembre 2018 à 20:00
Ligne 121 : Ligne 121 :     
{{ambox|text= '''POUR CALIBRER:''' faire tourner le senseur sur 360 degrés. Le mode de calibration s'interrompt entre 5 à 10 secondes.}}
 
{{ambox|text= '''POUR CALIBRER:''' faire tourner le senseur sur 360 degrés. Le mode de calibration s'interrompt entre 5 à 10 secondes.}}
 +
 +
<syntaxhighlight lang="python">from time import sleep
 +
from mag3110 import MAG3110, DR_OS_1_25_32
 +
 +
i2c = I2C( sda=Pin(2), scl=Pin(4) )
 +
mag = MAG3110( i2c )
 +
 +
print( "CHIP ID: %s" % mag.who_am_i() )
 +
 +
# Fixer le débit de donnée à 1.25 Hz et l'oversampling à 32 fois
 +
#  mag.setDR_OS( DR_OS_1_25_32 )
 +
 +
# Activer le senseur
 +
mag.start()
 +
 +
while True:
 +
# Pas encore calibré ?
 +
if not mag.is_calibrated:
 +
# Pas en cours de calibration ?
 +
if not mag.is_calibrating:
 +
print( "Démarrer le mode de calibration!")
 +
mag.enter_calibration()
 +
else:
 +
    # collecter des données de calibration
 +
mag.step_calibration()
 +
else:
 +
print( "Calibré" )
 +
break
 +
 +
# Afficher les infos durant la calibration
 +
#  (x,y,z) tuple
 +
# xyz = mag.read()
 +
# print( xyz )
 +
 +
print( 'Offset utilisateur = %s,%s,%s' % mag.user_offset() )
 +
#mag.setDR_OS( DR_OS_1_25_32 )
 +
while True:
 +
    if mag.data_ready:
 +
        print( 'x,y,z = %s,%s,%s ' % mag.read() )
 +
        heading = mag.heading()
 +
        print( 'Direction Nord = ', heading )
 +
        print( '-'*40 )
 +
        sleep( 3 )
 +
 +
print( "That's the end folks")</syntaxhighlight>
    
== Où acheter ==
 
== Où acheter ==
29 917

modifications

Menu de navigation