Android Arduino 使用 I2C 的事情 - 错误 6:没有这样的设备或地址
Android Things to Arduino using I2C - error 6: No such device or address
我尝试使用 I2C 将 NXP i.MX7D 运行 Android Things 连接到 Arduino UNO。从属代码相当简单:
#include <Wire.h>
void setup() {
Wire.begin(0x08); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
delay(100);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
Wire.write("hello "); // respond with message of 6 bytes
// as expected by master
}
两台设备是这样连接的:
NPX SDA 引脚 ---> 3.3v 电平转换器 5v ----> Arduino 引脚 A4
NPX SCL 引脚 ---> 3.3v 电平转换器 5v ----> Arduino 引脚 A5
当我使用 PIO 工具时,我似乎无法连接或读取 Arduino 从设备。 NPX 上有两个总线(I2C1,I2C2)我都试过,结果相同:
imx7d_pico:/ $ pio i2c I2C1 0x08 read-reg-byte 0x00
[WARNING:client_errors.cc(35)] error 6: No such device or address
6|imx7d_pico:/ $ pio i2c I2C2 0x08 read-reg-byte 0x00
[WARNING:client_errors.cc(35)] error 6: No such device or address
我假设电平转换器工作正常我确实在 UART 连接上取得了有限的成功(Arduino 能够发射到 NPX 但不能发射到 Arduino,之后将对此进行调查)
这里是连接的一些图片。
尝试添加 on Wire.onReceive 回调(与 onRequest 一起)到您的 arduino 代码中。
像这样:
#include <Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
我尝试使用 I2C 将 NXP i.MX7D 运行 Android Things 连接到 Arduino UNO。从属代码相当简单:
#include <Wire.h>
void setup() {
Wire.begin(0x08); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
delay(100);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
Wire.write("hello "); // respond with message of 6 bytes
// as expected by master
}
两台设备是这样连接的:
NPX SDA 引脚 ---> 3.3v 电平转换器 5v ----> Arduino 引脚 A4 NPX SCL 引脚 ---> 3.3v 电平转换器 5v ----> Arduino 引脚 A5
当我使用 PIO 工具时,我似乎无法连接或读取 Arduino 从设备。 NPX 上有两个总线(I2C1,I2C2)我都试过,结果相同:
imx7d_pico:/ $ pio i2c I2C1 0x08 read-reg-byte 0x00
[WARNING:client_errors.cc(35)] error 6: No such device or address
6|imx7d_pico:/ $ pio i2c I2C2 0x08 read-reg-byte 0x00
[WARNING:client_errors.cc(35)] error 6: No such device or address
我假设电平转换器工作正常我确实在 UART 连接上取得了有限的成功(Arduino 能够发射到 NPX 但不能发射到 Arduino,之后将对此进行调查)
这里是连接的一些图片。
尝试添加 on Wire.onReceive 回调(与 onRequest 一起)到您的 arduino 代码中。
像这样:
#include <Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}