【发布时间】:2017-01-18 02:47:18
【问题描述】:
我需要从 TTP229 读取 2 个不同的字节(16 键或 8 键触摸板检测器)。
我在 Python 中使用 I2C。 TTP229 datasheet PDF.
我无法读取第二个字节,但我可以获取第一个字节。
Python 代码:
import smbus
bus = smbus.SMBus(1)
adressTTP229 = 0x57 #0xAF>>1
byte1 = bus.read_byte(adressTTP229)
byte2 = bus.read_byte(adressTTP229)
byte1 始终等于byte2。
这个 Arduino 代码,工作正常:
#include <Wire.h>
#define ttp229 (0xAF>>1)
void setup() {
Serial.begin(9600); // start serial for output
Wire.begin();
}
void loop() {
delay(50);
bool isNewData = false;
Wire.requestFrom(ttp229,2,true);
while (Wire.available()) {
uint16_t b1 = Wire.read(); // receive a first byte
uint16_t b2 = Wire.read(); // receive a second byte
if (b1==b2 && b2==0) {break;}
//...
}
}
如何在 Python 中使用 Arduino 的 requestFrom() 函数?
【问题讨论】:
-
用 C 语言编写的模块,用于 Python,与芯片 TTP229 配合使用。 github libttp229
标签: python linux arduino raspberry-pi i2c