GithubHelp home page GithubHelp logo

fizban99 / microbit_ssd1306_7seg Goto Github PK

View Code? Open in Web Editor NEW
8.0 4.0 6.0 198 KB

micro:bit library to use an ssd1306 OLED display as a 7 segment display.

License: MIT License

Python 100.00%
microbit micropython oled-display-ssd1306

microbit_ssd1306_7seg's Introduction

micropython library to emulate a 7 segment display on a OLED SSD1306 128x64 I2C with a micro:bit

This library allows the micro:bit to emulate a 7 segment display with the typical low cost 0,96" OLED display sold in Amazon and eBay connected to the default I2C pins of the micro:bit. Some sort of breakout is required. Note that the Kitronik breakout does not have pre-soldered the I2C pins and you will need to attach some headers to access the I2C pins.

You should connect the device's SCL pin to micro:bit pin 19, and the device's SDA pin to micro:bit pin 20. You also must connect the device's ground to the micro:bit ground (pin GND).

This library uses the full resolution of the display, since it does not use a display buffer. All segments have been designed not to overlap the area of another segment. Number rendering is really fast, since only segments that change are drawn or cleared and the segments have been defined to expand to as few pages as possible.

The library requires a binary definition of the segments to be loaded (segments.bin) together with the ssd1306_7seg.py file. This allows reducing memory consumption at compile time.

7segments.png
  • 128x64 resolution of the numbers

  • 4 digits

  • Option to draw two dots to separate the first two digits from the second two digits to display times

  • Sample program demonstrating the usage

    microbit_timer.jpg

Initializes the OLED display with zeros if showZeros is set to 1 and with two dots separating the first two digits to display times if showDots is set to 1.

from ssd1306_7seg import initialize

initialize(1,1)

Displays the number n on the screen, with the decimal point at position numDec, being 0 the right-most position. n should be between 0 and 9999. If numDec=0 no decimal point is displayed. Note that the digit 0 does not support decimal point.

from ssd1306_7seg import initialize, disp_num

initialize(1,1)
disp_num(1306)
7-segment.png

Displays the digit definition d at position digit. A digit definition is created as the resulting binary number of the combination of required segments to paint the number:

bit_table.png

According to the above table, to paint a 1 we have to use the value 0x60 at the desired position. If we want digit 0 to be 1, we would use:

from ssd1306_7seg import initialize, set_digit

initialize(0,0)
set_digit(0,0x60)

Can you make the display show HELO? You can find the hexadecimal codes in the excel file of the tools folder. Remember that you can use the REPL for quick tests like this.

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.