티스토리 뷰

  • Arduino Source Code
  • I2C Communication
  • ONLY 'DEVICEADDRESS1_WRITE' is correct

 

#include <Wire.h>

#define DEVICEADDRESS1_WRITE 0x2F // 0x5C, 0x5E
#define DEVICEADDRESS1_READ 0x5E // 0x5D, 0x5F
#define DEVICEADDRESS2_WRITE 0x58
#define DEVICEADDRESS2_READ 0x59

#define INCREMENT_WIPER 0x04
#define DECREMENT_WIPER 0x08
#define WRITEVALUE 0x00
void setup(){
  Wire.begin();
  Serial.begin(9600);
  Test02();
  Serial.println("Test Started");
}

void loop(){
  byte value1 = 0x00;
  while(true){
    if(value1 > 0xF1) break;
    WriteValue(value1);
    value1 += 1;
    delay(1000);
  }
}

void WriteValue(byte valueIn){
  Wire.beginTransmission(DEVICEADDRESS1_WRITE);
  Wire.write(WRITEVALUE);
  Wire.write(valueIn);
  Wire.endTransmission();
}


void ScanAddress(){
  byte address1 = 0x11;

  while(true){
    address1 += 1;
    if(address1>0xF1) return;
    Serial.print("Address : ");
    Serial.println(address1, HEX);
  
    Wire.requestFrom(address1, 3);
  
    while(Wire.available()){
      char char1 = Wire.read();
      Serial.print(char1);
      Serial.print(", ");
    }
    Serial.println("-A");
    delay(100);  
    WriteValue(address1);
    delay(500);  
    
  }
}

void Test01(){
  Wire.requestFrom(DEVICEADDRESS1_READ, 3);

  while(Wire.available()){
    char char1 = Wire.read();
    Serial.print(char1);
    Serial.print(", ");
  }
  Serial.println("-A");
  delay(100);
  
  Wire.requestFrom(DEVICEADDRESS2_READ, 3);

  while(Wire.available()){
    char char1 = Wire.read();
    Serial.print(char1);
    Serial.print(", ");
  }
  Serial.println("-B");
  delay(500);

  Test02();  
  delay(500);

}

void IncreaseWiper(byte addressIn){
  Wire.beginTransmission(addressIn);
  Wire.write(INCREMENT_WIPER);
  Wire.endTransmission();  
}

void DecreaseWiper(byte addressIn){
  Wire.beginTransmission(addressIn);
  Wire.write(DECREMENT_WIPER);
  Wire.endTransmission();  
}

void Test02(){
  Wire.beginTransmission(DEVICEADDRESS1_WRITE);
  Wire.write(INCREMENT_WIPER);
  Wire.endTransmission();
  
  Wire.beginTransmission(DEVICEADDRESS2_WRITE);
  Wire.write(DECREMENT_WIPER);
  Wire.endTransmission();
}

 

[Test Curcuit - Schematic]

반응형

'SWDesk > Firmware' 카테고리의 다른 글

아두이노 나노 ESP32 - GET Request 예제  (0) 2023.12.27
SK6812 + Arduino-UNO  (0) 2022.09.15
아두이노 SMS 전송  (0) 2022.05.19
Control Code for 7-Segment  (0) 2022.02.25
ESP8266 APmode 테스트  (1) 2022.02.12