我試圖通過I2c將數據從Raspberry PI發送到Arduino。
當我用獨立的Java應用程序執行代碼時,我能夠發送和接收沒有問題的數據(代碼波紋管給我預期的結果)。Jetty Pi4J I2C錯誤操作/ dev/i2c-1
public static void main(String[] args) throws Exception {
// get I2C bus instance
final I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
I2CDevice arduino = bus.getDevice(0x04);
byte[] buffer = new byte[1];
buffer[0] = 1;
arduino.write(buffer, 0, buffer.length);
Thread.sleep(100);
buffer[0] = 0;
int number = arduino.read(buffer, 0, 1);
}
然後我嘗試同樣的代碼,但是這一次卻是一個Servlet內,在樹莓派使用碼頭,我也得到了以下錯誤:
java.io.IOException: Cannot open file handle for /dev/i2c-1 got -1 back.
at com.pi4j.io.i2c.impl.I2CBusImpl.<init>(I2CBusImpl.java:96)
at com.pi4j.io.i2c.impl.I2CBusImpl.getBus(I2CBusImpl.java:70)
at com.pi4j.io.i2c.I2CFactory.getInstance(I2CFactory.java:56)..
有誰知道什麼可能是發生了什麼?
問候,
有。我從中得出了答案。如果你不認爲這是一個答案,那麼它是一個評論,所以刪除它。 – Drew
請添加一些解釋。 –