All Projects → fizban99 → microbit_ssd1306

fizban99 / microbit_ssd1306

Licence: MIT license
Simple micropython library for the micro:bit to control the SSD1306 display

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to microbit ssd1306

pxt-calliope
A Microsoft MakeCode editor for the Calliope Mini board
Stars: ✭ 33 (-29.79%)
Mutual labels:  microbit
smart-garden-ornaments
The smart garden ornaments project! 🦩🌱🤖
Stars: ✭ 20 (-57.45%)
Mutual labels:  microbit
ninjaberry
Ninjaberry: Raspberry Pi UI for @bettercap
Stars: ✭ 39 (-17.02%)
Mutual labels:  oled-display-ssd1306
pxt-minode
mi:node kit(micro:bit IoT Starter Kit by element14) driver package for PXT/microbit
Stars: ✭ 25 (-46.81%)
Mutual labels:  microbit
pxt-bluetooth-gamepad
BLE HID Gamepad module for micro:bit
Stars: ✭ 20 (-57.45%)
Mutual labels:  microbit
pyscrlink
Scratch-link for Linux written in python
Stars: ✭ 88 (+87.23%)
Mutual labels:  microbit
zig-bare-metal-microbit
Bare metal microbit program written in zig
Stars: ✭ 27 (-42.55%)
Mutual labels:  microbit
pxt-powerfunctions
MakeCode extension for controlling your LEGO Power Functions devices with an IR-emitting LED
Stars: ✭ 44 (-6.38%)
Mutual labels:  microbit
Electronic-Cheat-Sheet-and-Schematics-MegaCollection
A lot of Files of various Electronic Shit that I have collected over the years. Cheatsheet, Schematics, Pinouts, Pdf, and More... Enjoy it ;)
Stars: ✭ 43 (-8.51%)
Mutual labels:  microbit
ganymede
the Ganymede keyboard. An ARM based, split, ergonomic keyboard
Stars: ✭ 58 (+23.4%)
Mutual labels:  ssd1306
Python-For-Kids
A comprehensive and FREE Online Python Development tutorial FOR KIDS utilizing an official BBC micro:bit Development Board going step-by-step into the world of Python for microcontrollers.
Stars: ✭ 621 (+1221.28%)
Mutual labels:  microbit
pxt-neopixel
A Neo-Pixel package for pxt-microbit
Stars: ✭ 47 (+0%)
Mutual labels:  microbit
Tinygo
Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
Stars: ✭ 9,068 (+19193.62%)
Mutual labels:  microbit
microbit-ble
Read data from micro:bit using Bluetooth from Linux
Stars: ✭ 40 (-14.89%)
Mutual labels:  microbit
esp-oled-firebase
0.91" inch OLED and an esp8266-12E, which is integrated to firebase to fetch text file and send and receive a text message
Stars: ✭ 101 (+114.89%)
Mutual labels:  oled-display-ssd1306
openblock-desktop
Graphic programming software for hardware like: arduino, microbit, esp32, esp8266...
Stars: ✭ 161 (+242.55%)
Mutual labels:  microbit
microbit hcsr04
micro:bit library for the HC-SR04 ultrasonic sensor
Stars: ✭ 15 (-68.09%)
Mutual labels:  microbit
blockly
Otto Blockly; a fully integrated graphical programming for any type of Arduino projects, including robots, ready to install in your computer, it works offline and also online
Stars: ✭ 85 (+80.85%)
Mutual labels:  microbit
pico-ssd1306
Simple library for using ssd1306 displays with the Raspberry Pi Pico and the pico-sdk.
Stars: ✭ 57 (+21.28%)
Mutual labels:  ssd1306
Pxt
Microsoft MakeCode (PXT - Programming eXperience Toolkit)
Stars: ✭ 1,649 (+3408.51%)
Mutual labels:  microbit

Basic micropython library to control the OLED SSD1306 128x64 I2C with a micro:bit

This library allows the micro:bit to control 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).

Due to the low memory of the micro:bit, all functions except for show_bitmap, work in zoom mode, so the effective screen resolution is 64x32 dots of 4x4 pixels of size.

Text is rendered using the internal microbit fonts.

The library is distributed in different files to allow importing only the required functions in order to reduce memory consumption.

1   Main features

  • Load a 128x64 bitmap file
  • Set and get pixel value
  • Render of text using the internal micro:bit font
  • Support of micro:bit Image object by transforming it into a stamp that can be displayed
  • Sample programs demonstrating the different functions

