Maker blocks for I2C

Can someone please help me learn how to setup I2C blocks for communications between Adafruit NRF52840 (or others) and other I2C units. At present I try to get a Adafruit PCF8575 Expander able to turn ON / OFF an LED, but am strugling to figure out how to do so. The address for the expander is HEX 0x20 (value 32 I believe) and the “data” addresses is two byte long.

So please teach me how to make the I2C blocks work the way I need them to, and I appreciate any help to get this to work.

The first thing you will want for that Adafruit PCF8575 is to find the datasheet. The datasheet tells you what you will need to send over I2C and why. For example: https://www.digikey.com/en/htmldatasheets/production/97868/0/0/1/pcf8575

Next you will see what is available so you are not re-inventing the wheel. See if someone already has done an interface. Even in a different language. If there is already an extension for MakeCode you will need to test it and possibly fix it. If it isn’t in the extension list already then there may be a reason for that. For the PCF8575 there is some C++ code. If you can translate that to Typescript then good. If not you could ask ChatGPT or Gemini or whatever to try to create one. You still need to test and fix it because AI doesn’t always get it right.

The other way to go is to use the I2C blocks from the pin library directly. Looking at the datasheet I think I would just use the Pin library. So I would start with something like this:

I don’t have a PCF8575 so this is not tested. You will need to do that and fix anything that goes wrong.

Hi Don, and thank you for your help. I have not yet tested what you have shown, but I will soon.

You may not have an PCF8575, but I want to learn how to make my own I2C setup using the “built-in” I2C blocks under “pins”. So if you could tell me how such a workflow would have to be done, that would be appreciatet. For now I need to figure out heads and tails of the image you have shown.