Search Code

የ Arduino ኮድ እና ቪዲዮ ለ SSD1306 OLED 128 x 32 ማሳያ ከ I2C ጋር

የ Arduino ኮድ እና ቪዲዮ ለ SSD1306 OLED 128 x 32 ማሳያ ከ I2C ጋር

በዚህ መማሪያ ውስጥ፣ በአርዱኖ (Arduino) ላይ ከI2C ግንኙነት ጋር የSSD1306 OLED 128 x 32 ማሳያን እንዴት መጠቀም እንደሚቻል እንመረምራለን። ግቡ እንደ ጽሑፍ፣ አራት ማዕዘኖች እና እንደ ቮልቴጅ እና የሙቀት መጠን ያሉ ተለዋዋጭ እሴቶችን በማያ ገጹ ላይ ማሳየት ነው። ይህ ዝግጅት የታመቀ እና ቀልጣፋ የማሳያ መፍትሄ ለሚፈልጉ ፕሮጀክቶች ተስማሚ ነው።

SSD1306 OLED 128x32

ሁሉንም ነገር ለማስኬድ አስፈላጊ የሆኑትን የሃርድዌር ክፍሎች፣ የሽቦ መገጣጠሚያ መመሪያዎች እና የአርዱኖ ኮድ እንመለከታለን። ለእይታ መመሪያ፣ ከዚህ መማሪያ ጋር አብሮ የሚሄደውን ቪዲዮ መመልከትዎን ያረጋግጡ (በቪዲዮው በ00:00)።

ሃርድዌር ተብራርቷል

ለዚህ ፕሮጀክት ቁልፍ ክፍሎች የSSD1306 OLED ማሳያን ያካትታሉ፣ ይህም ለቀላል ግንኙነት I2C ኮሙኒኬሽን የሚጠቀም አነስተኛ ኃይል የሚፈጅ ማሳያ ነው። ማሳያው የ128 x 32 ፒክስል ጥራት ያለው ሲሆን፣ ጽሑፍን እና ቀላል ግራፊክስን ለማሳየት ተስማሚ ያደርገዋል።

ማሳያውን ለመቆጣጠር፣ ትዕዛዞችን እና ውሂብን በI2C የሚልክ የአርዱኖ ቦርድ እንጠቀማለን። አርዱኖ እንደ Adafruit_GFX እና Adafruit_SSD1306 ያሉ ቤተ-መጻሕፍትን በመጠቀም መረጃን የማሳየት አመክንዮ ይይዛል። እነዚህ ቤተ-መጻሕፍት የግንኙነት ሂደቱን ያቃልላሉ እና ቅርጾችን እና ጽሑፎችን በቀላሉ ለመሳል ያስችላሉ።

የዳታሼት ዝርዝሮች

አምራችAdafruit
የክፍል ቁጥርSSD1306
የሎጂክ/IO ቮልቴጅ3.3 - 5 ቮ
የአቅርቦት ቮልቴጅ3.3 - 5 ቮ
የአሁኑ ፍጆታ~20 mA (በተለምዶ)
የማሳያ ጥራት128 x 32 ፒክስሎች
በይነገጽI2C
ልኬቶች128 x 32 ሚሜ
ማስታወሻዎች / ልዩነቶችበተለያዩ መጠኖች እና በይነገጾች ይገኛል
  • የI2C አድራሻን ያረጋግጡ፣ በተለምዶ ለOLEDዎች 0x3C ነው።
  • ጉዳትን ለማስቀረት ትክክለኛ የኃይል አቅርቦትን ያረጋግጡ።
  • አስፈላጊ ከሆነ ለSDA እና SCL መስመሮች የመጎተቻ ተቃዋሚዎችን (pull-up resistors) ይጠቀሙ።
  • በI2C ምልክት ውስጥ ጫጫታን ለመቀነስ ሽቦዎችን አጭር ያድርጉ።
  • ብዙ ሞጁሎችን ኃይል የሚሰጡ ከሆነ የሙቀት መበታተንን ግምት ውስጥ ያስገቡ።

የሽቦ መገጣጠሚያ መመሪያዎች

Arduino wiring for SSD1306 OLED 128x32
Arduino wiring for SSD1306 OLED 128x32

