sparkfun MAG3110 Скачать руководство пользователя страница 4

#include <SparkFun_MAG3110.h> 
 
MAG3110 mag = MAG3110(); //Instantiate MAG3110 
 
void setup() { 
  Serial.begin(9600); 
 
  mag.initialize(); //Initializes the mag sensor 
  mag.start();      //Puts the sensor in active mode 

 
void loop() { 
 
  int x, y, z; 
  //Only read data when it's ready 
  if(mag.dataReady()) { 
    //Read the data 
    mag.readMag(&x, &y, &z); 
 
    Serial.print("X: ");
    Serial.print(x); 
    Serial.print(", Y: "); 
    Serial.print(y); 
    Serial.print(", Z: "); 
    Serial.println(z); 
 
    Serial.println("--------"); 
  } 

Calling 

mag.initialize()

 sets up the sensor and checks whether a MAG3110 is connected properly. If 

mag.error

 is true, the Arduino was unable to talk to the

MAG3110! When initialized, the magnetometer is set to standby mode with all offsets set to 0. To put the magnetometer in active mode and start sampling, simply
write 

mag.start()

You can check whether any new data is ready using the 

mag.dataReady()

 function. This will return true if new data is available.

You can read all three axes using the 

mag.readMag()

 function. Don’t be afraid of the & symbol! This simply means we are giving the address of the variables to the

function so that they can be filled with the data. If this seems confusing, you might want to read about pointers.

If you run this sketch and open up Tools->Serial Monitor, you should see the following:

Other functions can be seen in the 

SparkFun-MAG3110-Other.ino

 sketch:

Содержание MAG3110

Страница 1: ...r You may want to use something like this 3 3V Low Dropout Regulator LDO For the rest of the items you will need see the wish list below SparkFun Logic Level Converter Bi Directional BOB 12009 If you...

Страница 2: ...upply Voltage 1 95V to 3 6V GND Must be connected to ground SDA Serial Data pin for I C Communication SCL Serial Clock pin for I C Communication INT Interrupt pin high when new data is ready You may n...

Страница 3: ...SCL Leonard Micro 2 SDA 3 SCL Due 20 SDA 21 SCL SDA1 SCL1 SparkFun MAG3110 Library SparkFun has created a library to make it easier to get readings from the MAG3110 sensor It also has code to calibra...

Страница 4: ...lk to the MAG3110 When initialized the magnetometer is set to standby mode with all offsets set to 0 To put the magnetometer in active mode and start sampling simply write mag start You can check whet...

Страница 5: ...n microTeslas Serial print X Serial print xf Serial print Y Serial print yf Serial print Z Serial println zf Serial println A few functions to point out from the example above mag setDR_OS This functi...

Страница 6: ...0 Triggered You can also do triggered measurements while in active mode This is more advanced and is covered in the datasheet Calibration All these functions are great but what if you need to find a p...

Страница 7: ...e calibration earlier by calling mag exitCalMode Please note that the calibration may be offset if you do not calibrate enough If you have not calibrated the MAG3110 calling mag readHeading will only...

Страница 8: ...library allows You can use an accelerometer in conjunction with this device to create a tilt compensated compass SparkFun has a variety of accelerometers available including the ADXL345 To get you sta...

Отзывы: