See the IO Pins page here for any extensions needed by Visual Studio and to enable the IO pins.


using Windows.Devices.Enumeration;
using Windows.Devices.I2c;

Initialise I2C Port For A Device

Write Bytes

	byte[] I2cWriteBuffer;

	//Write to I2C device
	I2cWriteBuffer = new byte[] { 0x01, 0x02 };
	OurI2cPort.Write(I2cWriteBuffer);						//Writes I2cWriteBuffer.Length bytes

	//Another way:
	OurI2cPort.Write(new byte[] { 0x01, 0x02 });						//Writes I2cWriteBuffer.Length bytes

Write Then Read Bytes

	byte[] I2cWriteBuffer;
	byte[] I2cReadBuffer;

	//Write then read I2C device
	I2cWriteBuffer = new byte[] {0x01, 0x02};
	I2cReadBuffer = new byte[3];
	OurI2cPort.WriteRead(I2cWriteBuffer, I2cReadBuffer);    //Writes I2cWriteBuffer.Length bytes, then does a restart and reads I2cReadBuffer.Length bytes

	//Another way:
	I2cReadBuffer = new byte[1];
	OurI2cPort.WriteRead(new byte[] { 0x00 }, I2cReadBuffer);
	// = I2cReadBuffer;

Read Bytes

	byte[] I2cReadBuffer;

	//Just read from I2C device
	I2cReadBuffer = new byte[4];
	OurI2cPort.Read(I2cReadBuffer);                         //Reads I2cReadBuffer.Length bytes

Disposing Of A I2C Device Object


We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.