As a supplier of 192x64 COG LCDs, I've received numerous inquiries about creating bar graphs on these displays. In this blog, I'll share a comprehensive guide on how to make a 192x64 COG LCD display bar graphs, covering everything from understanding the basics to implementing the actual code.
Understanding the 192x64 COG LCD
Before diving into creating bar graphs, it's essential to understand the characteristics of the 192x64 COG LCD. The "192x64" refers to the display's resolution, meaning it has 192 pixels horizontally and 64 pixels vertically. The "COG" stands for Chip On Glass, which is a technology where the integrated circuit is directly mounted on the glass substrate of the LCD. This results in a more compact and reliable display.
Compared to other LCDs like the 12864B lcd and 122x32 graphic lcd, the 192x64 COG LCD offers a larger display area, allowing for more detailed and complex visualizations, such as bar graphs.
Prerequisites
To create bar graphs on a 192x64 COG LCD, you'll need the following:
- 192x64 COG LCD: You can source this from a reliable supplier like us. Check out our 192x64 LCD for more details.
- Microcontroller: A microcontroller is used to control the LCD and generate the bar graph data. Popular choices include Arduino, Raspberry Pi, and STM32.
- Programming Language: You'll need to know a programming language compatible with your microcontroller, such as C, C++, or Python.
- LCD Driver Library: Most microcontrollers have libraries available for controlling LCDs. These libraries simplify the process of communicating with the LCD and performing basic operations like clearing the screen, writing text, and drawing shapes.
Step 1: Connect the LCD to the Microcontroller
The first step is to connect the 192x64 COG LCD to your microcontroller. The exact pin connections will depend on the specific LCD and microcontroller you're using. However, most LCDs require the following connections:
- Power Supply: Connect the LCD's VCC and GND pins to the appropriate power supply pins on the microcontroller.
- Data Lines: Connect the LCD's data lines (usually labeled D0 - D7) to the corresponding data pins on the microcontroller.
- Control Lines: Connect the LCD's control lines (such as RS, RW, and E) to the appropriate control pins on the microcontroller.
Once the connections are made, double-check them to ensure they're correct. Incorrect connections can lead to issues such as the LCD not displaying anything or displaying garbled characters.


Step 2: Initialize the LCD
After connecting the LCD to the microcontroller, you need to initialize the LCD using the LCD driver library. Initialization typically involves setting the display mode, clearing the screen, and configuring other display parameters.
Here's an example of how to initialize a 192x64 COG LCD using the Arduino IDE and the U8g2 library:
#include <U8g2lib.h>
// Create an instance of the U8g2 library for the 192x64 COG LCD
U8g2_SSD1306_192X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);
void setup() {
// Initialize the LCD
u8g2.begin();
// Clear the screen
u8g2.clearBuffer();
// Update the display
u8g2.sendBuffer();
}
void loop() {
// Your main code goes here
}
In this example, we're using the U8g2 library to control the 192x64 COG LCD. The U8g2_SSD1306_192X64_NONAME_F_SW_I2C constructor creates an instance of the library for the specific LCD model. The begin() function initializes the LCD, and the clearBuffer() and sendBuffer() functions clear the screen and update the display, respectively.
Step 3: Define the Bar Graph Data
Before drawing the bar graph on the LCD, you need to define the data that will be represented by the bars. This data can be obtained from various sources, such as sensors, databases, or user input.
For simplicity, let's assume we have an array of integers representing the values of the bars:
const int numBars = 5;
int barValues[numBars] = {20, 40, 60, 80, 100};
In this example, we have an array of 5 integers representing the values of 5 bars.
Step 4: Draw the Bar Graph
Once you have the bar graph data, you can start drawing the bars on the LCD. To draw a bar, you need to calculate the position and size of the bar based on the value it represents and the available display area.
Here's an example of how to draw a bar graph on a 192x64 COG LCD using the U8g2 library:
#include <U8g2lib.h>
// Create an instance of the U8g2 library for the 192x64 COG LCD
U8g2_SSD1306_192X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);
const int numBars = 5;
int barValues[numBars] = {20, 40, 60, 80, 100};
void setup() {
// Initialize the LCD
u8g2.begin();
}
void loop() {
// Clear the screen
u8g2.clearBuffer();
// Calculate the width of each bar
int barWidth = u8g2.getWidth() / numBars;
// Draw each bar
for (int i = 0; i < numBars; i++) {
int barHeight = (barValues[i] * u8g2.getHeight()) / 100;
int x = i * barWidth;
int y = u8g2.getHeight() - barHeight;
u8g2.drawBox(x, y, barWidth, barHeight);
}
// Update the display
u8g2.sendBuffer();
// Delay for a short period
delay(1000);
}
In this example, we first calculate the width of each bar based on the number of bars and the width of the LCD. Then, we loop through each bar and calculate its height based on its value and the height of the LCD. Finally, we use the drawBox() function to draw the bar on the LCD.
Step 5: Customize the Bar Graph
Once you have the basic bar graph working, you can customize it to make it more visually appealing and informative. Here are some ways to customize the bar graph:
- Add Labels: You can add labels to the bars to indicate their values or names. To add labels, you can use the
drawStr()function provided by the LCD driver library. - Change Colors: Most LCD driver libraries allow you to change the color of the bars and other elements of the display. You can use different colors to distinguish between different bars or to highlight important information.
- Animate the Bars: You can animate the bars to make the bar graph more dynamic. To animate the bars, you can update the bar values in the
loop()function and redraw the bar graph at regular intervals.
Conclusion
Creating bar graphs on a 192x64 COG LCD is a relatively straightforward process that involves connecting the LCD to a microcontroller, initializing the LCD, defining the bar graph data, drawing the bars on the LCD, and customizing the bar graph. By following the steps outlined in this blog, you should be able to create your own bar graphs on a 192x64 COG LCD.
If you're interested in purchasing a 192x64 COG LCD or have any questions about creating bar graphs on these displays, please feel free to contact us for more information and to discuss your specific requirements. We're here to help you find the best solution for your needs.
References
- U8g2 Library Documentation
- Arduino IDE Documentation
- LCD Data Sheets
