【发布时间】:2021-02-03 15:57:53
【问题描述】:
我无法在两个 I2C 接口上使用两个传感器。
问题是,当我尝试用以下内容替换 Wire.begin() 时:I2C.begin(21, 22),我的传感器 QMC5883L 返回 x、y 和 z 0。我手动包含了 Wire 库并创建了一个 TwoWire 对象:
#include <Wire.h>
TwoWire I2C = TwoWire(0);
当我尝试这个时,我在库中评论了_wire->begin(),它与草图中的Wire.begin() 的评论行和一起工作,但是当我尝试将Wire.begin()替换为I2C.begin(21, 22) 已经不行了。
这应该起作用的原因是我想创建 2 个这样的接口,然后将它们提供给 compass.begin(&I2C) 方法。在图书馆里我有这个:
void QMC5883LCompass::init(TwoWire *theWire){
_wire = theWire;
_wire->begin(); // this is the line I commented, when getting the zeros...
_writeReg(0x0B,0x01);
setMode(0x01,0x0C,0x10,0X00);
}
我是不是忘记了什么?
【问题讨论】: