I'm building an application on the Raspberry that required more I/O pins then the GPIO offered. So using i2c and the MCP23017 IC I'm having partial success.
I can execute the i2cset commands from the command line and they work perfectly, example:
Code: Select all
To set up GPB0-7 as outputs:
sudo i2cset -y 1 0x20 0x01 0x00
To turn on GPB0:
sudo i2cset -y 1 0x20 0x15 0x01
The problem comes in when I try to use the same i2cset commands in my PHP program. I have the Raspberry running apache2 and php5.
Code: Select all
<?php
system ('sudo i2cset -y 1 0x20 0x01 0x00'); /* set GPB0-7 to output pins */
system ('sudo i2cset -y 1 0x20 0x15 0x01'); /* turn on GPB0 */
?>
Nothing happens when I run the code, no errors, nothing... I'm thinking since i2cset must be run with sudo that is it possible its a permission problem? Regardless what the problem is, how can I execute i2cset commands from PHP?
Thanks
George