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 #1 from 9Volts9er/multipleSensor
Browse files Browse the repository at this point in the history
Multiple sensor
  • Loading branch information
9Volts9er authored Apr 13, 2021
2 parents bba2b3d + 470c5b9 commit 7de04ee
Showing 1 changed file with 63 additions and 0 deletions.
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);
}

0 comments on commit 7de04ee

Please sign in to comment.