0

I'm making a program where a buzzer activates if the accelerometer is tilted a certain number of degrees. I'm getting an error that says "'I2C_MODE' was not declared in this scope." I'm using a Grove Beginner Kit, so all of the parts are automatically connected to each other. I downloaded Seeed_Arduino_LIS3DHTR library from the following link: https://github.com/Seeed-Studio/Seeed_Arduino_LIS3DHTR and used sample code from the Grove Beginner Kit for Arduino Guide that came with the board, so everything should work properly. I'm getting this error and don't want to move further with the project until I figure out what's causing this error.

#include <LIS3DHTR.h>

//Gravity Acceleration
#include "LIS3DHTR.h"
#ifdef SOFTWAREWIRE
#include <SoftwareWire.h>
SoftwareWire myWire(3, 2);
LIS3DHTR<SoftwareWire> LIS(I2C_MODE); //IIC    This is what the error 
#define WIRE myWire
#else
#include <Wire.h>
LIS3DHTR<TwoWire> LIS(I2C_MODE);//IIC          THIS IS WHERE THE ERROR OCCURS
#define WIRE Wire
#endif
void setup() {
Serial.begin(9600);
while (!Serial) {};
LIS.begin(WIRE); //IIC init
delay(100);
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
}
void loop() {
if (!LIS) {
Serial.println("LIS3DHTR didn't connect.");
while (1);
return;
}
//3 axis
Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.prin
t(" ");
Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.prin
t(" ");
Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
delay(500);
}
TJ Webster
  • 15
  • 5

1 Answers1

0

The docs you linked have a different instantiation than what you have!

Try passing Wire to the .begin method rather than to LIS (which presumably does exist in Wire.h and likely also exists in SoftwareWire.h)

Plausibly putting LIS.begin() in setup() is needed, though it doesn't seem to matter from their examples

LIS3DHTR<TwoWire> LIS; //IIC
LIS.begin(Wire, 0x19)
ti7
  • 16,375
  • 6
  • 40
  • 68