MPU6050 accelerometer

Hi everyone!
I’m using a Sodaq ExpLoRer to prototype. I need an accelerometer for my project and I use an MPU6050 which is quite popular in the Arduino world. On my Arduino Uno, I use this library: https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050 and it works great. Though when I try to switch from my Uno to the ExpLoRer, I got an error about the I2Cdev library that is required to have the MPU work.
Can you guys help?
Thanks a lot,
Florian

Arduino : 1.6.13 (Mac OS X), Carte : “SODAQ ExpLoRer”

In file included from /Users/Florian/Documents/Arduino/libraries/I2Cdev/I2Cdev.h:80:0,
from /Users/Florian/Documents/Arduino/libraries/I2Cdev/I2Cdev.cpp:46:
/Users/Florian/Documents/Arduino/libraries/I2Cdev/I2Cdev.cpp: In static member function ‘static int8_t I2Cdev::readBytes(uint8_t, uint8_t, uint8_t, uint8_t*, uint16_t)’:
/Users/Florian/Documents/Arduino/libraries/I2Cdev/I2Cdev.cpp:276:62: error: ‘BUFFER_LENGTH’ was not declared in this scope
for (uint8_t k = 0; k < length; k += min(length, BUFFER_LENGTH)) {
^
/Users/Florian/Library/Arduino15/packages/SODAQ/hardware/samd/1.6.14/cores/arduino/Arduino.h:102:24: note: in definition of macro ‘min’
#define min(a,b) ((a)<(b)?(a):(b))
^
/Users/Florian/Documents/Arduino/libraries/I2Cdev/I2Cdev.cpp: In static member function ‘static int8_t I2Cdev::readWords(uint8_t, uint8_t, uint8_t, uint16_t*, uint16_t)’:
/Users/Florian/Documents/Arduino/libraries/I2Cdev/I2Cdev.cpp:414:70: error: ‘BUFFER_LENGTH’ was not declared in this scope
for (uint8_t k = 0; k < length * 2; k += min(length * 2, BUFFER_LENGTH)) {
^
/Users/Florian/Library/Arduino15/packages/SODAQ/hardware/samd/1.6.14/cores/arduino/Arduino.h:102:24: note: in definition of macro ‘min’
#define min(a,b) ((a)<(b)?(a):(b))
^
exit status 1
Erreur de compilation pour la carte SODAQ ExpLoRer

Ce rapport pourrait être plus détaillé avec
l’option “Afficher les résultats détaillés de la compilation”
activée dans Fichier -> Préférences.

The AVR version of wire includes the definition BUFFER_LENGTH as 32.
See: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/libraries/Wire/src/Wire.h

However, the SAMD version does not create that definition as it uses the RingBuffer class: https://github.com/arduino/ArduinoCore-samd/blob/master/libraries/Wire/Wire.h

RingBuffer defines SERIAL_BUFFER_SIZE as 64: https://github.com/arduino/ArduinoCore-samd/blob/master/cores/arduino/RingBuffer.h

I would recommend modifying your library to use your own definition with compiler directives to set the correct value based on what platform you are building for.

1 Like

I should mention that in the Sodaq version of the Arduino SAMD core the RingBuffer size is 129.

It is defined in cores/arduino/RingBuffer.h on line 28:

#define SERIAL_BUFFER_SIZE 129

Add this to your library to fix this issue:

#ifdef ARDUINO_ARCH_SAMD
#define BUFFER_LENGTH SERIAL_BUFFER_SIZE 
#endif
1 Like

Thanks Gabriel! I’m Ok with the accelerometer now. I have another issue, I’ll start a new topic…