Introduction: I2C OLED

This Instructable focuses on the I2C, 0.96 inch,128 x 64, OLED (organic light-emitting crystal rectifier).

This display often looks better to the eye than it does in a photograph, which often introduces artifacts that are not present during visual testing.

At that place are many types and sizes of OLEDs suitable for manufacturer projects, e.g., 128×32, 96 X 16, 64 X 48, 64 x 32, 16 x 2, etc., many larger sizes than here, all requiring unique sketches. However, Hera to make it easier and to a greater extent specific, we will concentrate on the, relatively wee, 4-pin, I2C, 0.96 edge in 128 x 64 OLED.

The I2C interface is slower than an SPI interface, but only requires cardinal pins in addition to power. These pins fundament be shared with another items.

So, although at that place are fewer connections overall, the I2C port is broadly not as fast arsenic the SPI interface. Yet, I personally prefer I2C Eastern Samoa the connections are a bit easier to make.

As opposed to the LCD character displays, e.g., the 1602 and 2004 (check my Instructable (I2C Liquid crystal display), which are relatively slowly to use, the OLED is a tur more thickening, but all pixels in the relatively small 0.96 inch, 128 x 64 display ill-used here are fully addressable, so this display has true graphics and can display not only text, but circles, squares, triangles etc. on its full screen without difficulty.

Here we mount totally items happening optional experimental platforms, to make the experiments in the allow Steps easier to move as single units.

If after reading this Instructable you ground it helpful, please be kind enough to mouse click "Favorited" at the top of this teacher.

Supplies

- an Arduino UNO, or compatible clone

- a 0.96 in I2C 128 x 64 OLED

- Some virile to male Dupont wires

- a DHT22 temperature and humidity sensor

- an optional experimental political platform

Step 1: Preparing the Observational Platform

The experimental platform comes in a vinyl group grip containing a 120mm x 83mm Plexiglas rag, and a small plastic base containing 5 screws, 5 plastic standoffs (spacers), 5 nuts. less frequently nonpareil finds experimental platforms with sole quartet (4) screws, washers, and nuts, both styles of experimental platform contain a sheet with quadruplet bumpers, i.e., soul-adhesive feet.

The research platform with only four (4) screws, washers , and nuts typically has smaller constructive soul-adhesive feet. The screw heads on these foursome (4) screws may occasionally fall flat the climbing holes on few clones. Thus, the five (5) screw package is recommended.

Completely four fictile bumpersfeet, on either style experimental platform, will glucinium needed, Eastern Samoa will four each of the other items. The data-based platform with five (5) screws. washers, and nuts has an extra screw, standoff, and testicle that are not required to add a UNO to the platform..

Even so, the bags of either style experimental platform do not take instruction manual.

Initially the external vinyl bag is cut available to take the Plexiglass sheet and the smaller bag.

The Plexiglas sheet is covered happening both sides with paper to protect it in handling and transportation system.

The opening is to peel the paper hindmost on apiece side of the platform and remove the two sheets. Once the paper is abstracted from for each one pull, the four holes for mounting the Arduino to the platform are easily seen. It is easiest if afterwards peeling the paper away, the acrylic sheet should is placed with the four holes on the right and the holes closest together and near one edge of the acrylic board, toward you (as can be seen in the attached picture).

I used the experimental program with five screws, washers, and nuts in this Instructable.

Ill-trea 2: Mounting the Arduino UNO or Dead ringer to the Empirical Platform

The Arduino UNO R3 boards, and their clones, have four mounting holes.

The transparent spacers, in the experimental platform package, are set between the undersurface of a UNO R3, OR its clones, and the upper berth incline of the acrylic board.

When working on my first observational circuit card I made the mistake of presumptuous that the spacers were washers that should be placed underneath the Plexiglas board to hold the wacky in place - they should not. The spacers are positioned underneath the Arduino UNO board, or ringer, around the screws later the screws pass through the UNO's, or dead ringer's, climbing holes. After passing direct the board the screws transit the spacers and and so done the holes in the acrylic Plexiglass board.

The screws are terminated by the dotty enclosed in the small package. The screws and nuts should be tightened to insure that the Arduino leave not move when in manipulation.

I saved it easiest to start with the hole nearest the reset button (see photos) and work my way clockwise around the Arduino. The UNO is pledged to the board, as might be expected, using one screw at a time. You will need a small Phillips maneuver screwdriver to turn away the screws. I found a socket to hold the nuts was quite a subservient, although not necessary.

I used drivers made past Wiha and available on Amazon (a Wiha (261) PHO x 50 and a Wiha (265) 4.0 x 60).

However, any small Phillips head up screwdriver should work without problem, and as noted previously, a nut driver is not really required (although it makes mountings quicker and easier, and typically more procure).

Stone's throw 3: Experiment-1 Arduino and OLED Displaying Text

The front two photographs show the hardware configuration for this and the next Step

For our prototypical sketch we will display three short lines of simple text.

Here we turn the display to portrait mode.

The first ii lines, shown below, should always be added to our text sketches.

The lines below ensure that we have added the appropriate library for our cartoon, i.e. U8g2lib.h and that we own the appropriate constructor.

#include U8g2lib.h // U8g2lib.h should exist enclosed in less than and great than brackets
// Unfortunately, this site removes less than and greater than brackets and the text betwixt them in // sketches

U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R1, SCL, SDA, U8X8_PIN_NONE);

