#! /usr/bin/perl # hipidisp.pl - RADIG II Display using the 0.96" 128x64 Pixel OLED # Display with I2C Interface, and the HiPi # Raspberry Pi Perl Library # # James M. Lynes, Jr. - KE4MIQ # Created: August 24, 2020 # Last Modified: 08/24/2020 - Initial test version # 08/25/2020 - Test updating the frequency string # display an incrementing frequency # # Target: Raspberry Pi 3B+ with Adafruit 0.96" OLED BOB # # Notes: 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 # The RADIG II is a Software Defined Radio(SDR) designed by # Pete Juliano, N6QW.blogspot.com, N6QWradiogenius.us # HiPi documentation is at https://raspberry.znix.com/ # # # 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 ); my $freq = 7030020; # Testing frequency my $freqstr = freqfmt($freq); # Freq as a string sleep(2); # Display splash for 2 sec $oled->display_reset(); # Clear buffer/reset display my $dc = $oled->create_context; # Create a drawing context # # Draw the static part of the screen # # Draw a box around the screen $dc->draw_rectangle(0, 0, 127, 63); $oled->draw_context(0, 0, $dc); $dc->clear_context(); # Draw title line centered my($w, $h) = $dc->draw_text(0, 0, 'RADIG II SDR', 'Sans14'); my $x = int(0.5 + ($oled->cols - $w) / 2); my $y = 5; $oled->draw_context($x, $y, $dc); $dc->clear_context(); # Draw initial frequency string $dc->draw_text(0, 0, $freqstr, 'Sans20'); $oled->draw_context(15, 25, $dc); $dc->clear_context(); # Draw Callsign string $dc->draw_text(0, 0, 'KE4MIQ', 'Sans12'); $oled->draw_context(75, 45, $dc); $dc->clear_context(); $oled->display_update(); sleep(2); # # Draw an incrementing frequency # while(1) { # Erase frequency string by rewriting same string inverted $dc->invert_pen(1); $dc->draw_text(0, 0, $freqstr, 'Sans20'); $dc->invert_pen(0); $oled->draw_context(15, 25, $dc); $dc->clear_context(); # Draw the updated frequency string $freq = $freq + 10; $freqstr = freqfmt($freq); $dc->draw_text(0, 0, $freqstr, 'Sans20'); $oled->draw_context(15, 25, $dc); $dc->clear_context(); $oled->display_update(); } # --------------------------------------------------------------------- # # trapcc - Trap CTRL-C for an orderly shutdown # sub trapcc{ die "Terminated by CTRL-C Signal\n\n"; # Kill the script } # # freqfmt - Format a frequency in Mhz into a display string # ##.###.### # sub freqfmt { my ($freq) = @_; my $hzstr = substr($freq, -3, 3); my $khzstr = substr($freq, -6, 3); my $mhzstr = substr($freq, -8, 2); if($freq < 10000000) {$mhzstr = substr($freq, -7, 1)}; my $freqstr = sprintf "%2d.%03d.%03d", $mhzstr, $khzstr, $hzstr; return $freqstr; }