Difference between revisions of "MAG3110 electronic compass module three axis magnetic sensor magnetometer"
(→Interface function) |
(→Usage) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= Introduction = | = Introduction = | ||
+ | |||
+ | [[File:MAGSensorA.png|640px]] | ||
+ | |||
+ | [[File:MAGSensorB.png|640px]] | ||
MAG3110 is a small, low -power digital 3D magnetic sensor with wide dynamic range , capable of operating in a PCB with high external magnetic field. The sensor device can be used in combination with the sensor which has triaxial accelerometer to produce accurate way navigation information . It uses a standard IIC output interface and smart embedded features , capable of measuring up to 10 gauss local magnetic field , the output data rates up to 80Hz. | MAG3110 is a small, low -power digital 3D magnetic sensor with wide dynamic range , capable of operating in a PCB with high external magnetic field. The sensor device can be used in combination with the sensor which has triaxial accelerometer to produce accurate way navigation information . It uses a standard IIC output interface and smart embedded features , capable of measuring up to 10 gauss local magnetic field , the output data rates up to 80Hz. | ||
Line 31: | Line 35: | ||
= Usage = | = Usage = | ||
− | Hardware: | + | '''Hardware:''' |
− | Arduino UNO | + | 1 x Arduino UNO |
− | Linker Base Shield | + | 1 x Linker Base Shield |
− | Dupont line | + | 4 x Dupont line |
− | MAG3110 | + | 1 x MAG3110 |
− | Wiring Diagram: | + | '''Wiring Diagram:''' |
Arduino MAG3110 | Arduino MAG3110 | ||
Line 57: | Line 61: | ||
Test Code: | Test Code: | ||
− | #include <Wire.h> | + | #include <Wire.h> |
− | #define MAG_ADDR 0x0E //7-bit address for the MAG3110, doesn't change | + | #define MAG_ADDR 0x0E //7-bit address for the MAG3110, doesn't change |
− | void setup() | + | void setup() |
− | { | + | { |
Wire.begin(); // join i2c bus (address optional for master) | Wire.begin(); // join i2c bus (address optional for master) | ||
Serial.begin(9600); // start serial for output | Serial.begin(9600); // start serial for output | ||
config(); // turn the MAG3110 on | config(); // turn the MAG3110 on | ||
− | } | + | } |
− | void loop() | + | void loop() |
− | { | + | { |
print_values(); | print_values(); | ||
delay(5); | delay(5); | ||
− | } | + | } |
− | void config(void) | + | void config(void) |
− | { | + | { |
Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E | Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E | ||
Wire.write(0x11); // cntrl register2 | Wire.write(0x11); // cntrl register2 | ||
Line 81: | Line 85: | ||
Wire.write(1); // send 0x01, active mode | Wire.write(1); // send 0x01, active mode | ||
Wire.endTransmission(); // stop transmitting | Wire.endTransmission(); // stop transmitting | ||
− | } | + | } |
− | void print_values(void) | + | void print_values(void) |
− | { | + | { |
Serial.print("x="); | Serial.print("x="); | ||
Serial.print(readx()); | Serial.print(readx()); | ||
Line 92: | Line 96: | ||
Serial.print("z="); | Serial.print("z="); | ||
Serial.println(readz()); | Serial.println(readz()); | ||
− | } | + | } |
− | int readx(void) | + | int readx(void) |
− | { | + | { |
int xl, xh; //define the MSB and LSB | int xl, xh; //define the MSB and LSB | ||
Line 118: | Line 122: | ||
int xout = (xl|(xh << 8)); //concatenate the MSB and LSB | int xout = (xl|(xh << 8)); //concatenate the MSB and LSB | ||
return xout; | return xout; | ||
− | } | + | } |
− | int ready(void) | + | int ready(void) |
− | { | + | { |
int yl, yh; //define the MSB and LSB | int yl, yh; //define the MSB and LSB | ||
Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E | Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E | ||
Line 143: | Line 147: | ||
int yout = (yl|(yh << 8)); //concatenate the MSB and LSB | int yout = (yl|(yh << 8)); //concatenate the MSB and LSB | ||
return yout; | return yout; | ||
− | } | + | } |
− | int readz(void) | + | int readz(void) |
− | { | + | { |
int zl, zh; //define the MSB and LSB | int zl, zh; //define the MSB and LSB | ||
Line 174: | Line 178: | ||
int zout = (zl|(zh << 8)); //concatenate the MSB and LSB | int zout = (zl|(zh << 8)); //concatenate the MSB and LSB | ||
return zout; | return zout; | ||
− | } | + | } |
Test Runs: | Test Runs: | ||
Line 190: | Line 194: | ||
[[File:MAGSensor6.png|640px]] | [[File:MAGSensor6.png|640px]] | ||
+ | |||
+ | = Documents = | ||
+ | |||
+ | [https://s3.amazonaws.com/linksprite/MAG3110+Sensor/MAG3110+Datasheet.pdf MAG3110 Datasheet.pdf] | ||
+ | |||
+ | [https://s3.amazonaws.com/linksprite/MAG3110+Sensor/MAG3110+Schematic.pdf MAG3110 Schematic.pdf] | ||
+ | |||
+ | [https://s3.amazonaws.com/linksprite/MAG3110+Sensor/Simplecode.rar Simplecode.rar] |
Latest revision as of 06:31, 8 August 2016
Contents
Introduction
MAG3110 is a small, low -power digital 3D magnetic sensor with wide dynamic range , capable of operating in a PCB with high external magnetic field. The sensor device can be used in combination with the sensor which has triaxial accelerometer to produce accurate way navigation information . It uses a standard IIC output interface and smart embedded features , capable of measuring up to 10 gauss local magnetic field , the output data rates up to 80Hz.
Feature
- Voltage: 3.3-5V
- Output data rates up to 80Hz
- Standard IIC interface , Under fast mode ,rates up to 400Hz
- Low power, single measurement mode
Application Ideas
- Electronic compass
- Location Information Service
Schematic
Interface function
Interface pin description
Usage
Hardware:
1 x Arduino UNO
1 x Linker Base Shield
4 x Dupont line
1 x MAG3110
Wiring Diagram:
Arduino MAG3110
5V --> VCC
GND --> GND
SDA (A4) --> SDA
SCL (A5) --> SCL
Test Code:
#include <Wire.h> #define MAG_ADDR 0x0E //7-bit address for the MAG3110, doesn't change void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial for output config(); // turn the MAG3110 on } void loop() { print_values(); delay(5); } void config(void) { Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E Wire.write(0x11); // cntrl register2 Wire.write(0x80); // send 0x80, enable auto resets Wire.endTransmission(); // stop transmitting delay(15); Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E Wire.write(0x10); // cntrl register1 Wire.write(1); // send 0x01, active mode Wire.endTransmission(); // stop transmitting } void print_values(void) { Serial.print("x="); Serial.print(readx()); Serial.print(","); Serial.print("y="); Serial.print(ready()); Serial.print(","); Serial.print("z="); Serial.println(readz()); } int readx(void) { int xl, xh; //define the MSB and LSB Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E Wire.write(0x01); // x MSB reg Wire.endTransmission(); // stop transmitting delayMicroseconds(2); //needs at least 1.3us free time between start and stop Wire.requestFrom(MAG_ADDR, 1); // request 1 byte while(Wire.available()) // slave may send less than requested { xh = Wire.read(); // receive the byte } delayMicroseconds(2); //needs at least 1.3us free time between start and stop Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E Wire.write(0x02); // x LSB reg Wire.endTransmission(); // stop transmitting delayMicroseconds(2); //needs at least 1.3us free time between start and stop Wire.requestFrom(MAG_ADDR, 1); // request 1 byte while(Wire.available()) // slave may send less than requested { xl = Wire.read(); // receive the byte } int xout = (xl|(xh << 8)); //concatenate the MSB and LSB return xout; } int ready(void) { int yl, yh; //define the MSB and LSB Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E Wire.write(0x03); // y MSB reg Wire.endTransmission(); // stop transmitting delayMicroseconds(2); //needs at least 1.3us free time between start and stop Wire.requestFrom(MAG_ADDR, 1); // request 1 byte while(Wire.available()) // slave may send less than requested { yh = Wire.read(); // receive the byte } delayMicroseconds(2); //needs at least 1.3us free time between start and stop Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E Wire.write(0x04); // y LSB reg Wire.endTransmission(); // stop transmitting delayMicroseconds(2); //needs at least 1.3us free time between start and stop Wire.requestFrom(MAG_ADDR, 1); // request 1 byte while(Wire.available()) // slave may send less than requested { yl = Wire.read(); // receive the byte } int yout = (yl|(yh << 8)); //concatenate the MSB and LSB return yout; }
int readz(void) { int zl, zh; //define the MSB and LSB Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E Wire.write(0x05); // z MSB reg Wire.endTransmission(); // stop transmitting delayMicroseconds(2); //needs at least 1.3us free time between start and stop Wire.requestFrom(MAG_ADDR, 1); // request 1 byte while(Wire.available()) // slave may send less than requested { zh = Wire.read(); // receive the byte } delayMicroseconds(2); //needs at least 1.3us free time between start and stop Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E Wire.write(0x06); // z LSB reg Wire.endTransmission(); // stop transmitting delayMicroseconds(2); //needs at least 1.3us free time between start and stop Wire.requestFrom(MAG_ADDR, 1); // request 1 byte while(Wire.available()) // slave may send less than requested { zl = Wire.read(); // receive the byte } int zout = (zl|(zh << 8)); //concatenate the MSB and LSB return zout; }
Test Runs: (1)Copy the code into the ArduinoIDE, and select the upper left corner of the compile button to compile, as shown below:
(2)Next, click “Tools->Board” to select the model of the development board and pair serial number, we select AVRISP mkll at here, found from the Device Manager for the serial port COM7. As shown below:
(3)After completing the above steps , upload code to the Arduino UNO , when the lower left corner of ArduinoIDE display “Done uploading”, open the serial monitor , set the baud rate ( 9600 ) , you can see the data return from MAG3110: