Code Monkey home page Code Monkey logo

adafruit_mma8451_library's Introduction

#Adafruit MMA8451 Accelerometer Driver Build StatusDocumentation

This driver is for the Adafruit MMA8451 Accelerometer Breakout (http://www.adafruit.com/products/2019), and is based on Adafruit's Unified Sensor Library (Adafruit_Sensor).

About the MMA8451

The MMA8451 is a low-cost but high-precision digital accelerometer that uses repeated-start I2C mode, with adjustable data rata and 'range' (+/-2/4/8).

More information on the MMA8451 can be found in the datasheet: http://www.adafruit.com/datasheets/MMA8451Q-1.pdf

What is the Adafruit Unified Sensor Library?

The Adafruit Unified Sensor Library (https://github.com/adafruit/Adafruit_Sensor) provides a common interface and data type for any supported sensor. It defines some basic information about the sensor (sensor limits, etc.), and returns standard SI units of a specific type and scale for each supported sensor type.

It provides a simple abstraction layer between your application and the actual sensor HW, allowing you to drop in any comparable sensor with only one or two lines of code to change in your project (essentially the constructor since the functions to read sensor data and get information about the sensor are defined in the base Adafruit_Sensor class).

This is imporant useful for two reasons:

1.) You can use the data right away because it's already converted to SI units that you understand and can compare, rather than meaningless values like 0..1023.

2.) Because SI units are standardised in the sensor library, you can also do quick sanity checks working with new sensors, or drop in any comparable sensor if you need better sensitivity or if a lower cost unit becomes available, etc.

Light sensors will always report units in lux, gyroscopes will always report units in rad/s, etc. ... freeing you up to focus on the data, rather than digging through the datasheet to understand what the sensor's raw numbers really mean.

About this Driver

Adafruit invests time and resources providing this open source code. Please support Adafruit and open-source hardware by purchasing products from Adafruit!

Written by Kevin (KTOWN) Townsend & Limor (LADYADA) Fried for Adafruit Industries.

adafruit_mma8451_library's People

Contributors

caternuson avatar driverblock avatar evaherrada avatar facchinm avatar hamaluik avatar jsissom avatar kevmeyer avatar ladyada avatar leethomason avatar microbuilder avatar tdicola avatar tyeth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_mma8451_library's Issues

I2C Pin Selection

The lib does not provide a possibility to select non default I2C pins.
It would be very helpful when an additional begin method provides additional parameters:
mma.begin(SDA_Pin, SCL_Pin, I2CAddr);

Regards
Rainer

Detect changes in yaw?

I've figured out I can check mma.x and mma.y quite easily to see what's up with the roll and pitch of the MMA8451, but how can I find out changes in yaw?

Guru Meditation Error: Core 1 panic'ed (IntegerDivideByZero). Exception was unhandled.

Thank you for opening an issue on an Adafruit Arduino library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:

  • Do not use GitHub issues for troubleshooting projects and issues. Instead use
    the forums at http://forums.adafruit.com to ask questions and troubleshoot why
    something isn't working as expected. In many cases the problem is a common issue
    that you will more quickly receive help from the forum community. GitHub issues
    are meant for known defects in the code. If you don't know if there is a defect
    in the code then start with troubleshooting on the forum first.

  • If following a tutorial or guide be sure you didn't miss a step. Carefully
    check all of the steps and commands to run have been followed. Consult the
    forum if you're unsure or have questions about steps in a guide/tutorial.

  • For Arduino projects check these very common issues to ensure they don't apply:

    • For uploading sketches or communicating with the board make sure you're using
      a USB data cable and not a USB charge-only cable. It is sometimes
      very hard to tell the difference between a data and charge cable! Try using the
      cable with other devices or swapping to another cable to confirm it is not
      the problem.

    • Be sure you are supplying adequate power to the board. Check the specs of
      your board and plug in an external power supply. In many cases just
      plugging a board into your computer is not enough to power it and other
      peripherals.

    • Double check all soldering joints and connections. Flakey connections
      cause many mysterious problems. See the guide to excellent soldering for examples of good solder joints.

    • Ensure you are using an official Arduino or Adafruit board. We can't
      guarantee a clone board will have the same functionality and work as expected
      with this code and don't support them.

