Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Raspberry PI OLED Display with HiPi

by jmlynesjr (Deacon)
on Aug 23, 2020 at 14:58 UTC ( [id://11121007]=CUFP: print w/replies, xml ) Need Help??

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...

Replies are listed 'Best First'.
Re: Raspberry PI OLED Display with HiPi
by stevieb (Canon) on Aug 25, 2020 at 22:51 UTC

    Based on an Adafruit library, known working OLED Perl code: OLED Perl.

    Use at your discretion. Screen refresh is slow, but it works.

      Thanks for the information Steve. That distribution requires WiringPi which I have moved on from. HiPi MonoOLED has a more complete function set IMHO.

      James

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

        Thank you.

        My work is now done in the RPi arena.

Re: Raspberry PI OLED Display with HiPi
by Anonymous Monk on Aug 24, 2020 at 09:35 UTC
    Please imgur some pics, thank you

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://11121007]
Approved by marto
Front-paged by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (1)
As of 2024-04-19 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found