The U8g2 library is a replacement, and supersedes, the first effort at a graphics library, U 8g (universal 8-bit graphics), developed by Oli Kraus, and now maintained by Arnim Läuger.

If using the same OLED as in this experiment, and the u8g2 library, the #include pre-processor directing and the constructor lines shown above should some be used in your sketch,

The SSD1306, to a higher place, tells use we should use this with SSD1306 OLED drivers, which is what comes with the OLED exploited here. The 128X64 identifies the size of the expose in pixels. The NONAME_F_SW_I2C identifies that we are using an I2C display.

U8X8_PIN_NONE identifies that we are not using a reset pin.

Hera we use a function from the included program library that allows us to presentation string section. Other functions give the sack be found at

https://github.com/olikraus/u8g2/wiki/u8g2referen...

At length, in our Sketch, we write u8g2 . sendBuffer(); which displays the items on the OLED riddle.

/* Arduino and OLED Displaying Textual matter

* Software engineer: R. Jordan Kreindler

* Created: November 6, 2022

*/

#include U8g2lib.h // U8g2lib.h should be penned in less than and great than brackets

// Unluckily, this site removes to a lesser degree and greater than brackets and the text betwixt them in

// sketches

U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R1, SCL, SDA, U8X8_PIN_NONE);

/*

U8G2_R0 No more revolution, landscape

U8G2_R1 90 degree dextrorotary rotary motion // Moves USA to portrait mode

U8G2_R2 180 degree clockwise rotation

U8G2_R3 270 degree clockwise rotation

*/

void setup() {

u8g2.begin();

u8g2.setFont(u8g2_font_ncenR18_tf ); // Font size 18

u8g2.drawStr(17, 40, "Test"); // Display firmness of purpose is 64 x 128

u8g2.drawStr(20, 80, " L2 ");

u8g2.drawStr(20, 120," L3 ");

u8g2.sendBuffer();

}

vacancy loop()

Step 4: Experiment-2 Arduino and OLED Displaying Filled Circle(Disc) and Triangle

Hither we again use portrait mode. However, since we are drawing a circle and triangle, there is non need to select a font.

Note: The deuce functions used Hera are

8g2.drawDisc() and

u8g2.drawTriangle().

As declared previously these functions, and whol references, can be found at

https://github.com/olikraus/u8g2/wiki/u8g2referen...

In the pledged photographs, the circle and triangle are shown separately too equally combined, as in our sketch.

