PaulStoffregen / NXPMotionSense

NXP Motion Sensors for Teensy and Arduino
69 stars 51 forks source link

ESP32 support issues #8

Open rfestag opened 5 years ago

rfestag commented 5 years ago

Description

This library does not work with ESP32 out of the box. There are two issues:

1) In read_regs, it is assumed that any non-zero return from Wire.endTransmission is an error. In ESP32, this is not the case (it returns 7 to indicate that the previous Wire.endTransmission(false) was buffered) 2) It seems to be written assuming certain Teensy-only files (crc16.h and elapsedMillis.h) are present and can be included.

I have things working on my end now, and would be happy to submit a pull request, but wasn't sure how you wanted to handle the issues on your end. I don't know if other return codes from ESP32 are non-error (I only know 7 and 0 are valid), and wasn't sure if there was a more elegant way to handle non-standard Wire responses that you'd prefer. I also think I can get around the second issue by ensuring those files are in my include path somewhere, but wasn't sure if it made sense to simply add them directly to this library rather than assume they were provided by the board's libraries (which appears to be the case now).

Steps To Reproduce Problem

Simply take any of the example scripts included in this package, compile and run on the latest arduino-esp32 code (https://github.com/espressif/arduino-esp32). Unfortunately, at the time of this submission, you must use the latest from master in git, not from the Board Manager. The latest stable version has bugs in i2c handling, and will not work at all until the patch is released.

In any case, simply compile for ESP32 and issue 2 above will appear. Issue 1 will appear as "config error FXOS8700" continuously being repeated. If you add debugging to the result of Wire.endTransmission(false) in read_regs, you'll see that it returns 7.

Hardware & Software

Board - Adafruit ESP32 Feather Shields / modules used - Teensy prop shield (via Teensy adapter feather wing) Arduino IDE version - 1.8.7 Teensyduino version (if using Teensy) - N/A Version info & package name (from Tools > Boards > Board Manager) -Latest master as described above Operating system & version - Manjaro Any other software or hardware? N/A

Arduino Sketch

#include <Arduino.h>
#include <NXPMotionSense.h>
#include <Wire.h>

NXPMotionSense imu;

void setup() {
  Serial.begin(115200);
  imu.begin();
}

void loop() {
  //Doesn't matter. If you get here, imu.begin() worked
}

Errors or Incorrect Output

ho 0 tail 12 room 4
load:0x40080400,len:6448
entry 0x400806e8
config error FXOS8700
config error FXOS8700
config error FXOS8700
config error FXOS8700
...
ladyada commented 4 years ago

hi @domonoky - if you'd like to use any NXP sensor set with the ESP32, please check out our guide - you can set up any sensors you'd like, save calibrations, and we have quat output for all algorithms - we tested it with an ESP32 feather and it definitely works :) https://learn.adafruit.com/how-to-fuse-motion-sensor-data-into-ahrs-orientation-euler-quaternions

Tanmay-Mathur-Neuro commented 2 years ago

Hi RFEStag, thanks for pointing it out. Did you find any workaround for esp32 to get absolute angle or Quaternions? I am trying to achieve the same with little success. Hi @ladyada First of all thanks for the cool looking dual imu board, I still am not having clarity with how to use Adafruit AHRS library with the FXAS +FXOS board to get the Quat data, any clues would be extremely helpful.

Regards T