S-0005: Difference between revisions

From 52Pi Wiki
Jump to navigation Jump to search
(Created page with "==0.96 Inch OLED Module == right|300px ==Description== 0.96 Inch OLED Module is a mini display screen with 128X64 resoluction and SSD1306 chipset.<br> Standa...")
 
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
==0.96 Inch OLED Module ==
==0.96 Inch OLED Module ==
[[File:Da4.jpg|right|300px]]
[[File:Da1.jpg|right|300px]]


==Description==
==Description==
Line 14: Line 14:
* Support IIC communication Protocol
* Support IIC communication Protocol
* Super Mini size
* Super Mini size
* Color: Black & White  
* Color: White  
* Resolution: 128x64 pixels
* Resolution: 128x64 pixels


==Specifications==
==Specifications==
===Display Specifications===
===Display Specifications===
===Display Specifications===
* Display Mode: Passive Matrix
* Display Mode: Passive Matrix
Line 34: Line 33:
[[File:96oled08.jpg|left|500px]]
[[File:96oled08.jpg|left|500px]]
<br style="clear:both;">
<br style="clear:both;">
==Gallery==
==Gallery==
{|
{|
|[[File:Xiao1.jpg|left|320px]]
|[[File:Da5.jpg|left|320px]]
|[[File:Xiao2.jpg|none|320px]]
|[[File:Da1.jpg|none|320px]]
|[[File:Xiao3.jpg|none|320px]]
|[[File:Da4.jpg|none|320px]]
|}
{|
|[[File:Oled96Da6.jpg|left|320px]]
|[[File:Oled96Da7.jpg|none|320px]]
|[[File:Oled96Da8.jpg|none|320px]]
|}
{|
|[[File:Oled96Da9.jpg|left|320px]]
|[[File:Oled96Da10.jpg|none|320px]]
|[[File:Oled96Da11.jpg|none|320px]]
|}
|}
{|
{|
|[[File:Xiao4.jpg|left|320px]]
|[[File:Oled96Da12.jpg|left|500px]]
|[[File:Xiao5.jpg|none|320px]]
|[[File:Oled96Da13.jpg|none|500px]]
|[[File:Xiao6.jpg|none|320px]]
|}
|}
==Documentations==
==Documentations==
* Schematic Drawing:[[File:0.91InchOLED-IIC-sch.pdf]]<br>
* SSD1306 Datasheet:[[File:SSD1306-Revision 1.0.pdf]]<br>
* SSD1306 Datasheet:[[File:SSD1306-Revision 1.0.pdf]]<br>
* Mechanical Drawing:[[File:M091-4P Model (1).pdf]]<br>
* Mechanical Drawing:[[File:0.96inch Mechanical Drawing.pdf]]<br>
 
==How to use==
==How to use==
===For Raspberry Pi 4B===
===For Raspberry Pi 4B===
* Open a terminal and Download demo code from: [ https://github.com/adafruit/Adafruit_Python_SSD1306 ]
* Open a terminal and Download demo code from: [ https://github.com/rm-hull/luma.examples ]
<pre>  
===Installation instructions===
sudo python -m pip install --upgrade pip setuptools wheel
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:
git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git
<pre>
cd Adafruit_Python_SSD1306
sudo usermod -a -G i2c,spi,gpio pi
sudo python setup.py install
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
</pre>
</pre>
* Run example Demo:
Log out and in again and clone this repository:
<pre>
<pre>
cd examples/
git clone https://github.com/rm-hull/luma.examples.git
python stats.py
cd luma.examples
</pre>
</pre>
{|
Finally, install the luma libraries using:
|[[File:91oled0180532.jpg|left|500px]]
<pre>sudo -H pip3 install -e . </pre>
|[[File:91oled0180531.jpg|none|500px]]
If you want to gather information from UPS PLUS device, you need to install following two libraries.<br>
|}
<pre>sudo pip3 install pi-ina219</pre>
<pre>sudo pip3 install psutil </pre>
 
===Running the examples===
After cloning the repository, enter the examples directory and try running one of the following examples listed below. For example:
<pre>python3 examples/3d_box.py</pre>
[[File:96oledscreen4.jpg|left|500px]]
[[File:Oled96example.jpg|left|500px]]
<br style="clear:both;">
* Other example Demo:
* Other example Demo:
<pre>python image.py</pre>
<pre> python3 animated_gif.py </pre>
[[File:91oled24.jpg|left|500px]]
[[File:Oled96exex.jpg|left|500px]]
<br style="clear:both;">
===For Arduino===
This routine is an OLED display routine based on the arduino UNO board.<br>
* 1. Before opening the program, put the font folder in the libraries (i.e. library) folder in the arduino root directory.
* 2. Because the routine shows a larger picture, more text, the picture and text of the mold are all stored in FLASH. So when displaying pictures or text, you need to read out the mold inside flash and then display it on the display, so the display speed is slower.
* 3. If the user wants to display what they want, they need to modify the font file in the font folder to add their own mold.
* 4. Refer to the contents of the "Model Inge Description" folder.
* 5. Because the company's word library chip is GBK code, and arduino utf-8 encoding method is different, so there is no word library display.
<font color=red><b>Download Sketch:</b></font> [[File:OLED arduino UNO demo.zip ]]
* 6. Unzip it and open it with Arduino IDE, select arduino UNO and COM port, press upload.
[[File:91oled.jpg|left|500px]]
<br style="clear:both;">
<br style="clear:both;">
* Demo code for mini Mini Tower Kit.
<pre>
#!/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
</pre>


==KeyWords==
==KeyWords==
* 0.91 inch OLED display, oled screen, oled, Raspberry Pi 4B,
* 0.96 inch OLED display, oled screen, oled, Raspberry Pi 4B, 128x64pixels

Latest revision as of 18:07, 14 January 2022

0.96 Inch OLED Module

Da1.jpg

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

96oled08.jpg


Gallery

Da5.jpg
Da1.jpg
Da4.jpg
Oled96Da6.jpg
Oled96Da7.jpg
Oled96Da8.jpg
Oled96Da9.jpg
Oled96Da10.jpg
Oled96Da11.jpg
Oled96Da12.jpg
Oled96Da13.jpg

Documentations

How to use

For Raspberry Pi 4B

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
96oledscreen4.jpg
Oled96example.jpg


  • Other example Demo:
 python3 animated_gif.py 
Oled96exex.jpg


  • 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