Below is an example of using the Adafruit 0.96" mono OLED display v2.1 on a Raspberry PI 3B+ with the HiPi distribution. Adafruit's newest version doesn't require a reset pin and includes the SparkFun qwiic I2C bus connectors.

This example is based on the MonoOLED example from the distribution with several modifications. From the Adafruit library source code comments, it was determined that the 128x64 I2C version requires an I2C address of 0x3D rather than the default of 0x3C. Four update_display() calls were added to write the internal buffer to the display.

After much searching, I found that Pololu is a good source of the RPi 20x2 connector shells. They also have pre-crimped jumpers and crimp pins. The jumpers and pins also fit into "Dupont" style shells.

#! /usr/bin/perl # hipioled.pl - Test of 0.96" 128x64 Pixel OLED Display with I2C Inter +face, # using the HiPi Raspberry Pi Perl Library # https://raspberry.znix.com/ # # James M. Lynes, Jr. - KE4MIQ # Created: June 27, 2020 # Last Modified: 06/27/2020 - Initial test version # 08/22/2020 - Changed I2C address to 0x3D for 128x64 d +isplay # per comment in Adafruit library sour +ce # - Added update_display() calls 4 places # to copy buffer to the display # 08/23/2020 - Removed several unneeded statements # # Target: Raspberry Pi 3B+ with Adafruit 0.96" OLED BOB # # Notes: Code based on HiPi documentation example # from HiPi::Interface::MonoOLED # Adafruit 0.96" OLED BOB v2.1(must jumper I2C pads on +the # back side of the BOB). New version doesn't requir +e # the reset pin and has SparkFun qwiic I2C bus conn +ectors # # RPI J8 - GPIO Pin Definitions si5351 BOB Pin Definitions +(I2C) # ----------------------------- -------------------------- +----- # [RED] 3V3 (1) (2) 5V (1) CLK0 - SMA # [YEL] SDA/GPIO2 (3) (4) 5V (2) CLK1 - SMA # [BLU] SCL/GPIO3 (5) (6) GND (3) CLK2 - NC # GPIO4 (7) (8) GPIO14 (4) SCL - [BLU] # GND (9) (10) GPIO15 (5) SDA - [YEL] # PB1/GPIO17 (11) (12) GPIO18 (6) GND - [BLK] # PB2/GPIO27 (13) (14) GND [BLK] (7) VIN - [RED] # ENCA/GPIO22 (15) (16) GPIO23 # 3V3 (17) (18) GPIO24 # ENCB/GPIO10 (19) (20) GND 0.96" OLED Pin Definitions +(I2C) # RED/ GPIO9 (21) (22) GPIO25 -------------------------- +----- # YEL/GPIO11 (23) (24) GPIO8 (1) SDA - [YEL] # GND (25) (26) GPIO7 (2) SCL - [BLU] # *GPIO0 (27) (28) GPIO1* (3) DC/A0 - NC # GRN/ GPIO5 (29) (30) GND (4) RST - [YEL] +GPIO21 # GPIO6 (31) (32) GPIO12 (5) CS - NC # GPIO13 (33) (34) GND (6) 3V3 - NC # GPIO19 (35) (36) GPIO16 (7) Vin - [RED] # GPIO26 (37) (38) GPIO20 (8) GND - [BLK] # GND (39) (40) GPIO21 [YEL] # * GPIO0 & GPIO1 are reserved use strict; use warnings; use HiPi qw( :oled :rpi); use HiPi::Interface::MonoOLED; $SIG{INT} = \&trapcc; # Trap CTRL-C Signal my $oled = HiPi::Interface::MonoOLED->new( # Create OLED Object type => SSD1306_128_X_64_I2C, # Use I2C interface address => 0x3D, # Addr for 128x64 I2C +BOB reset_pin => 21, # GPIO21 # flipped => 1, # Flip screen top to b +ottom # skip_logo => 1, # Don't display splash + screen # skip_reset => 1, # Don't reset the disp +lay ); sleep(2); # Display splash for 2 + sec $oled->display_reset(); # Clear buffer/reset d +isplay my $dc = $oled->create_context; my($w, $h) = $dc->draw_text(0, 0, 'Raspberry Pi', 'Sans14'); my $cx = int(0.5 + $w/2); # Center text string my $cy = int(0.5 + $h/2); # Draw top line centered { my $x = int(0.5 + ($oled->cols - $w) / 2); my $y = 0; $oled->draw_context($x, $y, $dc->rotated_context(0, 0, 0)); $oled->display_update(); # Copy buffer to displ +ay } # Draw bottom line rotated through 180 about its center($cx & $cy) { my $x = int(0.5 + ($oled->cols - $w) / 2); my $y = $oled->rows - $h - 1; $oled->draw_context($x, $y, $dc->rotated_context(180, $cx, $cy)); $oled->display_update(); # Copy buffer to displ +ay } $dc->clear_context; ($w, $h) = $dc->draw_text(0, 0, 'Perl', 'Sans14'); # Perl right { my $x = $oled->cols - 1; my $y = int(0.5 + ($oled->rows - $w) / 2); $oled->draw_context($x, $y, $dc->rotated_context(90, 0, 0)); $oled->display_update(); # Copy buffer to displ +ay } # Perl left { my $x = 0; my $y = int(0.5 + ($w + $oled->rows) / 2); $oled->draw_context($x, $y, $dc->rotated_context(-90, 0, 0)); $oled->display_update(); # Copy buffer to displ +ay } sub trapcc{ die "Terminated by CTRL-C Signal\n\n"; # Kill the script }

James

There's never enough time to do it right, but always enough time to do it over...


In reply to Raspberry PI OLED Display with HiPi by jmlynesjr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.