Pi4J / pi4j-v2

Pi4J Version 2.0
Apache License 2.0
266 stars 54 forks source link

Is I2C available in this project for output to a 16x2 LCD? #316

Closed jchristof closed 6 months ago

jchristof commented 6 months ago

RPi4 running RPiOs 64-bit Bookworm with desktop env. and recommended applications. Java is installed. Launching the components project, Intellij using remote ssh to Pi as root user. Trying to run #9 LCD example. Other launcher examples work fine such as the blinking led.

I scanned some of the Git issues and I'm confused as to whether I should be able to drive output to my 16x2. It looks like running as root should solve the issues but it's not working for me.

Could someone point out what I need to do to get I2C working?

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()//,
                            //PiGpioI2CProvider.newInstance(piGpio)
                    )

With LinuxFsI2CProvider

java.lang.reflect.UndeclaredThrowableException
    at jdk.proxy2/jdk.proxy2.$Proxy9.create(Unknown Source)
    at com.pi4j@2.4.0/com.pi4j.context.Context.create(Context.java:325)
    at com.pi4j@2.4.0/com.pi4j.internal.IOCreator.create(IOCreator.java:58)
    at com.pi4j@2.4.0/com.pi4j.internal.IOCreator.create(IOCreator.java:126)
    at com.pi4j.example/com.pi4j.catalog.components.base.I2CDevice.<init>(I2CDevice.java:24)

With PiGpioI2CProvider

java.lang.IllegalArgumentException: PIGPIO ERROR: INVALID I2C/SPI/SERIAL HANDLE [-74]; Valid range: >0
    at com.pi4j.library.pigpio@2.4.0/com.pi4j.library.pigpio.impl.PiGpioBase.validateHandle(PiGpioBase.java:278)
    at com.pi4j.library.pigpio@2.4.0/com.pi4j.library.pigpio.impl.PiGpioNativeImpl.i2cWriteByte(PiGpioNativeImpl.java:853)
    at com.pi4j.plugin.pigpio@2.4.0/com.pi4j.plugin.pigpio.provider.i2c.PiGpioI2C.write(PiGpioI2C.java:107)
    at com.pi4j.example/com.pi4j.catalog.components.base.I2CDevice.write(I2CDevice.java:62)
taartspi commented 6 months ago

Looking at the Pigpio issues, it will not work on P5. There is no detail on when the Pigpio might be modified. There are comments stating this appears to be a large undertaking and there is no firm commitment on who/when. Also, the linuxFS on P5 is not clearly understood. As more of us actually have a P5 in our hands we can validate what does and does not function and then size the work.

jchristof commented 6 months ago

Thanks for the reply - this is a RPi 4.

taartspi commented 6 months ago

Oh man. I saw bookworm and jumped to p5. U clearly said p4. I do have a bookworm image waiting for a p5. I will load it into a p4 and try your code. What is the model of the 16x2 you are using and the version of pi4j ?

jchristof commented 6 months ago

It's out of a FREENOVE starter kit. The tutorial docs describe it:

"The serial-to-parallel IC chip used in this module is PCF8574T (PCF8574AT), and its default I2C address is 0x27(0x3F). You can also view the RPI bus on your I2C device address through command "i2cdetect -y 1" (refer to the "configuration I2C" section below). "

jchristof commented 6 months ago

In /dev crw-rw---- 1 root i2c 89, 20 Jan 18 21:17 i2c-20 crw-rw---- 1 root i2c 89, 21 Jan 18 21:17 i2c-21

jchristof commented 6 months ago

Pi4j version - I cloned the main branch of the component project. https://github.com/Pi4J/pi4j-example-components

2.4.0
jchristof commented 6 months ago

Thanks again @taartspi. I spent some time reading the manual and discovered that I needed to enable the i2c interface in raspi config. The listing of the i2c bus in /dev threw me off and I thought it was pre-enabled.

jchristof commented 6 months ago

User error - needed to read the manual.

taartspi commented 6 months ago

Evening. Glad you got it going. Take care

taartspi commented 6 months ago

also You mentioned using ssh to connect. If you wanted VNC: When starting up bookworm I saw vnc viewers failed.
The temporary fix, raspi-config advanced Wayland, set x11.

sudo nano .config/wayvnc/config address=0.0.0.0 enable_auth=false enable_pam=true private_key_file=/home/pi/.config/wayvnc/key.pem certificate_file=/home/pi/.config/wayvnc/cert.pem

Then realVNC functioned.