Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Infineon Team
Published © MIT

Next Generation TLE493D: Your Guide to 3D Magnetic Sensing🧲

Learn how to use Infineon's TLE493D-P3xx-MS2GO to easily measure magnetic field in 3 dimensions, and all that in Arduino!

BeginnerProtip30 minutes207
Next Generation TLE493D: Your Guide to 3D Magnetic Sensing🧲

Things used in this project

Hardware components

TLE493D-P3xx-MS2GO
Infineon TLE493D-P3xx-MS2GO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Read I2C Sensor code example for front side sensor (P3B6)

Arduino
/** Project CPP includes. */
#include "TLx493D_inc.hpp"


using namespace ifx::tlx493d;


/* Definition of the power pin and sensor objects for Kit2Go XMC1100 boards. */
// const uint8_t POWER_PIN = 15; // XMC1100 : LED2

// TLx493D_A1B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);

// TLx493D_A2B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);
// TLx493D_P2B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);
// TLx493D_W2B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);


/** Definition of the power pin and sensor objects for S2Go with XMC4700 Relax Lite board. */
// const uint8_t POWER_PIN = 8; // XMC : P1.10

// TLx493D_A1B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);

// TLx493D_A2BW dut(Wire, TLx493D_IIC_ADDR_A0_e);
// TLx493D_W2B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);
// TLx493D_W2BW dut(Wire, TLx493D_IIC_ADDR_A0_e);


/** P3XX evaluation board */
const uint8_t POWER_PIN = 8;
TLx493D_P3B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);
// TLx493D_P3B6 dut(Wire, TLx493D_IIC_ADDR_A1_e);


/** Definition of the power pin and sensor objects for Arduino Uno boards */
/** Care must be taken to level shift down to 3.3V as the sensor boards expect only 3.3V ! */
/** Therefore disabled here. */
// const uint8_t POWER_PIN = 7;

// TLx493D_W2B6 dut(Wire, TLx493D_IIC_ADDR_A0_e);
// TLx493D_W2BW dut(Wire, TLx493D_IIC_ADDR_A0_e);


/** Definition of a counter variable. */
uint8_t count = 0;


void setup() {
    Serial.begin(115200);
    delay(3000);

    /** Definition of the power pin to power up the sensor. */
    /** Set delay after power-on to 50 for A1B6 Kit2Go sensor. */
    /** All other Kit2Go boards */
    // dut.setPowerPin(POWER_PIN, OUTPUT, INPUT, HIGH, LOW, 0, 250000);

    /** P3XX evaluation board */
    dut.setPowerPin(POWER_PIN, OUTPUT, INPUT, LOW, HIGH, 1000, 250000);

    dut.begin();

    Serial.print("setup done.\n");
}


/** In the loop we continuously reading the temperature value as well as the
 *  magnetic values in X, Y, Z-direction of the sensor and printing them to
 *  the serial monitor
 */
void loop() {
    double t, x, y, z;

    dut.setSensitivity(TLx493D_FULL_RANGE_e);
    Serial.print(true == dut.getMagneticFieldAndTemperature(&x, &y, &z, &t) ? "getMagneticFieldAndTemperature ok\n" : "getMagneticFieldAndTemperature error\n");

    dut.printRegisters();

    Serial.print("\nTemperature is: ");
    Serial.print(t);
    Serial.println("°C");

    Serial.print("Value X is: ");
    Serial.print(x);
    Serial.println(" mT");
    Serial.print("Value Y is: ");
    Serial.print(y);
    Serial.println(" mT");
    Serial.print("Value Z is: ");
    Serial.print(z);
    Serial.println(" mT");

    dut.setSensitivity(TLx493D_SHORT_RANGE_e);
    Serial.print(true == dut.getMagneticFieldAndTemperature(&x, &y, &z, &t) ? "getMagneticFieldAndTemperature ok\n" : "getMagneticFieldAndTemperature error\n");

    dut.printRegisters();

    Serial.print("\nTemperature is: ");
    Serial.print(t);
    Serial.println("°C");

    Serial.print("Value X is: ");
    Serial.print(x);
    Serial.println(" mT");
    Serial.print("Value Y is: ");
    Serial.print(y);
    Serial.println(" mT");
    Serial.print("Value Z is: ");
    Serial.print(z);
    Serial.println(" mT");
    Serial.print("\n\n\n\n");

    delay(1000);

    Serial.print("count : ");
    Serial.println(count);

    if( ++count == 4 ) {
        Serial.println("\nBefore reset -------------------------------------------------------------------------------------------------------");

        /** Reset does not work for W2BW : either drive strength too low or delay to stabilize critical. */
        dut.reset(true, dut.getSensorType() != TLx493D_A1B6_e);

        Serial.println("\nAfter reset -------------------------------------------------------------------------------------------------------");
        count = 0;
    }
}

