These read an 8 or 16-bit value from the device register indicated. int wiringPiI2CReadReg16 (int fd, int reg).int wiringPiI2CReadReg8 (int fd, int reg).These write an 8 or 16-bit data value into the device register indicated. int wiringPiI2CWriteReg16 (int fd, int reg, int data).int wiringPiI2CWriteReg8 (int fd, int reg, int data).Some devices accept data this way without needing to access any internal registers. int wiringPiI2CWrite (int fd, int data).Some devices present data when you read them without having to do any register transactions. the popular MCP23017 GPIO expander is usually device Id 0x20, so this is the number you would pass into wiringPiI2CSetup().įor all the following functions, if the return value is negative then an error has happened and you should consult errno. int saveLocation 4095 Wire.write ( (int) (saveLocation > 8)) Question 1: Do the parenthesis. The return value is the standard Linux filehandle, or -1 if any error – in which case, you can consult errno as usual.Į.g. I'm having troubles understanding this line of code that I see with every Arduino EEPROM tutorial. wiringPiI2CSetup() will work out which revision Raspberry Pi you have and open the appropriate device in /dev. The ID is the I2C number of the device and you can use the i2cdetect program to find this out. Reading and writing to registers which are in turn read/written by the master. This initialises the I2C system with your given device identifier. Note that you can use the gpio command to run the i2cdetect command for you with the correct parameters for your board revision: gpio i2cdetect Just remember that on a Rev 1 Raspberry pi it’s device 0, and on a Rev. You can still use the standard system commands to check the I2C devices, and I recommend you do so – e.g. Programs need to be linked with -lwiringPi as usual. To use the I2C library, you need to: #include If you need a baud rate other than the default 100Kbps, then you can supply this on the command-line: gpio load i2c 1000
#Wire library read from how to#
YOU NEED TO CONSULT SOMEONE ELSE TO WORK OUT HOW TO MAKE SURE THE I2C KERNEL SYSTEM IS WORKING BEFORE YO CAN USE THESE I2C WRAPPERS IN YOUR C PROGRAMS.īefore you can use the I2C interface, you may need to use the gpio utility to load the I2C drivers into the kernel: gpio load i2c
#Wire library read from software#
NOTE: THE GPIO LOAD SECTION IS OUT OF DATE AND NO-LONGER RELEVANT TO A MODERN Pi SOFTWARE DISTRIBUTION THAT USES THE DEVICE TREE. WiringPi includes a library which can make it easier to use the Raspberry Pi’s on-board I2C interface.