Replies: 1 comment
-
//This code works for vl53lox import com.pi4j.context.Context;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have successfully ported a relevant amount of working and tested code from Pi4j V1 to Pi4j V2.
My code runs on Raspberry Pi4, Raspbian 64 bits, java 11+, and uses Pi4J V2 Digital Outputs, SPI and i2c. I use PiGpio as a Pi4J provider.
I successfully tested the code in a local configuration, with the JVM running on the target RaspberryPi, and all works as expected. Since I can't keep from looking for troubles, I began experimenting with a remote PiGpio configuration, where a PiGpio daemon running as root on the Raspberry and controlling the hardware receives commands from a network socket from a Pi4J running somewhere.
Here, I had mixed fortunes, as I tried to explain in the following image:
Remote configs.pdf
A "pseudo-remote" configuration where both PiGpioD and the application run on the same RaspberryPi (or perhaps on different but identical RaspberryPis) works FLAWLESSLY: Digital Outputs work, SPI Works, i2c Works.
But then I tried a more challenging config (number 3), where the code runs on an alien machine (the Mac I use for development), and PiGpioD runs on the Raspberry Pi. I was prepared for anything and expected the entire code to crash miserably.
To my astonishment, the Digital Outputs and the SPI (where I have a display attached) work without a glitch in this configuration.
Unfortunately, i2c tries to do its things, but the code throws various PiGpio-related exceptions when attempting read/write from i2c.
I am asking if there is a known workaround for this, or if it could be a bug (or maybe a feature that can't be implemented, but it would seem strange to me that DigitalOututs and SPI work fine in remote but i2c does not).
First root error occurring the first time i2c is open in configuration 3 (see the drawing) is:
com.pi4j.library.pigpio.PiGpioException: PIGPIO ERROR: PI_BAD_HANDLE; unknown handle at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:265) at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:251) at com.pi4j.library.pigpio.impl.PiGpioBase.validateResult(PiGpioBase.java:232) at com.pi4j.library.pigpio.impl.PiGpioSocketImpl.gpioSetMode(PiGpioSocketImpl.java:209) at com.pi4j.plugin.pigpio.provider.i2c.PiGpioI2C.<init>(PiGpioI2C.java:74) at com.pi4j.plugin.pigpio.provider.i2c.PiGpioI2CProviderImpl.create(PiGpioI2CProviderImpl.java:82) at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318) at kabasys.hardware.RaspberryPi4JV2HardManager.getI2cHandle(RaspberryPi4JV2HardManager.groovy:380)
(please remember the same code works fine in "local" and "pseudo-remote" configurations.
Then further errors follow on reading/writing values from/to i2c, like:
com.pi4j.io.exception.IOReadException: I/O READ ERROR: 0 at com.pi4j.io.i2c.I2CRegisterDataReader.readRegisterWord(I2CRegisterDataReader.java:707) at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318) at kabasys.hardware.RaspberryPi4JV2HardManager.llI2cReadReg16(RaspberryPi4JV2HardManager.groovy:415)
or:
com.pi4j.io.exception.IOReadException: I/O READ ERROR: -77 at com.pi4j.io.i2c.I2CRegisterDataReader.readRegisterByte(I2CRegisterDataReader.java:694) at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318) at kabasys.hardware.RaspberryPi4JV2HardManager.llI2cReadReg8(RaspberryPi4JV2HardManager.groovy:405)
My init code is as follows:
` PiGpio piGpio = PiGpio.newSocketInstance("192.168.1.40", 8888)
(the JVM compiler I'm using is Groovy instead of Java, hence the lack of semicolons and the different positioning of the dots)
Now, in the "remote" configuration the board/platform detection by Pi4J obviously fails: but the Pi4J context/runtime successfully initialize. And SPI/Digital Outputs work out of the box.
Shall I perform a different initialisation, maybe forcing the correct board type?
If yes, could any good man suggest an initialisation sequence allowing to run i2c in remote mode?
Thank you all
Beta Was this translation helpful? Give feedback.
All reactions