Adafruit QT Py RP2040 (ADA4900)

For low-level reads like this the Arduino example you’re using is a little misleading.

You have to tell the device what register you want to read from in the form of a write
Then read the desired number of bytes.

Review this document

A complete read transaction has

  • 1st byte: a start Bit followed by Device address, and a write bit
  • 2nd byte: the register to be read from
  • 3rd byte: a repeat start, the Device Address, and a read bit
  • 4th byte: data is clocked from the device to the controller

I think you might want to try my (untested, GPT generated) code:

#include <Wire.h>

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize I2C communication
  Wire.begin();

  
}

void loop() {
  // Request one byte from the device at address 0x42, from register 0x12
  Wire.beginTransmission(0x42); // Start communication with the device at address 0x42
  Wire.write(0x12); // Specify the register address you want to read from
  Wire.endTransmission(false); // End transmission, but don't release the I2C bus

  Wire.requestFrom(0x42, 1); // Request 1 byte from the device
  while (Wire.available()) { // Wait for the data to be available
    byte data = Wire.read(); // Read the byte
    Serial.print("Received data: ");
    Serial.println(data, HEX); // Print the data in hexadecimal format
  }

 delay(100)
}

1 Like

Ah this is super interesting!
I had tried something like chat gpts recommendations based on code I found on the Arduino forums. Seeing it again made me try it in a vanilla project with no other code running. If you run this code in a new .ino file, all by itself, it works.

:peach: BUT!! :peach:
In my project I’m running the OLED animation on one core and the button checks on another.
If you run the same working code for the button above on core 1, but currently run code for the oled on core 2, it doesn’t work. The channel is noisy.
So my problem is that I’m running parallel threads on the same bus.

Very sad! I might have to come up with a new strategy.

Pix :heavy_heart_exclamation:

2 Likes

That sounds about right :expressionless:
But you have 2x I2C ports on the device! :smiley: So all is not lost.

OR, ditch the multithreading and schedule your bus transactions :wink:

2 Likes