I2C、Arduino、ADXL345、

有用的链接

  1. Arduino Wire参考:https://www.arduino.cc/en/Reference/Wire

  2. 我翻译的Wire库的应用说明:https://blog.csdn.net/acktomas/article/details/88069640

  3. I2C双向电平转换器(https://playground.arduino.cc/Main/I2CBi-directionalLevelShifter/),用于电平转换、上拉电阻和连接3.3V器件。

  4. Nick Gammon的有关I2C的页面(关于I2C的原理介绍很详细:http://gammon.com.au/i2c(该页面上还有一个“ I2C扫描程序”)。
    我将内容翻译:I2C-两线外设接口-用于Arduino:https://download.csdn.net/download/acktomas/11824487

  5. robtillaart制作了“ Multispeed I2C Scanner(https://forum.arduino.cc/index.php?topic=197360)” ,可以用不同的I2C速度进行扫描。如果您使用更长的导线或使用更高I2C速度的库,则Multispeed I2C扫描仪将非常有用。(与UNO一起验证,2009年,MEGA)
    赛斯维传感器网http://www.sensorway.cn/knowledge/

加速度传感器灵敏度表示的几种方式LSB/g,count/g,V/g,V/°

给出几种方式之间的说明及转换公式:
1)、LSB的意思是最小有效位,为数字输出方式,一般我们可以用mg/LSB来表示灵敏度,举个例子来说,ADI的加速度传感器ADXL345量程为+/2g,输出的位数为10位(2的10次方共1024个LSB)对应满量程,那么灵敏度就为4g/1024LSB=3.9mv/g,取倒数为256LSB/g。
2)、count为计数单位,为数字输出方式,比如说我们的SCA820-D04,量程为+/-2g,灵敏度为900count/g,速度为0g是输出为0count,也就是说1g的时候对应输出应该为900count,-1g的时候输出为-900count。
3)、V/g为模拟电压输出的灵敏度表示方式。
4)、简单的介绍下V/g和V/°的换算公式,以SCA100T-D01为例,其灵敏度为4V/g换算成mV/°等于4sin1°=69.8mV/°,规格书上写的是70mV/°。此外SCA100T-D01传感器从零点转动15度,电压的变化=4sin15°=1.035V,对应15度输出电压=2.5+1.035=3.503V,对应-15度输出电压=2.5-1.035=1.465V。注意,转动15度的电压变化不能算成70mV/°*15,这样计算式错误的

Table 1.Configuring the g-Select for 8-bit output using Register $16 with GLVL[1:0] bits

GLVL[1:0]g-RangeSensitivity
008g16LSB/g
012g64LSB/g
104g32LSB/g

比如上表为MMA7455L 加速度传感器

量程为4g 输出位数为8位,2的8次方为256,那么灵敏度就为4g/256LSB,取倒数则为256LSB/4g=32LSB/g

I2C通信之Arduino与加速度传感器ADXL345

转载:https://www.geek-workshop.com/thread-8539-1-1.html
//We connect CS to 3.3V to tell the sensor we will be using it as an I2C device, and not an SPI device.
IDE环境:Arduino1.0.5


#include <Wire.h>
#define ADXLAddress (0x53)     //ADXL345的I2C地址(ADDR接地)
int xAcc,   yAcc,   zAcc;        // 存放加速度值
int buff[6];                    //存放寄存器高低位值,X、Y、Z轴共6个

// 加速度传感器误差修正的偏移量
int a_offx = 0;
int a_offy = 0;
int a_offz = 0;

void writeRegister(int deviceAddress, byte address, byte val)
{
    Wire.beginTransmission(deviceAddress);
    Wire.write(address);       
    Wire.write(val);         
    Wire.endTransmission();
}

void readRegister(int deviceAddress, byte address)
{
    Wire.beginTransmission(deviceAddress);   
    Wire.write(address);         
    Wire.endTransmission();
    Wire.beginTransmission(deviceAddress);
    Wire.requestFrom(deviceAddress, 6);    

    int i = 0;
    while (Wire.available())   
       {  buff[i++] = Wire.read();   }
      Wire.endTransmission();
}

void initAcc()
{
    //配置ADXL345,ADXL345采用默认的+-2g量程,10位分辨率
  writeRegister (ADXLAddress, 0x2C, 0x09);//设置输出数据速率50Hz,带宽25Hz。
  //默认值为0x0A,对应输出数据速率100Hz,带宽50Hz
  writeRegister (ADXLAddress, 0x2D, 0x08);    //设置ADXL345为测量模式。
    
}

void getAccData()
{
  readRegister(ADXLAddress, 0x32);   
  xAcc = ((buff[1] << 8) | buff[0] ) + a_offx;    
  yAcc = ((buff[3] << 8) | buff[2] ) + a_offy;
  zAcc = ((buff[5] << 8) | buff[4]) + a_offz;
}

void setup()
{
    Serial.begin(9600);
    Wire.begin();
    initAcc();
    delay(50);
}
  
void loop()
{
  getAccData();
  Serial.print("xAcc=");
  Serial.print(xAcc);
  Serial.print("  yAcc=");
  Serial.print(yAcc);
  Serial.print("  zAcc=");
  Serial.println(zAcc);
  delay(200);
}


---------------------
作者:acktomas
来源:CSDN
原文:https://blog.csdn.net/acktomas/article/details/88072797
版权声明:本文为作者原创文章,转载请附上博文链接!
内容解析By:CSDN,CNBLOG博客文章一键转载插件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值