I'm trying to read and write to modules on the I2C bus on a Raspberry Pi using PHP. I'm using fopen() and fskeek().

Below is the code I've been trying to use to read data coming in from the physical device at location 19. This code reads nothing from the character device file /dev/i2c-1.

$i2c = fopen( '/dev/i2c-1', "rb" );
fseek( $i2c, hexdec( '19' ), SEEK_CUR );
echo fread( $this->i2c, 1000 );

I know I have two physical devices on my I2C Bus ( block 1 ) at locations 19 and 1e. I am certain this is working because I've installed i2c-tools and run i2cdetect -y 1. I am seeing data from the devices i have hooked up via a C++ app I'm running from this tutorial: http://blog.memsme.com/raspberry-pi-lsm303dlhc-2/

I'm aware that I could simply wrap i2c-tools commands in php to get the functionality I'm looking for. That is not what I want to do if I can avoid it. Perhaps I cannot. It's probably fairly obvious I'm not sure what I'm doing, but I'm exploring the Raspberry Pi with PHP in an attempt to open up this kind of low level development to a wider audience. Perhaps it's futile...

closed as off-topic by goldilocks Jan 13 '15 at 22:35

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – goldilocks
If this question can be reworded to fit the rules in the help center, please edit the question.