S-0005
0.96 Inch OLED Module
Description
0.96 Inch OLED Module is a mini display screen with 128X64 resoluction and SSD1306 chipset.
Standard IIC communication interface pinout compatible with most MCU development board such as arduino, Raspberry Pi,C51 series etc.
The Python library to use SSD1306-based 128x64 or 128x32 pixel OLED displays with a Raspberry Pi or Beaglebone Black too.
Features
- Easy to setup
- Super Low Power Consumption
- Power Input: 3.3V
- Good compatibility: Raspberry Pi 4B/3B+/3B/2B/Zero, Beagle Bone Black and so on.
- Support IIC communication Protocol
- Super Mini size
- Color: White
- Resolution: 128x64 pixels
Specifications
Display Specifications
- Display Mode: Passive Matrix
- Display Color: Monochrome (White)
- Drive Duty: 1/64 Duty
Mechanical Specifications
- Outline Drawing: According to the annexed outline drawing
- Number of Pixels: 128 × 64
- Panel Size: 24.74 × 16.9 × 1.42 (mm)
- Active Area: 21.74 × 10.86 (mm)
- Pixel Pitch: 0.17 × 0.17 (mm)
- Pixel Size: 0.15 × 0.15 (mm)
- Weight: TBD
Maximum Ratings
Gallery
Documentations
- SSD1306 Datasheet:File:SSD1306-Revision 1.0.pdf
- Mechanical Drawing:File:0.96inch Mechanical Drawing.pdf
How to use
For Raspberry Pi 4B
- Open a terminal and Download demo code from: [ https://github.com/rm-hull/luma.examples ]
Installation instructions
Assuming you are using a Raspberry Pi (running Debian Jessie or newer), follow the instructions to wire up your display, then from a command-line:
sudo usermod -a -G i2c,spi,gpio pi sudo apt -y install python3-dev python3-pip libfreetype6-dev libjpeg-dev build-essential sudo apt -y install libsdl-dev libportmidi-dev libsdl-ttf2.0-dev libsdl-mixer1.2-dev libsdl-image1.2-dev
Log out and in again and clone this repository:
git clone https://github.com/rm-hull/luma.examples.git cd luma.examples
Finally, install the luma libraries using:
sudo -H pip3 install -e .
If you want to gather information from UPS PLUS device, you need to install following two libraries.
sudo pip3 install pi-ina219
sudo pip3 install psutil
Running the examples
After cloning the repository, enter the examples directory and try running one of the following examples listed below. For example:
python3 examples/3d_box.py
- Other example Demo:
python3 animated_gif.py
- Demo code for mini Mini Tower Kit.
#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (c) 2014-2020 Richard Hull and contributors # See LICENSE.rst for details. # PYTHON_ARGCOMPLETE_OK """ Display basic system information. Needs psutil (+ dependencies) installed:: $ sudo apt-get install python3-dev $ sudo -H pip3 install psutil $ sudo pip3 install pyina219 $ sudo pip3 install psutil """ import os import sys import time from pathlib import Path from datetime import datetime import smbus2 from ina219 import INA219, DeviceRangeError if os.name != 'posix': sys.exit('{} platform not supported'.format(os.name)) from demo_opts import get_device from luma.core.render import canvas from PIL import ImageFont try: import psutil except ImportError: print("The psutil library was not found. Run 'sudo -H pip install psutil' to install it.") sys.exit() DEVICE_BUS = 1 DEVICE_ADDR = 0x17 PROTECT_VOLT = 3700 SAMPLE_TIME = 2 ina_supply = INA219(0.00725, address=0x40) ina_supply.configure() supply_voltage = ina_supply.voltage() supply_current = ina_supply.current() supply_power = ina_supply.power() ina_batt = INA219(0.005, address=0x45) ina_batt.configure() batt_voltage = ina_batt.voltage() batt_current = ina_batt.current() batt_power = ina_batt.power() bus = smbus2.SMBus(DEVICE_BUS) # TODO: custom font bitmaps for up/down arrows # TODO: Load histogram def bytes2human(n): """ >>> bytes2human(10000) '9K' >>> bytes2human(100001221) '95M' """ symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y') prefix = {} for i, s in enumerate(symbols): prefix[s] = 1 << (i + 1) * 10 for s in reversed(symbols): if n >= prefix[s]: value = int(float(n) / prefix[s]) return '%s%s' % (value, s) return "%sB" % n def cpu_usage(): # load average, uptime uptime = datetime.now() - datetime.fromtimestamp(psutil.boot_time()) av1, av2, av3 = os.getloadavg() return "Ld:%.1f %.1f %.1f Up: %s" \ % (av1, av2, av3, str(uptime).split('.')[0]) def mem_usage(): usage = psutil.virtual_memory() return "Mem: %s %.0f%%" \ % (bytes2human(usage.used), 100 - usage.percent) def disk_usage(dir): usage = psutil.disk_usage(dir) return "SD: %s %.0f%%" \ % (bytes2human(usage.used), usage.percent) def network(iface): stat = psutil.net_io_counters(pernic=True)[iface] return "%s: Tx%s, Rx%s" % \ (iface, bytes2human(stat.bytes_sent), bytes2human(stat.bytes_recv)) def stats(device): # use custom font font_path = str(Path(__file__).resolve().parent.joinpath('fonts', 'C&C Red Alert [INET].ttf')) font2 = ImageFont.truetype(font_path, 12) with canvas(device) as draw: draw.text((0, 0), cpu_usage(), font=font2, fill="white") if device.height >= 32: draw.text((0, 14), mem_usage(), font=font2, fill="white") if device.height >= 64: draw.text((0, 26), disk_usage('/'), font=font2, fill="white") try: draw.text((0, 38), network('wlan0'), font=font2, fill="white") except KeyError: # no wifi enabled/available pass def chrg_port(): aReceivedBuf = [] aReceivedBuf.append(0x00) for i in range(1, 255): aReceivedBuf.append(bus.read_byte_data(DEVICE_ADDR, i)) if (aReceivedBuf[8] << 8 | aReceivedBuf[7]) > 4000: charge_port = 'Charging via TYPE-C' elif (aReceivedBuf[10] << 8 | aReceivedBuf[9]) > 4000: charge_port = 'Charging via MicroUSB' else: charge_port = 'Not Charging' return "CP: %s" % charge_port def batt_cur(): aReceivedBuf = [] aReceivedBuf.append(0x00) for i in range(1, 255): aReceivedBuf.append(bus.read_byte_data(DEVICE_ADDR, i)) chrg_rate = ina_batt.current() return "Bat Current: %.3f mA" % chrg_rate def batt_cap(): aReceivedBuf = [] aReceivedBuf.append(0x00) for i in range(1, 255): aReceivedBuf.append(bus.read_byte_data(DEVICE_ADDR, i)) capacity = (aReceivedBuf[20] << 8 | aReceivedBuf[19]) return "Bat Capacity: %d%%"% capacity def full_bat(): aReceivedBuf = [] aReceivedBuf.append(0x00) for i in range(1, 255): aReceivedBuf.append(bus.read_byte_data(DEVICE_ADDR, i)) full_batt = (aReceivedBuf[14] << 8 | aReceivedBuf[13]) return "Full Bat Voltage: %d mV" % full_batt def ups_status(device): # use custom font font_path = str(Path(__file__).resolve().parent.joinpath('fonts', 'C&C Red Alert [INET].ttf')) font2 = ImageFont.truetype(font_path, 12) with canvas(device) as draw: draw.text((0, 0), full_bat(), font=font2, fill="white") if device.height >= 32: draw.text((0, 14), batt_cap(), font=font2, fill="white") if device.height >= 64: draw.text((0, 26), chrg_port(), font=font2, fill="white") try: draw.text((0, 38), batt_cur(), font=font2, fill="white") except KeyError: # no wifi enabled/available pass def main(): while True: #stats(device) #time.sleep(5) ups_status(device) time.sleep(5) if __name__ == "__main__": try: device = get_device() main() except KeyboardInterrupt: pass
KeyWords
- 0.96 inch OLED display, oled screen, oled, Raspberry Pi 4B, 128x64pixels