Infineon Team
Published © MIT

Angle Measurement Kit2Go

Let's have a look at how you could start measuring angles using the TLE5012Kit2Go

BeginnerProtip2 hours621
Angle Measurement Kit2Go

Things used in this project

Hardware components

TLE5012B E1000 MS2GO
Infineon TLE5012B E1000 MS2GO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

TLE5012B MS2Go Fritzing

Fritzing file of TLE5012B MS2Go

TLE5012B MS2Go Breakout Part Fritzing

Sensor breakout part of TLE5012B MS2Go

Code

Direction Detection

C/C++
In this code the microcontroller prints the direction registered by the sensor, when using the joystick attachment accessory
#include <TLE5012-ino.hpp>
Tle5012Ino Tle5012Sensor = Tle5012Ino();
errorTypes checkError = NO_ERROR;
double positionReading = 0.0;
int input=0;
void setup() {
  // put your setup code here, to run once:
  delay(2000);
  Serial.begin(9600);
  while (!Serial) {};
  checkError = Tle5012Sensor.begin();
  Serial.print("checkError: ");
  Serial.println(checkError,HEX);
  delay(1000);
  Serial.println("Init done");
}

void loop() {
  // put your main code here, to run repeatedly:

Tle5012Sensor.getAngleValue(positionReading);

if (positionReading >= -45 && positionReading <= 45) { 
  Serial.println("Up");
   input=1;
}
else if (positionReading < -45 && positionReading >= -120) {
  Serial.println("Right");
  input=2;
}
else if (positionReading < -120 || positionReading > 120) {
  Serial.println("Down");
  input=3;
}
else if (positionReading > 45 && positionReading <= 120) {
  Serial.println("Left");
  input=4;
}
 
  delay(200);
}

Basic application code

C/C++
This code periodically reads out the temperature and angle values
#include <TLE5012-ino.hpp>

Tle5012Ino Tle5012Sensor = Tle5012Ino();
errorTypes checkError = NO_ERROR;

void setup() {
  delay(2000);
  Serial.begin(9600);
  while (!Serial) {};
  checkError = Tle5012Sensor.begin();
  Serial.print("checkError: ");
  Serial.println(checkError,HEX);
  delay(1000);
  Serial.println("Init done");
}
void loop(){

double angleReading = 0.0;  //Variable Creation
Tle5012Sensor.getAngleValue(angleReading); //Calling the method
Serial.print("angle:");  Serial.println(angleReading); //Printing the result

double tempReading =0.0; //Variable Creation
Tle5012Sensor.getTemperature(tempReading); // Calling the method
Serial.print("Temperature:");  Serial.println(tempReading); //Printing the result

}

Sensor Library

Official Library for using the TLE5012 Magnetic Angle Sensor

Credits

Infineon Team
143 projects • 426 followers
Hands-on projects, tutorials, and code for sensors, MCUs, connectivity, security, power, and IoT. Follow for new builds and ideas.

Comments