CPX MakeCode I2C control

This MakeCode program for the Circuit Playground Express (CPX) shows how to control an Adafruit 4-digit 7-segment display using I2C bus statements. Comments in the program give details, and a related question follows.

I used a Digilent Electronics Explorer board and its Waveforms software Protocol Analyzer to look at CPX I2C bus traffic. I found that these CPX Arduino statements produce the given I2C bus traffic.

dsp7seg.begin(0x70); // default Adafruit 7-seg display I2C address
// Start, hE0 [ h70 | WR ], Stop
// Start, hE0 [ h70 | WR ], h21, Stop
// Start, hE0 [ h70 | WR ], h00, h00, h00, h00, h00, h00, h00, h00, h00, h00, h00, h00, h00, h00, h00, h00, h00, Stop
// Start, hE0 [ h70 | WR ], h81, Stop
// Start, hE0 [ h70 | WR ], hEF, Stop
dsp7seg.println(“0123”);
// no I2C output yet
dsp7seg.writeDisplay();
// Start, hE0 [ h70 | WR ], h00, h3F, h00, h06, h00, h00, h00, h5B, h00, h4F, h00, h00, h00, h00, h00, h00, h00, Stop

The Holtek HT16K33 datasheet (“Command Summary” on page 30) shows what that I2C bus traffic means to the LED display Backpack board. “h21” = System Setup, Oscillator On. “h00” = Display Data Address Pointer (h00) followed by 16 bytes of 0 data. “h81” = Display Setup, Blinking Off, Display On. “hEF” = Dimming Set, 16/16 Duty Cycle. “writeDisplay()” shows where h3F (7-segment ‘0’) h06 (‘1’) h00 (colon off) h5B (‘2’) h4F (‘3’) are positioned. The first “h00” and the “hEF” commands are not required to get the chip into operating condition.

The given MakeCode program produces this I2C bus traffic:

Error!
Start, hE0 [ h70 | WR ], h21, Stop
Start, hE0 [ h70 | WR ], h81, Stop
Start, hE0 [ h70 | WR ], h00, h3F, Stop
Start, hE0 [ h70 | WR ], h02, h06, Stop
Start, hE0 [ h70 | WR ], h04, h00, Stop
Start, hE0 [ h70 | WR ], h06, h5B, Stop
Start, hE0 [ h70 | WR ], h08, h4F, Stop

What is the initial “Error!” and how do I eliminate it using only Adafruit MakeCode statements (not JavaScript)?

I think there is no way to do the equivalent of the Arduino “Start, hE0 [ h70 | WR ], Stop” I2C operation and that this is a required but missing Adafruit MakeCode statement. But someone correct me if that is wrong.

I still hope to get a reply to the question that started this thread – “What is the initial “Error!” and how do I eliminate it using only Adafruit MakeCode statements (not JavaScript)?” But while looking into it further I developed two I2C-related MakeCode programs worth sharing.

This CPX MakeCode program works with any Adafruit display with an I2C Backpack based on the HT16K33 chip, such as their
4-Digit 7-Segment Display
Quad Alphanumeric Display
Bicolor LED Square Pixel Matrix
and others.

It walks a single 1 bit through all 128 possible locations in the HT16K33 registers, showing which register (indicated in binary on the CPX NeoPixels) and bit controls which display LED. This allows MakeCode to do individual LED control of these displays like the Adafruit CircuitPython and Arduino libraries do.

This CPX MakeCode and JavaScript program shows how to use JavaScript Buffers to write to HT16K33 registers. The Adafruit MakeCode “i2c read register” statement is currently unusable (see the defect report here) but the JavaScript equivalent works and is demonstrated in the program.