Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from 9Volts9er/master
Browse files Browse the repository at this point in the history
Bug fix and example clearification
  • Loading branch information
9Volts9er authored Apr 14, 2021
2 parents ea11b70 + 7de04ee commit 8945ae6
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 11 deletions.
6 changes: 6 additions & 0 deletions examples/Cartesian/Cartesian.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Tlv493d Tlv493dMagnetic3DSensor = Tlv493d();
void setup() {
Serial.begin(9600);
while(!Serial);

//For the Evalkit "TLV493D-A1B6 MS2GO" uncommend following 3 lines:
//pinMode(LED2, OUTPUT); //Sensor-VDD as output
//digitalWrite(LED2, HIGH); //Power on the sensor
//delay(50);

Tlv493dMagnetic3DSensor.begin();
}

Expand Down
6 changes: 6 additions & 0 deletions examples/CartesianFast/CartesianFast.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Tlv493d Tlv493dMagnetic3DSensor = Tlv493d();
void setup() {
Serial.begin(9600);
while(!Serial);

//For the Evalkit "TLV493D-A1B6 MS2GO" uncommend following 3 lines:
//pinMode(LED2, OUTPUT); //Sensor-VDD as output
//digitalWrite(LED2, HIGH); //Power on the sensor
//delay(50);

Tlv493dMagnetic3DSensor.begin();
Tlv493dMagnetic3DSensor.setAccessMode(Tlv493dMagnetic3DSensor.MASTERCONTROLLEDMODE);
Tlv493dMagnetic3DSensor.disableTemp();
Expand Down
63 changes: 63 additions & 0 deletions examples/DualSensor/DualSensor.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <Wire.h>
#include <Tlv493d.h>

#define POWER_PIN1 LED2 //Sensor 1 VDD is connected to POWER_PIN1
#define POWER_PIN2 LED1 //Sensor 2 VDD is connected to POWER_PIN2

// Tlv493d Opject
Tlv493d Tlv493d_Sensor1 = Tlv493d(); //Sensor 1 shall have I²C address 1
Tlv493d Tlv493d_Sensor2 = Tlv493d(); //Sensor 2 shall have I²C address 2

void setup() {
Serial.begin(9600);
while(!Serial);

//Switch off both sensors
pinMode(POWER_PIN1, OUTPUT);
pinMode(POWER_PIN2, OUTPUT);
digitalWrite(POWER_PIN1, LOW);
digitalWrite(POWER_PIN2, LOW);
delay(500);

//Power up and configure sensor 2
digitalWrite(POWER_PIN2, HIGH);
delay(50);
//Configure sensor 2 to address 2 at first, so it will not respond when later address 1 is configured.
Tlv493d_Sensor2.begin(Wire, TLV493D_ADDRESS2, true);

//power up and configure sensor 1
digitalWrite(POWER_PIN1, HIGH);
delay(50);
//Configure sensor 1 to address 1.
//IMPORTANT: Don't perform an I²C sensor reset (last bool argument) as this would also reset sensor 2
// -> Then sensor 2 would again respond to address 1, what we need to avoid.
Tlv493d_Sensor1.begin(Wire, TLV493D_ADDRESS1, false);

}

void loop() {
//Read both sensors
Tlv493d_Sensor1.updateData();
Tlv493d_Sensor2.updateData();

//Output sensor 1 data
Serial.println("Sensor 1:");
Serial.print("X = ");
Serial.print(Tlv493d_Sensor1.getX());
Serial.print(" mT; Y = ");
Serial.print(Tlv493d_Sensor1.getY());
Serial.print(" mT; Z = ");
Serial.print(Tlv493d_Sensor1.getZ());
Serial.println(" mT");
//Output sensor 2 data
Serial.println("Sensor 2:");
Serial.print("X = ");
Serial.print(Tlv493d_Sensor2.getX());
Serial.print(" mT; Y = ");
Serial.print(Tlv493d_Sensor2.getY());
Serial.print(" mT; Z = ");
Serial.print(Tlv493d_Sensor2.getZ());
Serial.println(" mT");
Serial.println();
delay(500);
}
6 changes: 6 additions & 0 deletions examples/SphericalFast/SphericalFast.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Tlv493d Tlv493dMagnetic3DSensor = Tlv493d();
void setup() {
Serial.begin(9600);
while(!Serial);

//For the Evalkit "TLV493D-A1B6 MS2GO" uncommend following 3 lines:
//pinMode(LED2, OUTPUT); //Sensor-VDD as output
//digitalWrite(LED2, HIGH); //Power on the sensor
//delay(50);

Tlv493dMagnetic3DSensor.begin();
Tlv493dMagnetic3DSensor.setAccessMode(Tlv493dMagnetic3DSensor.MASTERCONTROLLEDMODE);
Tlv493dMagnetic3DSensor.disableTemp();
Expand Down
6 changes: 6 additions & 0 deletions examples/spherical/spherical.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Tlv493d Tlv493dMagnetic3DSensor = Tlv493d();
void setup() {
Serial.begin(9600);
while(!Serial);

//For the Evalkit "TLV493D-A1B6 MS2GO" uncommend following 3 lines:
//pinMode(LED2, OUTPUT); //Sensor-VDD as output
//digitalWrite(LED2, HIGH); //Power on the sensor
//delay(50);

Tlv493dMagnetic3DSensor.begin();
}

Expand Down
13 changes: 2 additions & 11 deletions src/Tlv493d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@ void Tlv493d::begin(TwoWire &bus)

void Tlv493d::begin(TwoWire &bus, Tlv493d_Address_t slaveAddress, bool reset)
{
/**
* Workaround for kit2go vdd enable
*/
#ifdef TLV493D_A1B6_KIT2GO
pinMode(LED2, OUTPUT);
digitalWrite(LED2, HIGH);
delay(50);
#endif

initInterface(&mInterface, &bus, slaveAddress);
delay(TLV493D_STARTUPDELAY);

Expand All @@ -87,8 +78,8 @@ void Tlv493d::begin(TwoWire &bus, Tlv493d_Address_t slaveAddress, bool reset)
tlv493d::readOut(&mInterface);
// copy factory settings to write registers
setRegBits(tlv493d::W_RES1, getRegBits(tlv493d::R_RES1));
setRegBits(tlv493d::W_RES1, getRegBits(tlv493d::R_RES1));
setRegBits(tlv493d::W_RES1, getRegBits(tlv493d::R_RES1));
setRegBits(tlv493d::W_RES2, getRegBits(tlv493d::R_RES2));
setRegBits(tlv493d::W_RES3, getRegBits(tlv493d::R_RES3));
// enable parity detection
setRegBits(tlv493d::W_PARITY_EN, 1);
// config sensor to lowpower mode
Expand Down

0 comments on commit 8945ae6

Please sign in to comment.