If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:

  • Arduino board: ESP32

  • Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.10

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too): I'm getting a "Guru Meditation Error: Core 1 panic'ed (IntegerDivideByZero). Exception was unhandled." error when using this library for a mma8451 with two sen0366 distance sensors. I get this in the serial monitor when the esp32 resets:

Guru Meditation Error: Core 1 panic'ed (IntegerDivideByZero). Exception was unhandled.

Core 1 register dump:
PC : 0x400d1a1c PS : 0x00060f30 A0 : 0x800d1c27 A1 : 0x3ffb27b0
A2 : 0x461c4000 A3 : 0x400fced9 A4 : 0x6872b010 A5 : 0x407e76c8
A6 : 0x00000000 A7 : 0x00000400 A8 : 0x00000000 A9 : 0x00000088
A10 : 0x3ffc11a8 A11 : 0x3ffc11a4 A12 : 0x00000000 A13 : 0x00000000
A14 : 0x3ffb9108 A15 : 0x00000000 SAR : 0x0000001d EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x400d1b3c LEND : 0x400d1b48 LCOUNT : 0x00000000

Backtrace:0x400d1a19:0x3ffb27b00x400d1c24:0x3ffb27d0 0x400d1d5f:0x3ffb27f0 0x400d3359:0x3ffb2820

ELF file SHA256: 0000000000000000

Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:12804
ho 0 tail 12 room 4
load:0x40080400,len:3032
entry 0x400805e4
MMA8451 found!
Range = 2G

Bit shift operation losing sign value

  • Arduino board: HUZZAH32

  • Arduino IDE version (found in Arduino -> About Arduino menu): Using ESPHome

board: featheresp32; framework: arduino; platform: platformio/[email protected]
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif32 3.10006.210326 (1.0.6) 
 - tool-esptoolpy 1.30000.201119 (3.0.0) 
 - toolchain-xtensa32 2.50200.97 (5.2.0)
Library Manager: Installing Hash
Library Manager: Already installed, built-in library
Dependency Graph
|-- <AsyncTCP-esphome> 1.2.2
|-- <Adafruit MMA8451 Library> 1.2.0
|   |-- <Adafruit BusIO> 1.9.3
|   |   |-- <Wire> 1.0.1
|   |   |-- <SPI> 1.0
|   |-- <Wire> 1.0.1
|   |-- <Adafruit Unified Sensor> 1.1.4
|-- <FS> 1.0
|-- <ESPAsyncWebServer-esphome> 1.3.0
|   |-- <AsyncTCP-esphome> 1.2.2
|   |-- <Crypto> 0.2.0
|   |-- <FS> 1.0
|   |-- <WiFi> 1.0
|-- <ESPmDNS> 1.0
|   |-- <WiFi> 1.0
|-- <noise-c> 0.1.3
|   |-- <libsodium> 1.10018.1
|-- <DNSServer> 1.1.0
|   |-- <WiFi> 1.0
|-- <Update> 1.0
|-- <WiFi> 1.0
|-- <SPI> 1.0
  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too):

Bit shift operation in Adafruit_MMA8451.cpp appears to be losing sign during right shift:

  x = ((int16_t(buffer[0]) << 8) | int16_t(buffer[1])) >> 2;
  y = ((int16_t(buffer[2]) << 8) | int16_t(buffer[3])) >> 2;
  z = ((int16_t(buffer[4]) << 8) | int16_t(buffer[5])) >> 2;

I did not have this issue when using Adafruit_MMA8451_Library 1.1.0. The sign bit was preserved.

For my code:

Adafruit_MMA8451 mma = Adafruit_MMA8451();
mma.read();

