I2C Manual Data Reading

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
AleMonk
 
Posts: 2
Joined: Wed Mar 23, 2022 6:12 am

I2C Manual Data Reading

Post by AleMonk »

Hello, I'm an Electronic Engineering student and, for my thesis, I'm doing a little project with Adafruit ICM-20948 sensor.
I have to find a way to use the I2C bus communication using only wire.h classes (begin, read, write, beginTransmission, ecc...) but, if I do like so, I get only random values as a result.
I'm wondering if there's a way to make it work, because I tried to read some Adafruit libraries but I didn't find the information I needed.

Here you can find my code:

Code: Select all

#include <Wire.h>

void setup() {
  Wire.begin();
  Serial.begin(9600);
}

int numOfBytes = 4;
byte x = 0;

void loop() {
/*I send to the slave its address and the register I want to read
In this way it should return the data I need /*
  Wire.beginTransmission(0x69);
  Wire.write(0x69); //sensor address
  Wire.write(0x28); //register I want to read
  
  Wire.requestFrom(0x69, numOfBytes);
  while(Wire.available()){
    count++;
    x = Wire.read();
    Serial.print(x);
    Serial.print("\t");
  }
  Serial.println();
  delay(1000);
}
Last edited by adafruit_support_carter on Thu Apr 28, 2022 10:47 am, edited 1 time in total.
Reason: added [code] tags

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: I2C Manual Data Reading

Post by adafruit_support_carter »

You're missing a call to Wire.endTransmission() here:

Code: Select all

  Wire.beginTransmission(0x69);
  Wire.write(0x69); //sensor address
  Wire.write(0x28); //register I want to read
See basic write example:
https://www.arduino.cc/reference/en/lan ... ire/write/

You also don't need this line:

Code: Select all

  Wire.write(0x69); //sensor address
The address is already passed in and taken care of with Wire.beginTransmission(0x69);

See datasheet for basic I2C communication protocol examples:
https://invensense.tdk.com/wp-content/u ... 8-v1.3.pdf

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”