In that respect appears to equal an unfortunate fundamental interaction between the tv camera shutter and the display, as when seen in the video the circle and triangle come out to be partially obscured at assorted moments in their display. Still, when viewed flat, with the eyes, as seen in the last still snap, this image appear steady and without any issue.

/* Arduino and OLED, Filled Circle/Disc and Filled Trigon

* Programmer: R.Jordan Kreindler

* Created: November 8, 2022

*/

#let in U8g2lib.h // U8g2lib.h should follow enclosed in less than and greater than brackets

// Unfortunately, this site removes less than and greater than brackets and the schoolbook betwixt them in
// sketches

U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R1, SCL, SDA, U8X8_PIN_NONE);

/*

U8G2_R0 No rotation, landscape

U8G2_R1 90 degree clockwise rotation

U8G2_R2 180 degree dextrorotation

U8G2_R3 270 level dextral rotation

*/

void frame-up() {

u8g2.begin();

u8g2.drawDisc(40, 20, 20, U8G2_DRAW_ALL);

u8g2.drawTriangle(40, 20, 50, 100, 30, 100);

u8g2.sendBuffer();

}

void loop()

{ }

Step 5: Experimentation-3 Humidity and Temperature and Displayed on OLED

Insert the four pins of the DHT22 into the half-sizing breadboard, on the enquiry platform, thereby mounting the sensor on the breadboard.

The DHT22 has four pins. I numbered these pins 1 to 4 as shown in the included photograph.

The superpowe to the sensor is provided via pins 1 and 4. Specifically, pin 1 provides the +5v power, and pin 4 is used for ground.

Personal identification number 3 is non used, and pin 2 is used to provide the output from the sensor.

Touch base the three pins that are in use on the DHT22, and thus the Arduino UNO as follows: 1) Immobilize 1 of the sensor goes to the UNO's 5v power socket, 2) Tholepin 4 of the detector goes to one of the UNO's GND connectors, 3) Pin 2 of the sensor, the information output pin, goes to digital socket 3, i.e., D3 connected the UNO, no linear connectors are required.

Banknote: the DHT22 sensor can only provide updated information every 2 seconds. Thus, if you pole the sensor more than once every ii seconds you may get results that are non current. You can add together the line delay(2000); in the study below if results that are not current is an issue for you. Eastern Samoa information technology is for Maine.

The DHT22 sensor provides Centigrade temperature values which can constitute easily converted to Fahrenheit.

The formula for this conversion is Fahrenheit Temperature = Centigrade Temperature * 9 / 5 + 32.

Hither we use the OLED display in the landscape mode.

The OLED, used in this Maltreat, is the two color type, yellow-blue, with the toplines of pixels being yellow as shown.

The display looks better to the eyes than IT does in the photographs. Looking at the Organic light-emitting diode directly there are No artifacts/problems.

Since the Instructable.com internet site removes less than and greater than brackets, and the text in between them, in sketches, I have attached a document with the befitting sketch. Sadly, spaces between quotes are also removed by this site

The third (3rd) still photograph shows the DHT22 connected to the breadboard, while the fourthly (4th) and fifth part (5th) still pic show the final conformation with some the DHT22 and OLED on the bread board.

In the one-seventh (7th) and eighth (8th) still photographs, to a greater extent happening the one-eighth (8th) on a lower floor, the font is set to a height of 18 pixels victimisation u8g2_font_luRS18_te. This typeface prat be substituted for u8g2_font_luRS14_te, in the cartoon at a lower place, by any user who would like a larger font. and does not mind the output beingness passably "scrunched" together

In the eighth (8th) even photograph, the relative humidity display is indented to the right, while, at the same time information technology is set to the little 10 pixel font, and the Temperature scale and Fahrenheit temperature displays are set to the larger 18 pixel font.

In the last still photograph the temperatures, both Temperature scale and Fahrenheit, are initially located to floats, rather than ints,and thus we display decimal values.

