Skip to content

Instantly share code, notes, and snippets.

@ringvold
Created September 20, 2022 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ringvold/7437e8ee8aa4a7e7cd864e748dabb36e to your computer and use it in GitHub Desktop.
Save ringvold/7437e8ee8aa4a7e7cd864e748dabb36e to your computer and use it in GitHub Desktop.
Basic setup for working with oled with nerves (SSD1306 128x32)
# OLED
```elixir
Mix.install([
:oled,
:chisel
])
```
## Basic setup
```elixir
Circuits.I2C.detect_devices()
```
Create a display module
```elixir
defmodule MyApp.MyDisplay do
use OLED.Display, app: :my_app
end
```
Add the configuration
```elixir
Application.put_env(:my_app, MyApp.MyDisplay,
device: "i2c-1",
driver: :ssd1306,
type: :i2c,
width: 128,
height: 32,
rst_pin: 25,
dc_pin: 24,
address: 0x3C
)
```
```elixir
{:ok, pid} = MyApp.MyDisplay.start_link([])
```
```elixir
MyApp.MyDisplay.clear()
# Draw something
MyApp.MyDisplay.rect(0, 0, 127, 31)
MyApp.MyDisplay.line(0, 0, 127, 31)
MyApp.MyDisplay.line(0, 31, 127, 0)
# Display it!
MyApp.MyDisplay.display()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment