AST 27 – I2C OLED Display 128×64

Spread the love

අද වීඩියෝ එකේ කියලා දෙන්නේ මේ පොඩි, හුරුබුහුටි, ලස්සනට data display කරන්න පුලුවන් OLED Display එක ගැන. මේකේ තියෙන්නේ අඟල් 0.96 ක display එකක්. ඒ වගේම pixel 128 x 64 මේ display එකේ තියනවා. මේ display එක arduino board එකත් එක්ක communicate කරන්නේ I2C Protocol එක හරහා. වැඩි විස්තර ඔක්කොම වීඩියෝ එකේ තියනවා. මේකෙදි ලිව්ව code එකත් පහළින් මම දාල තියන්නම්.

වීඩියෝ එකේ ලියපු code එක

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 Nisal = Adafruit_SSD1306(128,64,&Wire);

void setup() {

  Nisal.begin(SSD1306_SWITCHCAPVCC, 0x3C);
 
}

int x = 500;

void loop() {

  Nisal.clearDisplay();
  Nisal.setTextColor(WHITE);

  Nisal.setTextSize(2);
  Nisal.setCursor(0,0);
  Nisal.print("Nisal");
  
  Nisal.setTextSize(4);
  Nisal.setCursor(20,22);
  Nisal.print(x);
  delay(100);

  Nisal.display();

  Nisal.dim(true);
  delay(500);
  Nisal.dim(false);
  delay(500);

}

I2C Scanner Code එක

#include <Wire.h>
 
void setup()
{
  Wire.begin();
 
  Serial.begin(9600);
  while (!Serial);             
  Serial.println("\nI2C Scanner");
}
 
 
void loop()
{
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
 
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
 
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
 
  delay(5000);           
}


Spread the love