我正在尝试在Nano32上运行两个I2C总线。
#include <Wire.h>
#include "MS5837.h"
// Setup sensor 1
#define I2C_SDA_1_PIN 21
#define I2C_SCL_1_PIN 22
TwoWire I2C_1 = TwoWire(0);
MS5837 sensor_1;
// Setup sensor 2
#define I2C_SDA_2_PIN 17
#define I2C_SCL_2_PIN 16
TwoWire I2C_2 = TwoWire(1);
MS5837 sensor_2;
void setup() {
Serial.begin(115200);
Serial.println("Starting");
I2C_1.begin(I2C_SDA_1_PIN, I2C_SCL_1_PIN);
I2C_2.begin(I2C_SDA_2_PIN, I2C_SCL_2_PIN);
while (!sensor_1.init(I2C_1)) {
Serial.println("Init sensor 1 failed!");
delay(5000);
}
while (!sensor_2.init(I2C_2)) {
Serial.println("Init sensor 2 failed!");
delay(5000);
}
}
void loop() {
}
MS5837库来自https://github.com/bluerobotics/BlueRobotics_MS5837_Library,是而不是它可以通过Arduino IDE安装。原因是该版本不允许使用TwoWire端口设置。
我面临的问题是,我在编译时得到以下错误消息:
In file included from c:UserstammoOneDriveDocumentsArduinolibrariesBlueRobotics_MS5837_LibraryMS5837.h:41,
from c:UserstammoOneDriveDocumentsArduinolibrariesBlueRobotics_MS5837_LibraryMS5837.cpp:1:
C:UserstammoAppDataLocalArduino15packagesesp32hardwareesp322.0.6librariesWiresrc/Wire.h: In member function 'bool MS5837::init(TwoWire&)':
C:UserstammoAppDataLocalArduino15packagesesp32hardwareesp322.0.6librariesWiresrc/Wire.h:127:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int)'
uint8_t requestFrom(int address, int size);
^~~~~~~~~~~
C:UserstammoAppDataLocalArduino15packagesesp32hardwareesp322.0.6librariesWiresrc/Wire.h:125:13: note: candidate 2: 'uint8_t TwoWire::requestFrom(uint8_t, uint8_t)'
uint8_t requestFrom(uint8_t address, uint8_t size);
^~~~~~~~~~~
C:UserstammoAppDataLocalArduino15packagesesp32hardwareesp322.0.6librariesWiresrc/Wire.h: In member function 'void MS5837::read()':
C:UserstammoAppDataLocalArduino15packagesesp32hardwareesp322.0.6librariesWiresrc/Wire.h:127:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int)'
uint8_t requestFrom(int address, int size);
^~~~~~~~~~~
C:UserstammoAppDataLocalArduino15packagesesp32hardwareesp322.0.6librariesWiresrc/Wire.h:125:13: note: candidate 2: 'uint8_t TwoWire::requestFrom(uint8_t, uint8_t)'
uint8_t requestFrom(uint8_t address, uint8_t size);
^~~~~~~~~~~
C:UserstammoAppDataLocalArduino15packagesesp32hardwareesp322.0.6librariesWiresrc/Wire.h:127:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int)'
uint8_t requestFrom(int address, int size);
^~~~~~~~~~~
C:UserstammoAppDataLocalArduino15packagesesp32hardwareesp322.0.6librariesWiresrc/Wire.h:125:13: note: candidate 2: 'uint8_t TwoWire::requestFrom(uint8_t, uint8_t)'
uint8_t requestFrom(uint8_t address, uint8_t size);
^~~~~~~~~~~
Sketch uses 273661 bytes (20%) of program storage space. Maximum is 1310720 bytes.
Global variables use 22672 bytes (6%) of dynamic memory, leaving 305008 bytes for local variables. Maximum is 327680 bytes.
我不知道如何解决这个问题,希望能得到指点。
我在Sparkfun_Qwiic_Relay.cpp中遇到了类似的问题。问题是fromRequest有(uint8_t, uint8_t)和(int, int)声明,但它被称为fromRequest(uint8_t, int)。这会产生一个硬编译器错误。将int类型转换为uint8_t修复了编译错误。
wjr