Skip to content

Instantly share code, notes, and snippets.

@gocs
Last active July 19, 2022 06:06
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 gocs/4192c3165670130b57a75f13038da179 to your computer and use it in GitHub Desktop.
Save gocs/4192c3165670130b57a75f13038da179 to your computer and use it in GitHub Desktop.
why does usb serial prints unreadable �? identify your usb's BAUD `stty -F /dev/ttyUSB0`
package main
import (
"bufio"
"fmt"
"github.com/tarm/serial"
)
func main() {
c := &serial.Config{Name: "/dev/ttyUSB0", Baud: 115200}
s, err := serial.OpenPort(c)
if err != nil {
fmt.Println(err)
return
}
scanner := bufio.NewScanner(s)
for scanner.Scan() {
fmt.Println(scanner.Text()) // Println will add back the final '\n'
}
if err := scanner.Err(); err != nil {
fmt.Println(err)
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment