Page 1 of 1

Communication I2C MMA8452 accelerometer

Posted: Mon Apr 16, 2018 1:00 pm
by fizzytaken
Hi,
I would like to use the MMA8452 I2C accelerometer with the pins 30 31 of the ESP32.
I found a library for arduino (https://github.com/sparkfun/MMA8452_Acc ... es/Arduino), but i would like to use this library but it would be necessary to change the SDA SCL pins defined for the arduino.

How can i do ?


Regards

Re: Communication I2C MMA8452 accelerometer

Posted: Sat Apr 21, 2018 11:13 am
by migbur
Hi
This arduino lib are made for arduino HW that has by default A4,A5 ping.
You may to change the .cpp lib

add the esp32 ping like : Wire.begin(21,22); // Initialize I2C

the pings to add, is located here
// INITIALIZATION
// This function initializes the MMA8452Q. It sets up the scale (either 2, 4,
// or 8g), output data rate, portrait/landscape detection and tap detection.
// It also checks the WHO_AM_I register to make sure we can communicate with
// the sensor. Returns a 0 if communication failed, 1 if successful.
byte MMA8452Q::init(MMA8452Q_Scale fsr, MMA8452Q_ODR odr)
{
scale = fsr; // Haul fsr into our class variable, scale

Wire.begin(); // Initialize I2C

byte c = readRegister(WHO_AM_I); // Read WHO_AM_I register

if (c != 0x2A) // WHO_AM_I should always be 0x2A
{
return 0;
}

You can run I2C scan script first to be sure that you ESP32 recognize the acellerometer.