tinygo
tinygo copied to clipboard
TinyGo support for SSD1306
I have tested both an Arduino Nano and ESP32 module with the SSD1306 OLED module while using the Go machine package with the tinygo SSD1306 driver ("tinygo.org/x/drivers/ssd1306"). It seems no matter how I flash TinyGo code to the modules the SSD1306 will not work. I'm certain this is a configuration issue as I'm able to flash LEDs and button controls to the pins. Please let me know if there's a resolution on this that I'm missing out on.
For reference, this is my code to print "Hello world!" on the OLED screen:
package main
import (
"time"
"github.com/tinygo-org/tinygo/src/machine"
"tinygo.org/x/drivers/ssd1306"
)
func main() {
// Initialize I2C
machine.I2C0.Configure(machine.I2CConfig{
SCL: machine.IO22,
SDA: machine.IO21,
})
// Initialize the SSD1306 display
display := ssd1306.NewI2C(machine.I2C0)
display.Configure(ssd1306.Config{
Width: 128,
Height: 64,
})
display.ClearBuffer()
drawText(&display, 0, 0, "Hello World!")
display.Display()
for {
time.Sleep(time.Second)
}
}
func drawText(display *ssd1306.Device, x int16, y int16, text string) {
for i := int16(0); i < int16(len(text)); i++ {
display.SetPixel(x+i*6, y, 1) // Basic "dot" rendering for each character
}
}
This is the error message I get:
# github.com/tinygo-org/tinygo/src/machine
../../../../../go/pkg/mod/github.com/tinygo-org/[email protected]/src/machine/machine_esp32_i2c.go:38:16: undefined: SCL_PIN
../../../../../go/pkg/mod/github.com/tinygo-org/[email protected]/src/machine/machine_esp32_i2c.go:41:16: undefined: SDA_PIN
For the ESP32 you need to specify a board, not just -target=esp32.
I don't know what's up with the Arduino Nano, does it produce the same error message?
The import
import (
"github.com/tinygo-org/tinygo/src/machine"
)
Is not valid. It should be only:
import (
"machine"
)
Closing since question appears to have been answered. Please reopen if needed.