1
0

More than 1 year has passed since last update.

2.7inch e-Paper HatをRaspberry Piで使用する go言語

Posted at

はじめに

e-Paperを購入したけど使っていなかったので、とりあえず試してみた。
あと、Pythonのプログラムがあるけど、go言語でやりたいので調べたらライブラリがあるのでとりあえずテストしてみた。

ソースコード

main.go
package main

import (
    "time"

    "github.com/otaviokr/go-epaper-lib"
)

func main() {
    // New EPaperDisplay handler for model 2.7 inches, black-and-white..
    epd, err := epaper.New(epaper.Model2in7bw)
    if err != nil {
        panic(err)
    }

    // Run mandatory initialization.
    epd.Init()

    // Clear screen to avoid undesired meshes.
    epd.ClearScreen()

    // Parse the string and process it with TTF font.
    text := "test"
    fontSize := 10.0
    fontFile := "/usr/share/fonts/truetype/dejavu/DejaVuSans-BoldOblique.ttf"
    m := epd.Write(text, fontSize, fontFile)

    // Add the resulting image into the buffer.
    epd.AddLayer(m, 0, 0, false)
    epd.AddLayer(m, 0, 30, true)

    // Print the buffer onto the display..
    epd.PrintDisplay()
    // epd.Display()

    // Just a timeout before clearing the screen.
    time.Sleep(10000 * time.Millisecond)
    epd.ClearScreen()

    // Always put the screen to sleep when it will not be refreshed shortly.
    epd.Sleep()
}

結果

go mod init epaper
go mod tity
go run ./

以下図のように表示されることが分かった。

image.png

これから、改造次第でいろいろと違うこともできそう

参考資料

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0