文章目录
- 有用的链接
- 表示加速度传感器灵敏度的几种方法LSB/g,count/g,V/g,V/°
- I2C通信之Arduino加速传感器ADXL345
有用的链接
-
Arduino Wire参考:https://www.arduino.cc/en/Reference/Wire。
-
我翻译的Wire图书馆的应用说明:https://blog.csdn.net/acktomas/article/details/88069640
-
I2C双向电平转换器(https://playground.arduino.cc/Main/I2CBi-directionalLevelShifter/),用于电平转换、上拉电阻和连接3.3V器件。
-
Nick Gammon的有关I2C页面(关于I2C详细介绍了原理:http://gammon.com.au/i2c(页面上还有一个 I2C)。 我翻译内容:I2C-两线外设界面-用于Arduino:https://download.csdn.net/download/acktomas/11824487
-
robtillaart制作了“ Multispeed I2C Scanner(https://forum.arduino.cc/index.php?topic=197360)” ,不同的可以使用I2C扫描速度。如果使用更长的导线或更高的导线I2C速度库,是的Multispeed I2C扫描仪会很有用。(与UNO2009年一起验证,MEGA) 赛斯维传感器网http://www.sensorway.cn/knowledge/
表示加速度传感器灵敏度的几种方法LSB/g,count/g,V/g,V/°
在几种方式之间给出解释和转换公式: 1)、LSB这意味着数字输出是最小有效的。一般来说,我们可以使用它mg/LSB以表示灵敏度为例,ADI加速传感器ADXL345量程为 /2g,输出位数为10位(210次方共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模拟电压输出的灵敏度表示。 简单介绍一下V/g和V/°以SCA100T-D以01为例,其灵敏度为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度的电压变化不能计入70度mV/°*15,这样计算式错误的
Table 1.Configuring the g-Select for 8-bit output using Register $16 with GLVL[1:0] bits
GLVL[1:0] | g-Range | Sensitivity |
---|---|---|
00 | 8g | 16LSB/g |
01 | 2g | 64LSB/g |
10 | 4g | 32LSB/g |
比如上表为MMA7455L 加速传感器
量程为4g 输出位数为8位,28次为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
)
;
}