使用I2C和Arduino与LCD1312芯片通信

时间:2018-06-08 21:33:16

标签: arduino i2c

我正在尝试使用如说明书中所述的I2C与LCD1312芯片通信。我正在使用Arduino这样做。我做了连接,仔细检查数据表后,我无法读出电感。我得到的只是255.如果有人做了类似的话,我试着在网上查询,但是没有成功。附上我在Arduino的代码:

P.S。不幸的是,我之前没有i2c的经验。我收到字节包,但都是255。 另外,我将每个串联的上拉电阻连接到SDA和SCL。

/////////

#include <Wire.h>

void setup() {
Wire.begin();    // join i2c bus (address optional for master)
Serial.begin(9600); // start serial communication at 9600bps
}

int reading1 , reading2 ;
byte d;

void loop() {
// step 1: instruct sensor to read echoes
Wire.beginTransmission(42); // 0x2A if ADDR is high
Wire.write(byte(0x00)); // Choosing whether to Read or Write
Wire.write(byte(0x00)); // Address to read (channel one is at address 0 according to the datasheet)

Wire.endTransmission(); // stop transmitting

delay(70); // 

Wire.beginTransmission(42); // 
Wire.write(byte(0x01)); // Read
Wire.endTransmission(); // stop transmitting

// 
Wire.requestFrom(42, 2); //

// 
int wireAv = Wire.available();
int index = 0;
Serial.println(wireAv);

if (wireAv)
{
d = Wire.read();
Serial.println("in while ");
Serial.print("d is ");
Serial.println(d,DEC);
Serial.println(" ");
}

delay(250); // wait a bit since people have to read the output 
}

////////////

谢谢!

干杯,

0 个答案:

没有答案
相关问题