When reading back mma.x, mma.y, mma.z they are always positive integers.
I repaired it in my code by doing the following:

  mma.x <<= 2;
  mma.x >>= 2;
  mma.y <<= 2;
  mma.y >>= 2;
  mma.z <<= 2;
  mma.z >>= 2;

Invalid bit mask for data rate?

void Adafruit_MMA8451::setDataRate(mma8451_dataRate_t dataRate)
{
uint8_t ctl1 = readRegister8(MMA8451_REG_CTRL_REG1);
ctl1 &= ~(0x28); // mask off bits
ctl1 |= (dataRate << 3);
writeRegister8(MMA8451_REG_CTRL_REG1, ctl1);
}

I think it should be:
ctl1 &= ~(0x38); // mask off bits
otherwise bit 4 is not masked (data rate is in bits 3,4 and 5)

Recent return code change seems to have broken MMA8451 library.

Error message...

In file included from MMA8451demo.cpp:21:0:
/home/pi/sketchbook/libraries/Adafruit_MMA8451_Library_master/Adafruit_MMA8451.h:93:8: error: conflicting return type specified for ‘virtual bool Adafruit_MMA8451::getEvent(sensors_event_t_)’
In file included from /home/pi/sketchbook/libraries/Adafruit_MMA8451_Library_master/Adafruit_MMA8451.h:27:0,
from MMA8451demo.cpp:21:
/home/pi/sketchbook/libraries/Adafruit_Sensor_master/Adafruit_Sensor.h:146:16: error: overriding ‘virtual void Adafruit_Sensor::getEvent(sensors_event_t_)’

Won´t initialize in Arduino DUE

The library does not work with Arduino DUE: The program uploads, send no problems or warnings. But frezee the whole program. Even a single serial message wont run.

I tryied with the same wiring on Arduino MEGA and on MEGA work good.

Consider removing Serial.print

  • Arduino board: all
  • Arduino IDE version (found in Arduino -> About Arduino menu): all
  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too): source code

The library has internal Serial.x statements. e.g. in begin()

Serial.print("$");

I'd suggest that libraries not use Serial to log messages, as the library may not be the only thing trying to use Serial. I believe there are also issues if Serial is used and it hasn't been initialized.

Error in code?

That section of Adafruit_MMA8451.cpp doesn't look right:

 // Low noise!
writeRegister8(MMA8451_REG_CTRL_REG4, 0x01);
// DRDY on INT1
writeRegister8(MMA8451_REG_CTRL_REG4, 0x01);
writeRegister8(MMA8451_REG_CTRL_REG5, 0x01);

LNOISE is on REG1, bit 2
REG4, bit 0 is "Auto-SLEEP/WAKE interrupt enabled"
so I think it should be:

 // Low noise!
writeRegister8(MMA8451_REG_CTRL_REG1, 0x04);
// Enable Auto-SLEEP/WAKE interrupt
writeRegister8(MMA8451_REG_CTRL_REG4, 0x01);
// DRDY on INT1
writeRegister8(MMA8451_REG_CTRL_REG5, 0x01);

I didn't test the code

Error Compiling demo

Hello, I'm trying to compile the demo and throws this error:

In file included from MMA8451demo.ino:21:0:
C:\Users\Guillermo\Documents\Arduino\libraries\Adafruit_MMA8451/Adafruit_MMA8451.h:93:8: error: conflicting return type specified for 'virtual bool Adafruit_MMA8451::getEvent(sensors_event_t_)'
bool getEvent(sensors_event_t event);
^
In file included from C:\Users\Guillermo\Documents\Arduino\libraries\Adafruit_MMA8451/Adafruit_MMA8451.h:27:0,
from MMA8451demo.ino:21:
C:\Users\Guillermo\Documents\Arduino\libraries\Adafruit_Sensor/Adafruit_Sensor.h:146:16: error: overriding 'virtual void Adafruit_Sensor::getEvent(sensors_event_t_)'
virtual void getEvent(sensors_event_t
);
^

Please Help!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.