Ir para conteúdo
View in the app

A better way to browse. Learn more.

EletrônicaBR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Navegação Limpa e Sem Anúncios! (Cadastre-se)

O melhor fórum técnico do mundo está de cara nova e de portas abertas! Estamos de cara nova e com ferramentas ainda mais poderosas para a sua bancada. Faça o seu cadastro de forma rápida e simples para acessar o maior e mais atualizado acervo de Esquemas Elétricos, BIOS e Firmwares da internet.

Aqui, o conhecimento vale muito: através do nosso sistema de créditos, membros participativos ganham acesso totalmente gratuito aos downloads. Venha trocar experiências com os melhores especialistas do mercado!

👉 Técnico sem o EletrônicaBR não é um técnico completo!

 

Como usar o i2c no Arduino

Featured Replies

  • 10 meses depois...
Postado

I'll share an example by Dejan from HowToMechatrinics, if you need more help understanding the script, please let me know:

 

/* 

 *  How I2C Communication Protocol Works - Arduino I2C Tutorial

 */

 

#include <Wire.h>

 

int ADXLAddress = 0x53; // Device address in which is also included the 8th bit for selecting the mode, read in this case.

 

#define X_Axis_Register_DATAX0 0x32 // Hexadecima address for the DATAX0 internal register.

#define X_Axis_Register_DATAX1 0x33 // Hexadecima address for the DATAX1 internal register.

#define Power_Register 0x2D // Power Control Register

 

int X0,X1,X_out;

 

void setup() {

  Wire.begin(); // Initiate the Wire library

  Serial.begin(9600);

  delay(100);

  // Enable measurement

  Wire.beginTransmission(ADXLAddress);

  Wire.write(Power_Register);

  // Bit D3 High for measuring enable (0000 1000)

  Wire.write(8); 

  Wire.endTransmission();

}

 

void loop() {

  Wire.beginTransmission(ADXLAddress); // Begin transmission to the Sensor

  //Ask the particular registers for data

  Wire.write(X_Axis_Register_DATAX0);

  Wire.write(X_Axis_Register_DATAX1);

 

  Wire.endTransmission(); // Ends the transmission and transmits the data from the two registers

 

  Wire.requestFrom(ADXLAddress,2); // Request the transmitted two bytes from the two registers

 

  if(Wire.available()<=2) {  //

    X0 = Wire.read(); // Reads the data from the register

    X1 = Wire.read();  

  }

 

  Serial.print("X0= ");

  Serial.print(X0);

  Serial.print("   X1= ");

  Serial.println(X1);

}

 

Regards from Argentina.

Julio.

Participe agora da conversa!

Você pode postar agora e se cadastrar mais tarde. Se você tiver uma conta, faça login para postar com sua conta.

Visitante
Responder

Account

Navigation

Pesquisar

Pesquisar

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.