2   Preparation and displaying of a bitmap image

  1. Create a bitmap with an image editor with only 2 bits per pixel (black and white)

  2. Use the LCDAssistant (http://en.radzio.dxp.pl/bitmap_converter/) to generate the hex data.

  3. Copy the hex data into the bitmap_converter.py file in the sample_images folder and run it on a computer with Python.

  4. Flash a completely empty file from mu.

  5. Copy the generated file to the micro:bit using the file transfer function in mu

  6. Create a main.py file, import sdd1306_bitmap and use the function show_bitmap to display the file

  7. Move the files main.py, sdd1306.py and sdd1306_bitmap.py to the micro:bit with the file transfer function in mu

  8. Reset the micro:bit or press CTRL+D in the Repl.

    https://cdn.rawgit.com/fizban99/microbit_ssd1306/7f60064d/microbit_with_logo.jpg

3   Library usage

3.1   initialize()

You have to use this instruction before using the display. This puts the display in its reset status.

3.2   clear_oled()

You will typically use this function after initialize(), in order to make sure that the display is blank at the beginning.

3.3   show_bitmap(filename)

Displays on the OLED screen the image stored in the file filename. The image has to be encode as described in the previous section.

from ssd1306 import initialize, clear_oled
from ssd1306_bitmap import show_bitmap

initialize()
clear_oled()
show_bitmap("microbit_logo")

3.4   set_px(x, y, color, draw=1)

Paints the pixel at position x, y (of a 64x32 coordinate system) with the corresponding color (0 dark or 1 lighted). If the optional parameter draw is set to 0 the screen will not be refreshed and draw_screen() needs to be called at a later stage, since multiple screen refreshes can be time consuming. This allows setting different pixels in the buffer without refreshing the screen, and finally refresh the display with the content of the buffer.

from ssd1306_px import set_px
from ssd1306 import draw_screen, initialize, clear_oled

initialize()
clear_oled()
set_px(10,10,1)
set_px(20,20,0,0)
draw_screen()

3.5   get_px(x, y)

Returns the color of the given pixel (0 dark 1 lighted)

from ssd1306 import initialize, clear_oled
from ssd1306_px import get_px

initialize()
clear_oled()
color=get_px(10,10)

3.6   add_text(x, y, text, draw=1)

Prints the text given by text at the row x and column y. The screen is divided into 12 columns and 5 rows. If the optional parameter draw is set to 0 the screen will not be refreshed and draw_screen() needs to be called at a later stage, since multiple screen refreshes can be time consuming. This allows writing different rows in the buffer without refreshing the screen, and finally refresh the display with the content of the buffer.

from ssd1306 import initialize, clear_oled
from ssd1306_text import add_text

initialize()
clear_oled()
add_text(0, 2, "Hello, world")

3.7   create_stamp(img)

Creates a stamp from an Image object. A stamp is just a set of bytes that will be used to print the image on the OLED display. The function transforms any led value different than 0 to 1. A stamp is defined with 5 columns of 8 pixels each, so a stamp occupies 5 bytes of memory and can also be defined as a bytearray of 5 bytes. If the stamp has been created from an Image, the stamp will be created centering the image. This command is used in combination of draw_stamp

3.8   draw_stamp(x, y, stamp, color, draw=1)

Draws the stamp on the screen at the pixel position x, y. The stamp will be printed using OR if color is 1 and AND NOT if color is 0, effectively removing the stamp when color=0.

from ssd1306 import initialize, clear_oled
from ssd1306_stamp import draw_stamp
from ssd1306_img import create_stamp
from microbit import Image

initialize()
clear_oled()
stamp = create_stamp(Image.HEART)
draw_stamp(10, 10, stamp, 1)

When drawing a stamp, the contents of the screen just before the first column of the stamp and the content of the screen just after the last column of the stamp is also redrawn. This is done to allow using a function like this to perform a simple movement of a stamp:

def move_stamp(x1, y1, x2, y2, stmp):
  draw_stamp(x1, y1, stmp, 0, 0)
  draw_stamp(x2, y2, stmp, 1, 1)

The previous function removes a stamp at position x1,y1 and redraws it at position x2, y2. Note that the first draw_stamp() does not refresh the screen. The screen is only refreshed once, with the second draw_stamp(). If the stamp is 5x5 and it is centered within the 8x7 area, the stamp will be properly updated if the distance between the two coordinates is maximum one pixel.

3.9   pulse(time=500)

Modifies the contrast of the screen progressively to create pulse effect. Thanks to Steve Stagg for his suggestion.

from ssd1306 import initialize, clear_oled
from ssd1306_bitmap import show_bitmap
from ssd1306_effects import pulse

initialize()
clear_oled()
show_bitmap("microbit_logo")
pulse()

3.10   blink(time=1000)

Makes the screen blink by switching it off and on.

from ssd1306 import initialize, clear_oled
from ssd1306_bitmap import show_bitmap
from ssd1306_effects import blink

initialize()
clear_oled()
show_bitmap("microbit_logo")
blink()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].