የSSD1306 OLED ማሳያን ለማገናኘት፣ በመጀመሪያ የማሳያውን VCC ፒን በአርዱኖ ላይ ካለው የ5V ውፅዓት ጋር ያገናኙ። በመቀጠል፣ የGND ፒንን ከአርዱኖው የመሬት (ground) ፒኖች አንዱ ጋር ያገናኙ። ለI2C ኮሙኒኬሽን፣ የማሳያውን SDA ፒን በአርዱኖ ላይ ካለው SDA ፒን ጋር ያገናኙ፣ ይህም ለUNO A4 ነው። ከዚያ፣ የማሳያውን SCL ፒን በአርዱኖ ላይ ካለው SCL ፒን ጋር ያገናኙ፣ ይህም ለUNO A5 ነው። የተለየ የአርዱኖ ሞዴል እየተጠቀሙ ከሆነ፣ ለSDA እና SCL የተወሰነውን የፒን ካርታ ይመልከቱ።

ለተጨማሪ ክፍሎች፣ ለመቆጣጠር የሚፈልጉት LED ካለዎት፣ በ330-ohm ተቃዋሚ በኩል ከፒን 9 ጋር ያገናኙት። የተቃዋሚውን ሌላኛውን ጫፍ ከLED አኖድ (anode) ጋር ማገናኘትዎን ያረጋግጡ፣ ካቶድ (cathode) ደግሞ ወደ መሬት መሄድ አለበት። ይህ ዝግጅት ፒን 9 ሲነቃ LED እንዲበራ ያስችላል።

የኮድ ምሳሌዎች እና ጉዞ

በአርዱኖ ኮድ ውስጥ፣ ለOLED ማሳያ አስፈላጊ የሆኑትን ቤተ-መጻሕፍት በማካተት እንጀምራለን። ቁልፍ መለያ display ነው፣ እሱም የAdafruit_SSD1306 ክፍል ምሳሌ ነው። ማሳያው በsetup() ተግባር ውስጥ ይጀመራል፣ እንዲሁም ለመሳል ለማዘጋጀት ማሳያውን እናጸዳለን።

SSD1306 OLED 128x32
void setup() {
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
  delay(2000);
  display.clearDisplay(); 
}

loop() ተግባር ውስጥ፣ በተለዋዋጭ የሚዘመን የቮልቴጅ እሴትን ለመያዝ vString የተባለ የሕብረቁምፊ ተለዋዋጭ እንገልጻለን። robojaxText() ተግባር በተወሰኑ መጋጠሚያዎች ላይ ጽሑፍን በማያ ገጹ ላይ ለማሳየት ይጠቅማል።

void loop() {
  String vString = String(count, 3);
  display.clearDisplay();
  robojaxText("Voltage:          ", 4, 3, 1, false);
  robojaxText(vString, 72, 3, 1, false);
  display.display();
  count += 0.173;
  delay(2000); 
}

robojaxText() ተግባር ጽሑፍን ለማስቀመጥ እና ለማሳየት ወሳኝ ነው። ለጽሑፍ ሕብረቁምፊ፣ የx እና y መጋጠሚያዎች፣ የጽሑፍ መጠን እና ማሳያው ወዲያውኑ መዘመን እንዳለበት የሚወስን ቡሊያን (boolean) መለኪያዎችን ይወስዳል።

void robojaxText(String text, int x, int y, int size, boolean d) {
  display.setTextSize(size);
  display.setTextColor(WHITE);
  display.setCursor(x, y);
  display.println(text);
  if(d) {
    display.display();
  }
}

ይህ ተግባር ጽሑፉን ከማተም በፊት የጽሑፍ መጠንን፣ ቀለምን እና የጠቋሚ ቦታን ያዘጋጃል። ለተሟላ የኮድ ጉዞ ቪዲዮውን መመልከትዎን ያስታውሱ (በቪዲዮው በ10:00)።

ማሳያ / ምን እንደሚጠበቅ

ኮዱ ወደ አርዱኖ ሲጫን፣ የOLED ማሳያው ቮልቴጅን፣ የሙቀት መጠንን እና አቅምን እሴቶች በየሁለት ሰከንዱ በተለዋዋጭ ሁኔታ ሲዘምኑ ማሳየት አለበት። እንዲሁም በጽሑፍ ክፍሎች ዙሪያ የተሳለ አራት ማዕዘን ማየት አለብዎት። ማሳያው ምንም ካላሳየ፣ ግንኙነቶቹ ትክክል መሆናቸውን እና የI2C አድራሻው በኮዱ ውስጥ ከተገለጸው ጋር መዛመዱን ያረጋግጡ።

የቪዲዮ ጊዜ ምልክቶች

  • 00:00 - ለፕሮጀክቱ መግቢያ
  • 02:00 - የሽቦ መገጣጠሚያ መመሪያዎች
  • 05:00 - የኮድ ጉዞ
  • 10:00 - የውጤት ማሳያ

ምስሎች

