Documentation ¶
Overview ¶
Package ssd1306 controls a 128x64 monochrome OLED display via a SSD1306 controller.
The driver does differential updates: it only sends modified pixels for the smallest rectangle, to economize bus bandwidth. This is especially important when using I²C as the bus default speed (often 100kHz) is slow enough to saturate the bus at less than 10 frames per second.
The SSD1306 is a write-only device. It can be driven on either I²C or SPI with 4 wires. Changing between protocol is likely done through resistor soldering, for boards that support both.
Some boards expose a RES / Reset pin. If present, it must be normally be High. When set to Low (Ground), it enables the reset circuitry. It can be used externally to this driver, if used, the driver must be reinstantiated.
Datasheets ¶
Product page: http://www.solomon-systech.com/en/product/display-ic/oled-driver-controller/ssd1306/
https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf
"DM-OLED096-624": https://drive.google.com/file/d/0B5lkVYnewKTGaEVENlYwbDkxSGM/view
"ssd1306": https://drive.google.com/file/d/0B5lkVYnewKTGYzhyWWp0clBMR1E/view
Example ¶
bus, err := i2creg.Open("") if err != nil { log.Fatalf("failed to open I²C: %v", err) } defer bus.Close() dev, err := NewI2C(bus, 128, 64, false) if err != nil { log.Fatalf("failed to initialize ssd1306: %v", err) } // Draw on it. f := basicfont.Face7x13 img := image1bit.NewVerticalLSB(dev.Bounds()) drawer := font.Drawer{ Dst: img, Src: &image.Uniform{image1bit.On}, Face: f, Dot: fixed.P(0, img.Bounds().Dy()-1-f.Descent), } drawer.DrawString("Hello from periph!") dev.Draw(dev.Bounds(), img, image.Point{}) if err := dev.Err(); err != nil { log.Fatal(err) }
Output:
Index ¶
- type Dev
- func (d *Dev) Bounds() image.Rectangle
- func (d *Dev) ColorModel() color.Model
- func (d *Dev) Draw(r image.Rectangle, src image.Image, sp image.Point)
- func (d *Dev) Err() error
- func (d *Dev) Halt() error
- func (d *Dev) Invert(blackOnWhite bool) error
- func (d *Dev) Scroll(o Orientation, rate FrameRate, startLine, endLine int) error
- func (d *Dev) SetContrast(level byte) error
- func (d *Dev) StopScroll() error
- func (d *Dev) String() string
- func (d *Dev) Write(pixels []byte) (int, error)
- type FrameRate
- type Orientation
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dev ¶
type Dev struct {
// contains filtered or unexported fields
}
Dev is an open handle to the display controller.
func NewI2C ¶
NewI2C returns a Dev object that communicates over I²C to a SSD1306 display controller.
If rotated, turns the display by 180°
func NewSPI ¶
NewSPI returns a Dev object that communicates over SPI to a SSD1306 display controller.
If rotated is true, turns the display by 180°
The SSD1306 can operate at up to 3.3Mhz, which is much higher than I²C. This permits higher refresh rates.
Wiring ¶
Connect SDA to MOSI, SCK to SCLK, CS to CS.
In 3-wire SPI mode, pass nil for 'dc'. In 4-wire SPI mode, pass a GPIO pin to use.
The RES (reset) pin can be used outside of this driver but is not supported natively. In case of external reset via the RES pin, this device drive must be reinstantiated.
func (*Dev) ColorModel ¶
ColorModel implements devices.Display.
It is a one bit color model, as implemented by image1bit.Bit.
func (*Dev) Draw ¶
Draw implements devices.Display.
It draws synchronously, once this function returns, the display is updated. It means that on slow bus (I²C), it may be preferable to defer Draw() calls to a background goroutine.
It discards any failure.
func (*Dev) Halt ¶
Halt turns off the display.
Sending any other command afterward reenables the display.
func (*Dev) Scroll ¶
func (d *Dev) Scroll(o Orientation, rate FrameRate, startLine, endLine int) error
Scroll scrolls an horizontal band.
Only one scrolling operation can happen at a time.
Both startLine and endLine must be multiples of 8.
Use -1 for endLine to extend to the bottom of the display.
func (*Dev) SetContrast ¶
SetContrast changes the screen contrast.
Note: values other than 0xff do not seem useful...
func (*Dev) StopScroll ¶
StopScroll stops any scrolling previously set and resets the screen.
type FrameRate ¶
type FrameRate byte
FrameRate determines scrolling speed.
const ( FrameRate2 FrameRate = 7 FrameRate3 FrameRate = 4 FrameRate4 FrameRate = 5 FrameRate5 FrameRate = 0 FrameRate25 FrameRate = 6 FrameRate64 FrameRate = 1 FrameRate128 FrameRate = 2 FrameRate256 FrameRate = 3 )
Possible frame rates. The value determines the number of refreshes between movement. The lower value, the higher speed.
type Orientation ¶
type Orientation byte
Orientation is used for scrolling.
const ( Left Orientation = 0x27 Right Orientation = 0x26 UpRight Orientation = 0x29 UpLeft Orientation = 0x2A )
Possible orientations for scrolling.
Directories ¶
Path | Synopsis |
---|---|
Package image1bit implements black and white (1 bit per pixel) 2D graphics.
|
Package image1bit implements black and white (1 bit per pixel) 2D graphics. |
Package ssd1306smoketest is leveraged by periph-smoketest to verify that two SSD1306, one over I²C, one over SPI, can display the same output.
|
Package ssd1306smoketest is leveraged by periph-smoketest to verify that two SSD1306, one over I²C, one over SPI, can display the same output. |