H3LIS331DL and ESP32 library?

I want to use the esp32 to do live streaming of the accelerometer data, but the i am getting errors when compiling the example code for the esp32.

the code compiles fine for an arduino nano, but the 5v incompatibility makes it unusable for my devices.

using the provided i2c example for the H3LIS331 on an esp32 produces the errors:


> In file included from /home/jj/.arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/esp32-hal.h:53:0,
>
> from /home/jj/.arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/Arduino.h:35,
>
> from sketch/esp32_h3lis331_i2c_try1.ino.cpp:1:
>
> /home/jj/.arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/esp32-hal-gpio.h:39:27: error: expected identifier before numeric constant
>
> #define OPEN_DRAIN 0x10
>
> ^
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:38:28: note: in expansion of macro ‘OPEN_DRAIN’
>
> typedef enum {PUSH_PULL, OPEN_DRAIN} pp_od;
>
> ^
>
> /home/jj/.arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/esp32-hal-gpio.h:39:27: error: expected ‘}’ before numeric constant
>
> #define OPEN_DRAIN 0x10
>
> ^
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:38:28: note: in expansion of macro ‘OPEN_DRAIN’
>
> typedef enum {PUSH_PULL, OPEN_DRAIN} pp_od;
>
> ^
>
> /home/jj/.arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/esp32-hal-gpio.h:39:27: error: expected unqualified-id before numeric constant
>
> #define OPEN_DRAIN 0x10
>
> ^
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:38:28: note: in expansion of macro ‘OPEN_DRAIN’
>
> typedef enum {PUSH_PULL, OPEN_DRAIN} pp_od;
>
> ^
>
> In file included from /home/jj/Arduino/esp32_h3lis331_i2c_try1/esp32_h3lis331_i2c_try1.ino:1:0:
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:45:10: error: expected unqualified-id before ‘)’ token
>
> LIS331(); // Constructor. Defers all functionality to .begin()
>
> ^
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:46:14: error: variable or field ‘begin’ declared void
>
> void begin(comm_mode mode);
>
> ^
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:46:14: error: ‘comm_mode’ was not declared in this scope
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:50:21: error: variable or field ‘setPowerMode’ declared void
>
> void setPowerMode(power_mode pmode);
>
> ^
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:50:21: error: ‘power_mode’ was not declared in this scope
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:51:15: error: variable or field ‘setODR’ declared void
>
> void setODR(data_rate drate);
>
> ^
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:51:15: error: ‘data_rate’ was not declared in this scope
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:55:25: error: variable or field ‘setHighPassCoeff’ declared void
>
> void setHighPassCoeff(high_pass_cutoff_freq_cfg hpcoeff);
>
> ^
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:55:25: error: ‘high_pass_cutoff_freq_cfg’ was not declared in this scope
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:59:19: error: variable or field ‘intPinMode’ declared void
>
> void intPinMode(pp_od _pinMode);
>
> ^
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:59:25: error: expected ‘)’ before ‘_pinMode’
>
> void intPinMode(pp_od _pinMode);
>
> ^
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:71:3: error: expected unqualified-id before ‘private’
>
> private:
>
> ^
>
> /home/jj/Arduino/libraries/SparkFun_LIS331_Arduino_Library-master/src/SparkFun_LIS331.h:78:1: error: expected declaration before ‘}’ token
>
> };
>
> ^
>
> exit status 1
>
> Error compiling for board ESP32 Dev Module.

Any help with the compiling would be appreciated. As a sanity check, the esp32 was able to compile and blink the led afterwards, so the standard esp32 libraries seem unaffected?

thanks

Just a heads-up you can always step down the voltage from 5v to 3.3v using one of these

https://www.sparkfun.com/products/14765

https://www.sparkfun.com/products/12009

That being said, perhaps try and reinstall your IDE/packages/libraries, and perhaps see if it is able to compile after?