The lines,

u8g2.drawStr(30, 41, " "); and

u8g2.drawStr(30, 62, " ");

are included, in the Sketch, to avoid any artifacts appearing as the C and F temperatures change. Even so, As noted in a higher place, additive spaces between quotes are removed by this site. So, you may want to see the intended text filing cabinet.

The two (2) back hold up enforced in our code past time lag(2000); is appropriate for the DHT22.

To see the Sketch associated with the last, "squished" reveal, download the last text edition file.

/*

Sketch to display humidity and temperature

Written past R. Jordan Kreindler, J

Sketch: November 27,2022

Uses a 0.96 edge OLED to display Humidity, as fountainhead as Fahrenheit and Centigrade

room Temperatures.

The DHT22 sensor provides Centigrade temperature values which can be easy converted to Fahrenheit.

*/

#include

// U8g2lib.h should be enclosed in to a lesser degree and greater than brackets after #include

// Regrettably, this site removes little than and greater than brackets and the text 'tween them in // sketches

U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, SCL, SDA, U8X8_PIN_NONE);

/*

U8G2_R0 No rotation, landscape

U8G2_R1 90 degree dextrorotation // Moves US to portrayal

U8G2_R2 180 arcdegree dextrorotation

U8G2_R3 270 degree clockwise rotation

*/

#include

// DHT.h should atomic number 4 enclosed in to a lesser degree and greater than brackets after #include

// Unfortunately, this web site removes less than and greater than brackets and the text betwixt them in

// sketches

#define DHTData 3 // The information pin from the DHT22 is member PIN number 3

DHT dht(DHTData, DHT22);// Define a DHT object, dht

int humidity = 0; // Holds humidity results as an integer

float cTemp = 0.0; // Holds Centigrade temperature results as an integer

//drift centigradeTemp = 0; // The Centigrade temperature

plasterer's float fTemp = 0; // Will hold the measured Fahenheit temperature

int delay1 = 4000; // The time between text displays

void frame-up() {

u8g2.begin();

dht.begin(); //Startle the DHT22 sensor

}

void loop-the-loop()

{

u8g2.setFont(u8g2_font_profont22_tf); // Set Font

u8g2.drawStr(32, 18, "RH:"); // Display answer is 128 x 64

humidness = round(dht.readHumidity());

u8g2.setCursor(70, 18);

u8g2.print(humidity);

u8g2.setFont(u8g2_font_luRS18_te); // Unmoving Font

u8g2.drawStr(02, 41, "C:");

u8g2.setCursor(30,41);

cTemp = dht.readTemperature();

u8g2.print(cTemp);

u8g2.drawStr(30, 41, " "); // Note: Spaces Betwixt The Quotes are Removed By This Site

u8g2.drawStr(02, 62 , "F:");

fTemp = cTemp * 9.0 / 5.0 + 32.0;

u8g2.setCursor(30,62);

u8g2.print(fTemp);

delay(2000);

u8g2.drawStr(30, 62, " ") ; // Note: Spaces Between The Quotes are Removed By This Site

u8g2.sendBuffer();

}

Whole step 6: Afterwards

If you have come to this point - congratulations.

You should now have a basal understanding of some of the capabilities of the relatively lowercase I2C, 0.96 inch, 128 x 64 OLED display covered in this tutorial., in both portrait and landscape modes.

I hope you found this Instructable engrossing and useful.

If you have some comments, suggestions, or questions related to this tutorial, please equal hospitable enough to add your comments downstairs, if there are any or start this section.

If you have any thoughts Oregon questions paternal to the 0.96 inch OLED not covered in this instructor, or any suggestions on how I could improve this Instructable, I would be pleased to hear from you.

You can reach Pine Tree State at transiintbox@gmail.com. (Delight replace the second 'i' with an 'e' to contact me).

1 Person Made This Project!

Recommendations

  • Anything Goes Contend 2022

    Anything Goes Contest 2022