-
Notifications
You must be signed in to change notification settings - Fork 14
/
SparkFun_MAG3110_Basic.ino
executable file
·59 lines (49 loc) · 1.41 KB
/
SparkFun_MAG3110_Basic.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* *********************************************
* SparkFun_MAG3110_Basic
* Triple Axis Magnetometer Breakout - MAG3110
* Hook Up Guide Example
*
* Utilizing Sparkfun's MAG3110 Library
* A basic sketch that reads x y and z readings
* from the MAG3110 sensor
*
* George B. on behalf of SparkFun Electronics
* Created: Sep 22, 2016
* Updated: n/a
*
* Development Environment Specifics:
* Arduino 1.6.7
*
* Hardware Specifications:
* SparkFun MAG3110
* Bi-directional Logic Level Converter
* Arduino Micro
*
* This code is beerware; if you see me (or any other SparkFun employee) at the
* local, and you've found our code helpful, please buy us a round!
* Distributed as-is; no warranty is given.
* *********************************************/
#include <SparkFun_MAG3110.h>
MAG3110 mag = MAG3110(); //Instantiate MAG3110
void setup() {
Serial.begin(9600);
Wire.begin(); //setup I2C bus
Wire.setClock(400000); // I2C fast mode, 400kHz
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("--------");
}
}