SSD1306 OLED 128x32
SSD1306 OLED 128x32
SSD1306 OLED 128x32
SSD1306 OLED 128x32
SSD1306 OLED 128x32
SSD1306 OLED 128x32
SSD1306 OLED 128x32
SSD1306 OLED 128x32
Arduino wiring for SSD1306 OLED 128x32
Arduino wiring for SSD1306 OLED 128x32
83-Arduino code and video for SSD1306 OLED 128 x 32 display with I2C
ቋንቋ: C++
/*********************************************************************
This is an example for our monochrome OLEDs based on SSD1306 drivers.

This example is for a 128x32 size display using I2C.

If you get the error: Adafruit_GFX.h not found, download the Adafruit-GFX Library
https://github.com/adafruit/Adafruit-GFX-Library


Purchase this OLED module from Amazon: https://amzn.to/36zFvTb

Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information.
All text above, and the splash screen must be included in any redistribution.

 * Watch the video for this code to learn it fully.
  * Watch the video here: https://youtu.be/RjyulqVsz2o
 * This code is offered "as is" without any warranty.
 * Updated by Ahmad Shamshiri for Robojax.com video tutorial
 * on March 18, 2018 at 10:21 in Ajax, Ontario, Canada.
 * Please view other Robojax codes and videos at http://robojax.com/learn/arduino
 * If you are sharing this code, you must keep this copyright note.
 * 
*********************************************************************/

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

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
double count=0;

/*
 * PIN connection:
 * Pin connection see: https://www.arduino.cc/en/Reference/Wire
 * for UNO: SDA to A4, SCL to A5
 * for Mega2560: SDA to 20, SCL to 21
 * for Leonardo: SDA to 2, SCL to 3
 * for Due: SDA to 20, SCL to 21
 * VCC to 5V
 * GND to GND :-)
 */


// this is the Width and Height of Display which is 128 x 32
#define LOGO16_GLCD_HEIGHT 32
#define LOGO16_GLCD_WIDTH  128 


#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

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

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  display.display();
  delay(2000);
   // Clear the buffer.
  display.clearDisplay(); 
}


void loop() {
  String vString =  String(count, 3);// using a float and the 
  display.clearDisplay();
  robojaxText("Voltage:          ", 4, 3, 1, false);
  robojaxText(vString, 72, 3, 1, false);
  robojaxText("V", 110, 3, 1, false);
  robojaxText("Temperature: 32C", 4, 11, 1, false);
  robojaxText("Capacity:   92.86L", 4, 21, 1, false);
  //display.drawLine(1, 37, 100, 37, WHITE);
 display.drawRect(1, 1, 126,31, WHITE);
  //display.drawCircle(63,31, 31, WHITE);
   //display.startscrollright(0x00, 0x0F);
  display.display();
  count +=0.173;
   delay(2000); 
}


/*
 * robojaxText(String text, int x, int y,int size, boolean d)
 * text is the text string to be printed
 * x is the integer x position of text
 * y is the integer y position of text
 * size is the text size, 1, 2, 3 etc
 * d is either true or false.  If true, the display is updated.
 */
void robojaxText(String text, int x, int y,int size, boolean d) {

  display.setTextSize(size);
  display.setTextColor(WHITE);
  display.setCursor(x,y);
  display.println(text);
  if(d){
    display.display();
  }
  
  //delay(100);
}

እንደሚያስፈልግዎት ይችላል

ምንጮች እና ምንጮች

ፋይሎች📁

የዳታ ማዕከል (pdf)

  • SSD1306 display datasheet
    SSD1306 is a single-chip CMOS OLED/PLED driver with controller for organic / polymer light emitting diode dot-matrix graphic display system. It consists of 128 segments and 64commons. This IC is designed for Common Cathode type OLED panel. The SSD1306 embeds with contrast control, display RAM and oscillator, which reduces the number of external components and power consumption. It has 256-step brightness control. Data/Commands are sent from general MCU through the hardware selectable 6800/8000 series compatible Parallel Interface, I2C interface or Serial Peripheral Interface. It is suitable for many compact portable applications, such as mobile phone sub-display, MP3 player and calculator, etc.
    SSD1306_display_datasheet.pdf 1.79 MB

ፍሪትዚንግ ፋይል

  • SSD1306 128x32 OLED Wiring
    Fritzing wiring diagram for an SSD1306 128x32 OLED display, showing connections to a microcontroller (likely Arduino). Useful for breadboard prototyping and verifying I2C or SPI wiring.
    SSD1306_128x32_wiring.fzz

Wiring diagram

  • SSD1306 128x32 OLED Wiring
    Fritzing wiring diagram for an SSD1306 128x32 OLED display, showing connections to a microcontroller (likely Arduino). Useful for breadboard prototyping and verifying I2C or SPI wiring.
    SSD1306_128x32_wiring.fzz