-
Hi, I'm getting above mentioned exception when trying to replicate the JoystickAnalog example found here. Specifications:
Log:
Dependencies: ext {
pi4jVersion = '2.3.0'
}
dependencies {
implementation 'ch.qos.logback:logback-classic:1.4.7'
implementation "com.pi4j:pi4j-core:${pi4jVersion}"
implementation "com.pi4j:pi4j-plugin-raspberrypi:${pi4jVersion}"
implementation "com.pi4j:pi4j-plugin-pigpio:${pi4jVersion}"
} main(): public static void main(String[] args) {
Context context = Pi4J.newAutoContext();
JoystickAnalogApp app = new JoystickAnalogApp();
app.execute(context);
context.shutdown();
} JoystickAnalogApp#execute(): @Override
public void execute(Context pi4j) {
LOGGER.info("Joystick Test started");
Ads1115 ads1115 = new Ads1115(pi4j, 0x01, Ads1115.GAIN.GAIN_4_096V, Ads1115.ADDRESS.GND, 4);
//joystick with normalized axis from 0 to 1
JoystickAnalog joystick = new JoystickAnalog(pi4j, ads1115, 0, 1, 3.3, true, Pin.D26);
//register event handlers
joystick.xOnMove(value -> LOGGER.info("Current value of joystick x axis is: {}", String.format("%.3f", value)));
joystick.yOnMove(value -> LOGGER.info("Current value of joystick y axis is: {}", String.format("%.3f", value)));
joystick.pushOnDown(() -> LOGGER.info("Pressing the Button"));
joystick.pushOnUp(() -> LOGGER.info("Stopped pressing."));
joystick.pushWhilePressed(() -> LOGGER.info("Button is still pressed."), 1000);
joystick.calibrateJoystick();
//start continuous reading with single shot in this mode you can connect up to 4 devices to the analog module
joystick.start(0.05, 10);
//wait while handling events before exiting
LOGGER.info("Move the joystick to see it in action!");
delay(30_000);
//stop continuous reading
joystick.stop();
delay(1000);
//deregister all event handlers
joystick.deregisterAll();
LOGGER.info("Joystick test done");
} I've already remotely debugged my application, the exception is thrown when calling default int readRegisterWord(int register) {
byte[] buffer = new byte[2];
int actual = readRegister(register, buffer);
if (actual < 2) throw new IOReadException(actual);
return ((buffer[0] & 0xff) << 8) | (buffer[1] & 0xff);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
My error was solved by switching from auto context to a custom one, as provided in the above linked project. final var piGpio = PiGpio.newNativeInstance();
Context context = Pi4J.newContextBuilder()
.noAutoDetect()
.add(new RaspberryPiPlatform() {
@Override
protected String[] getProviders() {
return new String[]{};
}
})
.add(PiGpioDigitalInputProvider.newInstance(piGpio),
PiGpioDigitalOutputProvider.newInstance(piGpio),
PiGpioPwmProvider.newInstance(piGpio),
PiGpioSerialProvider.newInstance(piGpio),
PiGpioSpiProvider.newInstance(piGpio),
LinuxFsI2CProvider.newInstance())
.build(); I also therefore had to add the linux dependency in my |
Beta Was this translation helpful? Give feedback.
My error was solved by switching from auto context to a custom one, as provided in the above linked project.
Context context = Pi4J.newAutoContext();
to