Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Python library to enable 128x32 pixel OLED for Raspberry Pi (both 32 and 64bit).

License

NotificationsYou must be signed in to change notification settings

crismc/rpi_i2c_oled

Repository files navigation

Python library to enable 128x32 pixel OLED for Raspberry Pi (both 32 and 64-bit) that utilize the SSD1306 chipset. This works as a standalone service and can run on a standard Raspberry Pi running Raspian.

This addon leverages the originalAdafruit Python SSD1306 andGPIO libraries, which have been deprecated. However, I have taken the nessassary parts out of this and bundled them into this I2C module avoiding the need for GPIO and relying on the Raspberry Pi's I2C setup.

Buy Me A Coffee

license-badgerelease

Some Teaser Screenshots

WelcomeHA SplashCPUMemoryStorageNetworkExit Screen
WelcomeSplashCPU StatsRAM StatsStorage StatsNetwork StatsExit
CPU StatsRAM StatsStorage StatsNetwork Stats
CPU StatsRAM StatsStorage StatsNetwork Stats

Custom Screen & Static Text Variables

As well as the above screens, you can configure a static custom screen which can be fixed or animated.

If the configured text is greater than the screen size, it will scroll across the screen unless you configure it to display as lines.

Scrolling animations also supports configurable apmlitude enabling the text to wave up and down as it scrolls.

ExitWelcome

This screen can take variables to help personalise your view:

"Static_Screen_Text": "Today is {datetime}, running hassio verion {hassio.os.version} on {hostname} with IP {ip}"

The following variables are supported

VariableDescription
{datetime}Displays the current datetime based on the defined format specified in theDateTime_Format config option.
{hostname}Displays the current hostname of the host device
{ip}Displays the host device IP
{hassio.info.property}Fetches a specified property from Home Assistants supervisor API (e.g.http://supervisor/os/info). You can state the namespace and property which will populate with the responding value. This must be fixed with hassio first, followed by the namespace (e.g. os, network etc), then the property e.g. hassio.os.latest_version will callhttp://supervisor/os/info and display thelatest_version value.


Home Assistant Support

This repository has been broken out to work as a standalone service and will work on a standard Raspberry Pi running Raspian. Any screens which are dependent on Home Assistant (e.g.Splash) will be automatically disabled.

The Home Assistant add-on that uses this can be accessed fromHomeAssistant_Addons

Hardware Setup

You can use 0.91 Inch 128x32 I2C module, as long as it is registered on /dev/i2c-1 which is the Rasperry Pi default.

I purchased thisMakerHawk I2C OLED Display Module I2C Screen Module 0.91" 128x32 I2C

PinDetails
1Power (3.3V / VCC)
3SDA (I2C Data)
5SCL (I2C Clock)
14Ground (0V)

Installation

Enable I2C on the Raspberry Pi

sudo raspi-config# Interface Options > I2C

One-Step Automated Install


Those who want to get started quickly and conveniently may install the RPI_I2C_OLED using the following command:

curl -sSL https://raw.githubusercontent.com/crismc/rpi_i2c_oled/v1.0.4/basic-install.sh | sudo bash

This will download the latest release, and install it as a service. Once run, you can control theoled service by the following:

sudo service oled startsudo service oled stopsudo service oled restart

Installing From Source


Initial apt-get installs:

sudo apt-get install i2c-tools git vim

Test I2C device is working:

$ i2cdetect -y 1

Install Python3 dependencies

sudo apt-get install python3-dev python3-smbus python3-pil

Checkout this code

git clone git@github.com:crismc/rpi_i2c_oled.gitcd rpi_i2c_oled

Test OLED

cd rpi_i2c_oledpython3 display.py

Running as a Service


Copy the repo file to /etc:

sudo cp -ri ../rpi_i2c_oled /etc

Create a sym link of the service file in /etc/systemd/system, and reload it

sudo ln -s /etc/rpi_i2c_oled/oled.service /etc/systemd/system/oled.servicesudo systemctl daemon-reload

Test it out

sudo service oled startsudo service oled stopsudo service oled restart

Start on boot

sudo systemctl enable oled.service

Configuration Options

You can modify the display of the content by editing theoptions.json file.

By default theoptions.json is loaded from the same directory as thedisplay.py.

Note: The keys are caseinsensitive

If you want to change this location, simply pass in the path to the desired config using the flags -c or --config:

python3 display.py -c /path/to/options.json

or

python3 display.py --config /path/to/options.json
NameTypeRequirementDescriptionDefault
i2c_busintRequiredI2C bus number. /dev/i2c-[bus number]1
Temperature_UnitstringRequiredDisplay the CPU temperature in C or FC
RotateintOptionalRotates the screen by the number of degrees provided counter clockwise around its centre (e.g. 180 displays the screen upside down).0
Show_IconsbooleanOptionalShow icons for each screentrue
Show_HintbooleanOptionalShow hint for each screen (instead of icon)false
CompactbooleanOptionalShow data in a more compact formfalse
Default_DurationintRequiredHow long in seconds to display each screen by default. Ignored if specified on specific screen10
DateTime_FormatstringOptionalFormat of the{datetime} static text variable%d/%m/%Y %H:%M:%S
Graceful_Exit_TextstringOptionalText to display when the service is exited. Accepts same variables as the custom screen.Exited at {datetime}
Static_Screen_TextstringOptionalText to display when theShow_Static_Screen is enabled. Accepts all static text variables.Hassio verion {hassio.os.version} on {hostname} with IP {ip}
Static_Screen_Text_NoScrollbooleanOptionalDisable the scrolling animation if the static text its too large to fit. If set to true, make a best effort to stack the text as centered linesfalse
Scroll_AmplitudeintOptionalAmount of wave action the scrolling animation text has. The bigger the number, the bigger the wave.6
Show_Static_ScreenbooleanRequiredShow the static screen with the specified custom textfalse
Show_Welcome_ScreenbooleanRequiredShow the animated Welcome tohostname screentrue
Welcome_Screen_TextstringOptionalText to display when theShow_Welcome_Screen is enabled. Accepts all static text variables.Welcome to {hostname}
Show_Splash_ScreenbooleanRequiredShow the Home Assistant core and version screen. I you're not using Home Assistant, leave this falsefalse
Show_Network_ScreenbooleanRequiredShow the Network Information screentrue
Show_CPU_ScreenbooleanRequiredShow the CPU Information screentrue
Show_Memory_ScreenbooleanRequiredShow the Memory Information screentrue
Show_Storage_ScreenbooleanRequiredShow the Storage Information screentrue
Screenshotboolean or stringOptionalSaves a screenshot of the screen to the specified path, or to './img/examples/' if set to Truefalse
*_Screen_LimitintOptionalNumber of times to show the screen in the cycle. Once limit is reached, display will no longer appearnull
*_Screen_DurationintOptionalHow long in seconds to display the screen10


Logs & Debugging

As logging is initiated before the party begins, log levels are defined outside of theoptions.json.

Therefore, to enable debugging, when runningdisplay.py add-d or--debug to the command.

e.g.:

$python3 display.py -dINFO:Config:Loading config: /etc/rpi_i2c_oled/options.jsonINFO:Config:Home Assistant is not supported on this instanceINFO:Config:'welcome' limited to 5 iterationsINFO:__main__:'welcome' is being processedINFO:Screen:'WelcomeScreen' createdINFO:Screen:'WelcomeScreen' rendering



Compatible Hardware (SSD1306 Chips)

Several examples of SSD1306 driven I2C OLED hardware that should work. This was originally designed specifically to work with theAdafruit SSD1306-based OLED displays. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

Credits

  • Special thanks toGareth Cheyne for his initial version of this project.

  • Tony DiCola (RIP) andAdafruit Industries for initial implementation details, see original repo:https://github.com/adafruit/Adafruit_Python_SSD1306

  • crismc - After the removal of GPIO support from Home Assistant, the referenced addon no longer worked for me, so I took the initial project apart, and smashed it together with the Adafruit I2C libraries removing the GPIO requirements. Additionally, the original build didn't work on 64-bit versions of the Raspberry Pi, nor would it work as a stand alone service.

  • Ultronics

See Also


[8]ページ先頭

©2009-2025 Movatter.jp