0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

2.7inch e-Paper V2用の制御プログラムをGo言語で書くには

Posted at

概要

以前2.7 inch e-PaperのプログラムGo言語で作る方法を記載したがこれは、2.7 inch e-Paper(b) V1用である可能性がある
https://qiita.com/karosuwindam/items/dd5a781ce49d9473c7e7

そのために、一応作成方法について記載する

ベース資料について

以下URLの情報が非常に参考になった。

実際の作業について

2.13 V2用のプログラムをベースに作成したがまずリポジトリが現時点では参照できないので以下の通りにv3に置きかえる必要がある。

import (
	"periph.io/x/conn/v3/gpio"
	"periph.io/x/conn/v3/gpio/gpioreg"
	"periph.io/x/conn/v3/physic"
	"periph.io/x/conn/v3/spi"
	"periph.io/x/conn/v3/spi/spireg"
	"periph.io/x/host/v3"
)

他には、2.7inchの場合は、176x264のためサイズを変更させる必要がある

初期化実行時の処理は、公式プログラムのpythonの書き方を参考に以下の順番を実行する

  1. ハードウェアリセット
  2. ソフトウェアリセット
  3. Y-RAMの開始と終わりのポジションを0と264に設定
  4. Y-RAMのカウント数を0に設定
  5. data entry modeを設定

実際にコードを変更する場合は以下の通りにする。

func (e *Epd) Init() {
	//EPD hardware init start
	e.reset()
	e.readBusy()

	//SWRESET
	e.executeCommandAndLog(0x12, "SOFT_RESET", nil)
	e.readBusy()

	// set Ram-Y address start/end position s=0 e=264
	e.executeCommandAndLog(0x45, "SET_Y-RAM_START_END_POSITION", []byte{0x00, 0x00, 0x07, 0x01})

	// set RAM y address count to 0
	e.executeCommandAndLog(0x4F, "SET Y-RAM COUNT TO", []byte{0x00, 0x00})

	//data entry mode
	e.executeCommandAndLog(0x11, "DATA_ENTRY_MODE", []byte{0x03})

	slog.Debug("INIT DONE")
	time.Sleep(100 * time.Millisecond)
}

ディスプレイターンONの処理は以下の通り0xF7を書き込むように変更

// TurnDisplayOn turn the epd on
func (e *Epd) TurnDisplayOn() {
	e.sendCommand(0x22)
	e.sendData(0xF7)
	e.sendCommand(0x20)
	e.readBusy()
}

ディプレイを白く塗りつぶすクリア処理は以下の通りoffからonに変更する。

func (e *Epd) Clear() {
	lineWidth := e.Width / 8
	if e.Width%8 != 0 {
		lineWidth++
	}
	e.sendCommand(0x24)
	for i := 0; i < e.Height; i++ {
		for j := 0; j < lineWidth; j++ {
			e.sendData(0xFF)
		}
	}
	e.TurnDisplayOn()
}

もし、全て黒にする処理は以下の通り書けば実行できる。

func (e *Epd) Black() {
	lineWidth := e.Width / 8
	if e.Width%8 != 0 {
		lineWidth++
	}
	e.sendCommand(e.StartTransmission)
	for i := 0; i < e.Height; i++ {
		for j := 0; j < lineWidth; j++ {
			e.sendData(0x00)
		}
	}
	e.TurnDisplayOn()

}

あとの注意点として、TurnDisplayOnを実行したあとは、3秒ぐらい待つと次の書き込みは失敗しない

プログラムのテスト

自分は、以下の通りのテストコードを書いて動作テストを実施した

func TestEPaper(t *testing.T) {
	e := CreateEpd()
	if err := e.Open(); err != nil {
		t.Fatalf("open error %v", err.Error())
	}
	defer e.Close()
	defer e.Clear()
	e.Init()
	e.Clear()
	time.Sleep(3 * time.Second)
 	fmt.Printf("Display\n")
	e.Black()
	fmt.Printf("sleeping\n")
	time.Sleep(3 * time.Second)
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?