Skip to content

Instantly share code, notes, and snippets.

@kmtr
Last active December 9, 2016 00:59
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 kmtr/bcae076fcdb253e2b286367b2407b160 to your computer and use it in GitHub Desktop.
Save kmtr/bcae076fcdb253e2b286367b2407b160 to your computer and use it in GitHub Desktop.
GoでI2C制御のAQM0802液晶を使う ref: http://qiita.com/kmtr/items/6f61d2e1609ae83ce5c4
$ env GOOS=linux GOARCH=arm GOARM=7 go build
$ sudo raspi-config
1 Advanced Options
A7 I2C
Yes
Finish
$ sudo rmmod i2c-dev i2c-bcm2708
$ sudo modprobe i2c-bcm2708 baudrate=50000
$ sudo modprobe i2c-dev
dev := i2c.New(0x3e, 1)
dev := i2c.New(0x3e, 1)
dev.Write([]byte{0x0, 0x38})
const (
wait = 26300 * time.Nanosecond
)
func cmd(dev *i2c.I2C, b byte) {
dev.Write([]byte{0x0, b})
time.Sleep(wait)
}
func write(dev *i2c.I2C, s string) {
chars := []byte(s)
dev.Write(append([]byte{0x40}, chars...))
time.Sleep(wait)
}
package main
import (
"time"
"github.com/davecheney/i2c"
)
const (
wait = 26300 * time.Nanosecond
)
func cmd(dev *i2c.I2C, b byte) {
dev.Write([]byte{0x0, b})
time.Sleep(wait)
}
func write(dev *i2c.I2C, s string) {
chars := []byte(s)
dev.Write(append([]byte{0x40}, chars...))
time.Sleep(wait)
}
func main() {
dev, _ := i2c.New(0x3e, 1)
cmd(dev, 0x38)
cmd(dev, 0x39)
cmd(dev, 0x14)
cmd(dev, 0x70)
cmd(dev, 0x56)
cmd(dev, 0x6c)
time.Sleep(200 * time.Millisecond)
cmd(dev, 0x38)
cmd(dev, 0x0c)
cmd(dev, 0x01)
time.Sleep(1080 * time.Microsecond)
write(dev, "Origami")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment