Git Product home page Git Product logo

bsb_ssd1306_i2c's Introduction

Python SSD1306

This project contains a python module for interfacing with SSD1306 OLED device connected via I2C bus.

Partially based on Adafruit Arduino code

All code is GPLv2 licensed unless explicitly stated otherwise.

Building

Use Black-Swift [VirtualBox VM] (http://www.black-swift.com/wiki/index.php?title=C/C%2B%2B_Building_and_Remote_Debugging_with_Eclipse) In virtual machine change directory to /home/openwrt/openwrt Copy sources to package/bsb_ssd1306_i2c/ directory, for example

Run and say yes for new bsb_ssd1306_i2c package: make oldconfig

Run for compile package: make *package/bsb_ssd1306_i2c/compile V=s*.

Check bin/brcm2708/packages/base/ for results (like ssd1306-i2c_0.3-1_brcm2708.ipk)

Usage

First, setup I2C on your Black Swift board:

opkg install kmod-i2c-gpio-custom i2c-tools
insmod i2c-dev
insmod i2c-gpio-custom bus0=0,18,19

This mean that SDA connected to GPIO18 and SCL to GPIO19

Connect your SSD1306 OLED display. Don't forget about pull-up resistors!

Check your connections:

i2cdetect -y 1

Example programm

from ssd1306_i2c import SSD1306
ssd = SSD1306(1, 0x3c) # /dev/i2c-1, device address 0x3c
ssd.clear()
ssd.circle(25, 25, 15, 1)
ssd.line(0, 0, 127, 20, 1);
ssd.update()
ssd.write("SSD1306 I2C", x=5, y=6)
ssd.update()

ssd.font("Fixed3x5")
ssd.write("1234567890", x=5, y=9, color=1)
ssd.font("Arial14")
ssd.write("1234567890", x=5, y=20, color=1)
ssd.font("Corsiva12")
ssd.write("1234567890", x=5, y=40, color=1)
ssd.update()
#!/usr/bin/env
import time
from ssd1306_i2c import SSD1306
ssd = SSD1306(0, 0x3c) # /dev/i2c-0, device address 0x3c

ssd.clear()
ssd.rect(1, 1, 127, 63, 1)
ssd.update()

def main():
  while True:
    ssd.rect_fill(10, 25, 111, 25, 0)
    ssd.font("VerdanaDigits24")
    ssd.write(time.strftime("%H:%M:%S"), x=12, y=25, color=1)
    ssd.update()

if __name__ == '__main__':

  try:
    main()
  except KeyboardInterrupt:
    pass
  finally:
    ssd.clear()
    ssd.update()

Methods

SSD1306(bus, address)

Connects to the specified I2C bus using device address

update()

Update OLED display image from buffer.

clear()

Clear OLED display.

pixel(x, y, color)

Draws pixel at specified location and color on OLED display.

circle(x0, y0, radius, color)

Draws circle at specified location, radius and color on LCD display.

line(x0, y0, x1, y1, color)

Draws line at specified locations and color on OLED display.

line_vertical(x, y, len, color)

Draws vertical line at specified location, length and color on OLED display.

line_horisontal(x, y, len, color)

Draws horisontal line at specified location, length and color on OLED display.

rect(x, y, w, h, color)

Draws rect at specified location, width, height and color on OLED display.

rect_fill(x, y, w, h, color)

Draws and fills rect at specified location, width, height and color on OLED display.

cursor(x, y)

Set text cursor at specified location.

font(name, spacing=1)

Set text font name and char spacing.

char(ch, x=0, y=0, color=1)

Draw char at current or specified position with current font and size.

write(string, x=0, y=0, color=1)

Draw string at current or specified position with current font and size.

bsb_ssd1306_i2c's People

Contributors

polkabana avatar nmaas87 avatar harihend1973 avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.