Things used in this project

Hardware components:
Anduino Arduino Uno
×1
Pmod cmps  73095.1456866167.500.659
Digilent Pmod CMPS
×1
Software apps and online services:
Ide web
Arduino IDE

Schematics

Pmod CMPS and Arduino Uno Fritzing file
Fritzing file displaying the connection of the Pmod CMPS to the Arduino Uno.
pmodcmpsarduinouno_wHM2FduMKC.fzz
Pmod CMPS and Arduino Uno Fritzing Image
Fritzing image displaying the connection between the Pmod CMPS and Arduino Uno.
Pmodcmpsarduinouno bb boyvfvtoa8

Code

Pmod CMPS and Arduino Uno CodeArduino
Using this code will display the 3 components of the magnetic field, its module, and then it angle in the serial monitor.
/************************************************************************
*
* Test of the Pmod
*
*************************************************************************
* Description: Pmod_CMPS
* The three components (X, Y, Z) of the magnetic field and then its module
* and its angle are displayed in the serial monitor
*
* Material
* 1. Arduino Uno
* 2. Pmod CMPS
*
************************************************************************/

#include <Wire.h> // call library
#define HMC5803L_Addresse 0x1E // adresse I2C of the modue

double composante_X;
double composante_Y;
double composante_Z;
double module;
double angle;

void setup()
{
 Serial.begin(9600);
 Wire.begin(); // initialization of I2C bus
 Init_HMC5803L(); // initialization ofthe compass
}

void loop()
{
 Wire.beginTransmission(HMC5803L_Addresse); // Launch of the measure
 Wire.write(0x02);
 Wire.write(0x01);
 Wire.endTransmission();
 delay(10);
 Wire.requestFrom(HMC5803L_Addresse, 6); // Recovery of components
 if(Wire.available() <=6)
 {
  composante_X = Wire.read() << 8 | Wire.read();
  composante_Y = Wire.read() << 8 | Wire.read();
  composante_Z = Wire.read() << 8 | Wire.read();
 }
 Serial.print("X=");
 Serial.print (composante_X);
 Serial.print('\t');
 Serial.print("Y=");
 Serial.print (composante_Y);
 Serial.print('\t');
 Serial.print("Z=");
 Serial.print (composante_Z);
 Serial.print('\t');
 // Calculation of module
 module = sqrt(composante_X * composante_X + composante_Y * composante_Y + composante_Z *
composante_Z);
 Serial.print("M=");
 Serial.print(module);
 Serial.print('\t');
 //Calculation of angle
 angle= atan2(composante_Y,composante_X) * (180 /
3.14159265); // angle en degrés
 if (angle<0) {angle=angle+360;}
 Serial.print("Angle=");
 Serial.println(angle);
 delay(1000);
}
// initialization of HMC5803L
void Init_HMC5803L(void)
{
 Wire.beginTransmission(HMC5803L_Addresse);
 Wire.write(0x00);
 Wire.write(0x70);
 Wire.write(0x01);
 Wire.write(0xA0);
 Wire.endTransmission();
}

Credits

01aa44817a11ceb1a3050ebac4b68bbc
Martha Migliacio
1 project • 0 followers
Contact
Thanks to Lextronics.

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login