Read SPI Sensor example for back side sensor (P3I8)

Arduino
/** Project CPP includes. */
#include "TLx493D_inc.hpp"


using namespace ifx::tlx493d;


/** Definition of the power and chip select pin. */
/** P3XX evaluation board */
const uint8_t POWER_PIN       = 4; // XMC1100_XMC2GO
const uint8_t CHIP_SELECT_PIN = 3;

/** Declaration of the sensor object. */
TLx493D_P3I8 dut(SPI);

/** Definition of a counter. */
uint8_t count = 0;


void setup() {
    Serial.begin(115200);
    delay(3000);

    /** Setting the chip select pin for the SPI board using the functions of the Board Support Class.
     * Power supply has to be switched on through transistor, therefore inverse logic.
     */
    dut.setPowerPin(POWER_PIN, OUTPUT, INPUT, LOW, HIGH, 1000, 250000);
    dut.setSelectPin(CHIP_SELECT_PIN, OUTPUT, INPUT, LOW, HIGH, 0, 0);
    dut.begin(true, true);

    Serial.print("setup done.\n");
}

/** In the loop we're reading out the temperature value (in °C) as well as the magnetic fields values in X, Y, Z-direction (in mT).
 *  We're also reading out the raw temperature value (in LSB).
 */
void loop() {
    double temp = 0.0;
    double valX = 0, valY = 0, valZ = 0;
    int16_t tempRaw = 0;

    dut.printRegisters();
    Serial.print("\n");

    /** Note that you don't have to toggle any chip select signal, this is done in the background within the transfer function. */
    Serial.print(true == dut.getTemperature(&temp) ? "getTemperature ok\n" : "getTemperature error\n");

    Serial.print("Temperature is: ");
    Serial.print(temp);
    Serial.println(" °C");

    dut.getRawTemperature(&tempRaw);

    Serial.print("Raw temperature is: ");
    Serial.print(tempRaw);
    Serial.println(" LSB");

    Serial.print(true == dut.getMagneticFieldAndTemperature(&valX, &valY, &valZ, &temp) ? "getMagneticFieldAndTemperature ok\n" : "getMagneticFieldAndTemperature error\n");

    Serial.print("Value X is: ");
    Serial.print(valX);
    Serial.println(" mT");
    Serial.print("Value Y is: ");
    Serial.print(valY);
    Serial.println(" mT");
    Serial.print("Value Z is: ");
    Serial.print(valZ);
    Serial.println(" mT");

    dut.printRegisters();
    Serial.print("\n");

    delay(1000);

    Serial.print("count : ");
    Serial.println(count);

    if( ++count == 10 ) {
        Serial.println("Before reset -------------------------------------------------------------------------------------------------------");

        /* Use reset to do a full power down reset or softwareReset to reset using register settings. **/
        dut.reset();
        // dut.softwareReset();

        Serial.println("After reset -------------------------------------------------------------------------------------------------------");
        count = 0;
    }
}

arduino-xensiv-3d-magnetic-sensor-tlx493d

Arduino Library for Infineon's 3D Magnetic Sensors.

Credits

Infineon Team
100 projects • 157 followers
Contact

Comments

Please log in or sign up to comment.