embedded-php / ext-i2c

Embedded PHP: I2C Extension
Other
1 stars 1 forks source link

Getting "undefined symbol: i2c_smbus_write_byte" inside the .so binary #2

Open halfer opened 1 year ago

halfer commented 1 year ago

I am working on a project on a Raspberry Pi 3 that combines a MCP2221 chip with a ST7789V2 LCD panel. The first of these connects to the Pi via USB, and connects to the LCD via a Grove/Stemma wire. I'd like to be able to write graphics primitives to the panel from USB.

I have installed PHP 8.2 on the latest Raspberry Pi OS via the additional "Sury" repo, this seems fine.

I then went through the ext-i2c build steps and I can see i2c in my php -m.

I am using this resource to understand what bytes to send to the LCD panel. I think I need to communicate in raw I2C, but I have very little idea of what I am doing!

I know the LCD device has a default wire address of 0x3e.

For the 0x04 command (get firmware version) I believe I need to send one byte and get back four. I am trying to do it with this code (typed by hand, I don't have a GUI on the Pi):

<?php

$projectRoot = __DIR__;
require_once $projectRoot . '/vendor/autoload.php';

use I2C\Bus as I2CBus;

$busId = 2;
$i2cAddress = 0x3e;

$bus = new I2CBus($busId, $i2cAddress);
echo "Set up bus class\n";

$bus->write(0x04);
$byte0 = $bus->read();
$byte1 = $bus->read();
$byte2 = $bus->read();
$byte3 = $bus->read();
echo "Attempted to read 4 bytes from device\n";

When I run this I get a low-level error:

php: symbol lookup error: /usr/lib/php/20220829/i2c.so: undefined symbol: i2c_smbus_write_byte

Should I try PHP 8.1? Might my ext-i2c build have been defective?

halfer commented 1 year ago

Ah, so it's not PHP 8.2 - I have just reset to PHP 8.1, and I get the same error (with of course the modified Zend year/version number in the directory).

halfer commented 1 year ago

From a bit of research, it looks like there is a class of I2C functions that have been removed from Linux modules, so would guess I would need to link to an earlier version.

More information here: https://github.com/hallard/ArduiPi_OLED/issues/15#issuecomment-322444243

flavioheleno commented 1 year ago

Hi @halfer , sorry for the radio silence, days have been a bit busy on this end. The error is indeed a difference between the kernel version against which you compiled the extension and the kernel version you are running it on. Would you please let me know each version so I can take a look at the changes?

halfer commented 1 year ago

No worries, thank you. As it happens I was trying to solve a problem the wrong way anyway - it turns out that I need to talk to the MCP2221 via USB, which will issue I2C commands on my behalf!

Let me get the information I think you need. First the kernel:

uname --all
Linux raspberrypi 6.1.23-v8+ #1642 SMP PREEMPT Mon Apr  3 17:42:16 BST 2023 aarch64 GNU/Linux

I have done the build and the run on the same Raspberry Pi 3B.

I wonder if you need information about libi2c, but I can't find it - I thought it would be available via lsmod. Do let me know what you need, and how I can get it.

halfer commented 1 year ago

Ah, just looking at modinfo i2c_dev - vermagic gives me 6.1.28-v8+, though I note this is slightly different to the uname line above.

flavioheleno commented 1 year ago

it turns out that I need to talk to the MCP2221 via USB, which will issue I2C commands on my behalf!

Indeed that's the case! Sorry that I did not mention that before, the error got my full attention and I left that behind.

as to kernel and module version, I'll do some research here