#! /usr/bin/perl # hipioled.pl - Test of 0.96" 128x64 Pixel OLED Display with I2C Interface, # 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 display # per comment in Adafruit library source # - 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 require # the reset pin and has SparkFun qwiic I2C bus connectors # # 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 bottom # skip_logo => 1, # Don't display splash screen # skip_reset => 1, # Don't reset the display ); sleep(2); # Display splash for 2 sec $oled->display_reset(); # Clear buffer/reset display 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 display } # 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 display } $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 display } # 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 display } sub trapcc{ die "Terminated by CTRL-C Signal\n\n"; # Kill the script }