KE2059 keyes brick MMA8452Q三轴数字加速度倾角传感器(焊盘孔)

ke2059-6

1.概述

MMA8452Q是一款具有 12位分辨率的智能低功耗、三轴、电容式微机械加速度传感器。这款加速度传感器具有丰富嵌入式功能,带有灵活的用户可编程选项,可以配置多达两个中断引脚。嵌入式中断功能可以节省整体功耗,解除主处理器不断轮询数据的负担。MMA8452Q 具有±2g/±4g/±8g的用户可选量程,可以实时输出高通滤波数据和非滤波数据。该器件可配置嵌入式的功能生成惯性唤醒中断信号,这就使MMA8452Q 在监控事件同时,在静止状态保持低功耗模式。

为了方面接线,我们还配送1根4pin线,线的一端为白色防反插接口(和传感器上防反插白色端子匹配),另一端为4pin杜邦线母头接口。

该传感器兼容各种单片机控制板,如arduino系列单片机。使用时,我们可以在单片机上堆叠一个传感器扩展板。传感器和自带导线连接,然后连接在传感器扩展板上,简单方便。同时,传感器自带2个直径为3mm的定位孔,方便你将传感器固定在其他设备。

2.规格参数

导线长度:200mm

工作电压: DC 3.3-5V

±2g/±4g/±8g 动态量程可选

输出数据速率 (ODR) 范围: 1.56 Hz 至 800 Hz

噪声:99μg/√Hz

12位和 8位数字输出

I2C 数字输出接口(在上拉电阻为4.7 kΩ 时,最高频率可达2.25 MHz)

适用于 6个中断来源的 2个可编程中断引脚

3 个运动检测嵌入式通道: 自由落体检测,  脉冲检测,  晃动检测。

带有设定滞后补偿的方向(横向/纵向)检测

自动唤醒和自动休眠的ODR可自动更改

高通滤波数据可实时输出

功耗: 6 μA – 165 μA

尺寸:131*22*14mm

重量:5.1g

3.连接图

KE2059-3

4.测试代码

特别注意:在烧录程序前,要把Wire和SparkFun_MMA8452Q_Arduino_Library_master文件夹放到 编译器安装目录下的\Arduino\libraries里。不然编译不过。例如我的:C:\Program Files\Arduino\libraries

#include <Wire.h> // Must include Wire library for I2C

#include <SparkFun_MMA8452Q.h> // Includes the SFE_MMA8452Q library

// Begin using the library by creating an instance of the MMA8452Q

// class. We’ll call it “accel”. That’s what we’ll reference from

// here on out.

MMA8452Q accel;

// The setup function simply starts serial and initializes the

// accelerometer.

void setup()

{

Serial.begin(9600);

Serial.println(“MMA8452Q Test Code!”);

// Choose your adventure! There are a few options when it comes

// to initializing the MMA8452Q:

// 1. Default init. This will set the accelerometer up

// with a full-scale range of +/-2g, and an output data rate

// of 800 Hz (fastest).

accel.init();

// 2. Initialize with FULL-SCALE setting. You can set the scale

// using either SCALE_2G, SCALE_4G, or SCALE_8G as the value.

// That’ll set the scale to +/-2g, 4g, or 8g respectively.

//accel.init(SCALE_4G); // Uncomment this out if you’d like

// 3. Initialize with FULL-SCALE and DATA RATE setting. If you

// want control over how fast your accelerometer produces

// data use one of the following options in the second param:

// ODR_800, ODR_400, ODR_200, ODR_100, ODR_50, ODR_12,

// ODR_6, or ODR_1.

// Sets to 800, 400, 200, 100, 50, 12.5, 6.25, or 1.56 Hz.

//accel.init(SCALE_8G, ODR_6);

}

// The loop function will simply check for new data from the

// accelerometer and print it out if it’s available.

void loop()

{

// Use the accel.available() function to wait for new data

// from the accelerometer.

if (accel.available())

{

// First, use accel.read() to read the new variables:

accel.read();

// accel.read() will update two sets of variables.

// * int’s x, y, and z will store the signed 12-bit values

// read out of the accelerometer.

// * floats cx, cy, and cz will store the calculated

// acceleration from those 12-bit values. These variables

// are in units of g’s.

// Check the two function declarations below for an example

// of how to use these variables.

printCalculatedAccels();

//printAccels(); // Uncomment to print digital readings

// The library also supports the portrait/landscape detection

// of the MMA8452Q. Check out this function declaration for

// an example of how to use that.

printOrientation();

Serial.println(); // Print new line every time.

}

}

// The function demonstrates how to use the accel.x, accel.y and

// accel.z variables.

// Before using these variables you must call the accel.read()

// function!

void printAccels()

{

Serial.print(accel.x, 3);

Serial.print(“\t”);

Serial.print(accel.y, 3);

Serial.print(“\t”);

Serial.print(accel.z, 3);

Serial.print(“\t”);

}

// This function demonstrates how to use the accel.cx, accel.cy,

// and accel.cz variables.

// Before using these variables you must call the accel.read()

// function!

void printCalculatedAccels()

{

Serial.print(accel.cx, 3);

Serial.print(“\t”);

Serial.print(accel.cy, 3);

Serial.print(“\t”);

Serial.print(accel.cz, 3);

Serial.print(“\t”);

}

// This function demonstrates how to use the accel.readPL()

// function, which reads the portrait/landscape status of the

// sensor.

void printOrientation()

{

// accel.readPL() will return a byte containing information

// about the orientation of the sensor. It will be either

// PORTRAIT_U, PORTRAIT_D, LANDSCAPE_R, LANDSCAPE_L, or

// LOCKOUT.

byte pl = accel.readPL();

switch (pl)

{

case PORTRAIT_U:

Serial.print(“Portrait Up”);

break;

case PORTRAIT_D:

Serial.print(“Portrait Down”);

break;

case LANDSCAPE_R:

Serial.print(“Landscape Right”);

break;

case LANDSCAPE_L:

Serial.print(“Landscape Left”);

break;

case LOCKOUT:

Serial.print(“Flat”);

break;

}

}

5.测试结果

烧录好测试代码,按照接线图连接好线,利用USB线上电后,打开软件串口监视器,设置波特率为9600。串口监视器显示当传感器三轴加速度以及传感器放置状态,如下图。

6.库文件链接

https://pan.baidu.com/s/1T9OcteO0x1sBxlxTPxffxQ

提取码:b7qk