@@ -9,110 +9,76 @@ void setup()
99 // Start serial communication at 115200 baud
1010 Serial.begin (115200 );
1111 // Set clock speed to be the fastest for better communication
12- Wire.setClock (400000 );
12+ Wire.setClock (1000000 );
13+
1314
1415 // Begin example of the magnetic sensor code (and add whitespace for easy reading)
1516 Serial.println (" TMAG5273 Example 1: Basic Readings" );
1617 Serial.println (" " );
1718 // If begin is successful (0), then start example
18- if (sensor.begin (0X0D , Wire) == false )
19+ if (sensor.begin (0X22 , Wire) == false )
1920 {
2021 Serial.println (" Begin" );
2122 }
2223 else // Otherwise, infinite loop
2324 {
2425 Serial.println (" Device failed to setup - Freezing code." );
25- // while(1); // Runs forever
26+ while (1 ); // Runs forever
2627 }
2728
28- // Reset oscillator error flag
29- sensor.setOscillatorError (1 );
29+ // TESTING CODE:
30+ // Print out the I2C address
31+ uint16_t address = sensor.getI2CAddress ();
32+ Serial.print (" I2C Address: " );
33+ Serial.println (address, HEX);
3034
31- // Check device status register to make sure no errors are present
32- if (sensor.getDeviceStatus () == 1 )
33- {
34- Serial.println (" Oscillator Error" );
35- }
36- else if (sensor.getDeviceStatus () == 2 )
37- {
38- Serial.println (" Interrupt Pin Error" );
39- }
40- else if (sensor.getDeviceStatus () == 3 )
41- {
42- Serial.println (" OTP CRC Error" );
43- }
44- else if (sensor.getDeviceStatus () == 4 )
45- {
46- Serial.println (" Undervoltage Error" );
47- }
48-
49- // Define I2C Read mode
50- sensor.setReadMode (0 );
51- if (sensor.setReadMode (0 ) == 0 )
52- {
53- Serial.println (" Read Mode Set Successfully!" );
54- delay (100 );
55- }
56-
57- // Set low active current mode
58- sensor.setLowPower (0 );
59- if (sensor.setLowPower (0 ) == 0 )
60- {
61- Serial.println (" Low Active Current Set Successfully!" );
62- delay (100 );
63- }
64-
65- // Set operating mode to continuous measure
66- sensor.setOperatingMode (2 );
67- if (sensor.setOperatingMode (2 ) == 0 )
68- {
69- Serial.println (" Operating Mode Set Successfully!" );
70- delay (100 );
71- }
72-
73- // Enable all magnetic channels (X, Y, Z)
74- int magCheck = 0 ;
75- magCheck = sensor.setMagChannel (7 );
76- Serial.print (" Mag Check: " );
77- Serial.println (magCheck);
35+ sensor.setMagChannel (7 );
7836 int magChannel = sensor.getMagChannel ();
37+ Serial.print (" Magnetic Channel set: " );
7938 Serial.println (magChannel);
8039
81- // Set the I2C Read Mode to be standard 3-byte command
82- sensor.setReadMode (0 );
83-
40+ sensor.setXYAxisRange (1 );
8441
8542}
8643
8744
8845
8946void loop ()
9047{
91- // Do we need dataReady? Do we have that option? --> Look into more
92-
9348
94- if (( sensor.getMagChannel () != 0 ) || (sensor. getMagChannel () == - 1 ) ) // Checks if mag channels are on - turns on in setup
49+ if (sensor.getMagChannel () != 0 ) // Checks if mag channels are on - turns on in setup
9550 {
9651 float magX = sensor.getXData ();
9752 float magY = sensor.getYData ();
9853 float magZ = sensor.getZData ();
9954 float temp = sensor.getTemp ();
100-
55+
56+ int xyField = sensor.getXYAxisRange ();
57+ int xLSB = sensor.getXLSB ();
58+ int xMSB = sensor.getXMSB ();
10159 Serial.println (); // Create a whitespace for easy viewing
102- Serial.print (" Magnetic Field, X in mT: " );
103- Serial.println (magX);
60+ Serial.print (" Magnetic Field, X : " );
61+ Serial.print (magX);
62+ Serial.println (" mT" );
63+ Serial.print (" XY Axis Range: " );
64+ Serial.println (xyField);
65+ Serial.print (" XLSB: " );
66+ Serial.println (xLSB, BIN);
67+ Serial.print (" XMSB: " );
68+ Serial.println (xMSB, BIN);
10469 // Serial.print("Magnetic Field, Y in mT: ");
10570 // Serial.println(magY);
10671 // Serial.print("Magnetic Field, Z in mT: ");
10772 // Serial.println(magZ);
10873 // Serial.print("Temperature in Celsius: ");
10974 // Serial.println(temp);
11075 delay (500 ); // Delay added for easier readings
111-
11276 }
11377 else
11478 {
11579 Serial.println (" Mag Channels disabled, stopping.." );
11680 while (1 );
11781 }
82+
83+ delay (1000 );
11884}
0 commit comments