OLED

Test Status Hex version

OLED is a library to manage the monochrome OLED screen based (for now) on chip SSD1306 connected by SPI or I2C.

The idea is to support other similar chips also.

NOTE: On OLED v0.3.0 the Scenic driver has been moved to scenic_driver_oled.

Sample

Features

Graphic primitives

  • [x] Points
  • [x] Lines
  • [x] Rects
  • [x] Filled Rects
  • [x] Circles
  • [ ] Filled Circles
  • [ ] Polygons
  • [ ] Filled Polygons
  • [ ] Text rendering (Try Chisel)




Using OLED and Scenic

Basic Setup

1. edit your mix.exs

def deps do
  [
    {:oled, "~> 0.3"}
  ]
end

2. create a display module

defmodule MyApp.MyDisplay do
  use OLED.Display, app: :my_app

end

3. add the configuration

config :my_app, MyApp.MyDisplay,
  device: "spidev0.0",
  driver: :ssd1306,
  type: :spi,
  width: 128,
  height: 64,
  rst_pin: 25,
  dc_pin: 24

4. add your application's supervision tree

defmodule MyApp.Application do
  use Application

  def start(_type, _args) do
    import Supervisor.Spec, warn: false

    children = [
      # Add this line
      MyApp.MyDisplay
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

5. use it

  # Draw something
  MyApp.MyDisplay.rect(0, 0, 127, 63)
  MyApp.MyDisplay.line(0, 0, 127, 63)
  MyApp.MyDisplay.line(0, 63, 127, 0)

  # Display it!
  MyApp.MyDisplay.display()

Displays configuration

config :my_app, MyApp.MyDisplay,
  device: "spidev0.0",  # Device (i.e.: `spidev0.0`, `i2c-1`, ...)
  driver: :ssd1306,     # Driver. (Only SSD1306 for now)
  type: :spi,           # Connection type: `:spi` or `:i2c`
  width: 128,           # Display Width
  height: 64,           # Display Height
  rst_pin: 25,          # Reset GPIO pin (SPI only)
  dc_pin: 24            # DC GPIO pin (SPI only)
  address: 0x3C         # DC GPIO pin (I2C only)