SlideShare a Scribd company logo
EXPLORANDO GOLANG
EM AMBIENTE EMBARCADO
Alvaro Viebrantz
aviebrantz.com
@alvaroviebrantz
Alvaro Viebrantz
@alvaroviebrantz
aviebrantz.com
Google Developer Expert for IoT
Product Engineer @ Leverege
Organizador do GDG Cuiabá e DevMT
Explorando Go em Ambiente Embarcado
WEB SYSTEM LEVEL
& CONTAINERS
DATABASES &
MONITORING
MACHINE LEARNING
& DATA SCIENCE
MOBILE NATIVE WEB (?)SERVER
Use Cases
EMBARCADOS!
MICRO CONTROLADOR (MCU)
VS
SINGLE BOARD COMPUTER (SBC)
EMGO - Bare metal Go
Golang infelizmente não tem um bom suporte para micro controladores
github.com/ziutek/emgo
Embedded Rust
O Ecossistema Rust está mais maduro nisso
VS
github.com/rust-embedded
VAMOS FOCAR EM LINUX E 

SINGLE BOARD COMPUTERS
VANTAGENS
FOOTPRINT BAIXO (CPU/MEM)
DEPLOY COM UM ÚNICO BINÁRIO
MORE ON: GITHUB.COM/RAKYLL/GO-HARDWARE
PERIPH.IO GOBOT.IO
GOBOT.IO
MAIS FÁCIL DE INICIAR
FOCO EM CONECTIVIDADE E NÃO O ACESSO AO HARDWARE
FOCO NO ACESSO AO HARDWARE E SUPORTE A MÚLTIPLAS PLACAS
MAIS BAIXO NÍVEL
PERIPH.IO
“AMBIENTE DE DESENVOLVIMENTO”
E CROSS COMPILE
$ go build main.go
$ GOOS=? GOARCH=? go build main.go
$ GOOS=? GOARCH=? go build main.go
• GOOS - linux, darwin, windows, android,
dragonfly, freebsd, netbsd, openbsd, plan9,
solaris.
• GOARCH - amd64, 386, arm, arm64, ppc64le, ppc64,
mips64le, mips64, mipsle, mips and s390x.
$ GOOS=? GOARCH=? go build main.go
• GOOS - linux
• GOARCH - arm (32-bit ARM), arm64 (64-bit ARM),
mips64le (MIPS 64-bit, little-endian), mips64 (MIPS
64-bit, big-endian), mipsle (MIPS 32-bit, little-
endian), mips (MIPS 32-bit, big-endian).
$ GOOS=? GOARCH=? go build main.go
• GOOS - linux
• GOARCH - arm and mips
-ldflags="-s -w"
Quick tip:
to strip debugging info
build:
    GOOS=linux GOARCH=arm go build -ldflags="-s -w" -o robot-arm main.go
    
copy:
    rsync -P -a robot-arm pi@orangepizero.local:/home/pi/go
$ make build copy
PLAQUINHAS, PLAQUINHAS,
PLAQUINHAS
Raspberry Pi 3 👑
+ Ecossistema gigante
+ Wifi e Bluetooth embutido
+ Muito material na internet
+ CPU ARMv8 e 1Gb de ram
Orange Pi Zero 🍊
- Documentação ruim
+ Wifi e Bluetooth embutido
+ Muito barato
+ CPU ARMv6 e 512mb de ram
Onion Omega2
+ Low Profile
+ Larga escala
+ Wifi embutido
+ CPU MIPS e 64mb de ram
BeagleBone 🐶
Orange Pi Plus 2🍊
Raspberry Pi Zero 👑
Banana Pi M3 🍌
COMO É FEITA A COMUNICAÇÃO
COM O HARDWARE ?
CPU REGISTERS VS SYSFS
@ IOmemory.s
@ Opens the /dev/gpiomem device and maps GPIO memory
@ into program virtual address space.
@ 2017-09-29: Bob Plantz
@ Define my Raspberry Pi
.cpu cortex-a53
.fpu neon-fp-armv8
.syntax unified @ modern syntax
@ Constants for assembler
@ The following are defined in /usr/include/asm-generic/fcntl.h:
@ Note that the values are specified in octal.
.equ O_RDWR,00000002 @ open for read/write
.equ O_DSYNC,00010000 @ synchronize virtual memory
.equ #__O_SYNC,04000000 @ programming changes with
.equ O_SYNC,#__O_SYNC|O_DSYNC @ I/O memory
@ The following are defined in /usr/include/asm-generic/mman-common.h:
.equ PROT_READ,0x1 @ page can be read
.equ PROT_WRITE,0x2 @ page can be written
.equ MAP_SHARED,0x01 @ share changes
@ The following are defined by me:
.equ PERIPH,0x3f000000 @ RPi 2 & 3 peripherals
@ .equ PERIPH,0x20000000 @ RPi zero & 1 peripherals
.equ GPIO_OFFSET,0x200000 @ start of GPIO device
.equ O_FLAGS,O_RDWR|O_SYNC @ open file flags
.equ PROT_RDWR,PROT_READ|PROT_WRITE
.equ NO_PREF,0
.equ PAGE_SIZE,4096 @ Raspbian memory page
.equ FILE_DESCRP_ARG,0 @ file descriptor
.equ DEVICE_ARG,4 @ device address
.equ STACK_ARGS,8 @ sp already 8-byte aligned
@ Constant program data
.section .rodata
.align 2
CPU Register #-> /dev/gpiomem
CPU REGISTERS VS SYSFS
____ _ ____
/ #__ ___ (_)#__ ___ / #__ #__ _ ___ ___ ____ _
/ /_/ / _ / / _ / _  / /_/ / ' / -_) _ `/ _ `/
____/_#//_/_/___/_#//_/ ____/_/_/_/#__/_, /_,_/
W H A T W I L L Y O U I N V E N T ? /___/
-----------------------------------------------------
Ω-ware: 0.1.10 b160
-----------------------------------------------------
root@Omega-5D69:~# ls /sys/class/
bdi firmware i2c-dev mem net ppp
scsi_host tty
block gpio input misc pci_bus pwm
sound video4linux
bluetooth hidraw leds mmc_host phy scsi_device
spi_master watchdog
dma i2c-adapter mdio_bus mtd power_supply scsi_disk
spidev
root@Omega-5D69:~# ls /sys/class/gpio/
export gpio11 gpio16 gpio17 gpiochip0 gpiochip32 gpiochip64
unexport
base device/ label ngpio subsystem/ uevent
sysFS
root@Omega-5D69:~# echo out > /sys/class/gpio/gpio11/direction
root@Omega-5D69:~# echo 1 > /sys/class/gpio/gpio11/value
root@Omega-5D69:~# echo 0 > /sys/class/gpio/gpio11/value
Blink a LED with sysFS
TEM SUPORTE PARA SYSFS E CPU REGISTERS
ESCOLHE A MELHOR IMPLEMENTAÇÃO DISPONÍVEL
PERIPH.IO
MÃO NA MASSA
VAMOS MONTAR UMA
ESTAÇÃO METEOROLÓGICA
github.com/alvarowolfx/golang-iot-weather-station
!33
34
Onion Omega2
BMP280
Sensor de Temperatura
e Pressão
TM1637
Driver display 4 digitos
VAMOS PROGRAMAR!
INICIALIZAÇÃO
GPIO

GENERAL PURPOSE
INPUT/OUTPUT
38
ATENÇÃO!!! CADA PLACA TEM UM ESQUEMA DE NOMES PARA GPIO
DIGITAL
GPIO - SAÍDA
GPIO - LEITURA
SENSORES

DIGITAIS E ANALÓGICOS
COMUNICAÇÃO SERIAL
44
Comunicação Serial
Padrões mais conhecidos e utilizados
• I2C (Síncrono e padrão Master/Slave) - Tipicamente utilizado por sensores
digitais.
• SPI (Síncrono e alta taxa de transmissão) - Tipicamente usado em Display
gráficos e numéricos.
• UART (Assíncrono) - Tipicamente usado em módulos de Radio, GPS,
Displays LCD, Debug Serial, etc.
Sensor de Temperatura e Pressão - BMP280
SPI e I²C
I²C - Acesso ao barramento
BMxx80 - Acesso ao sensor
Display de 4 Digitos - tm1637
Protocolo próprio
TM1637 - Mostrando digitos
O QUE FAZER COM ISSO ?
INFINITAS POSSIBILIDADES COM GOLANG
Abstração
package http
HTTP Server
HTTP Server
HTTP Server
OpenCensus: A Stats Collection and Distributed
Tracing Framework
opencensus.io
OpenCensus
Armazenamento e sincronização em tempo real
• Coletar métricas
• Trace da aplicação
• Vendor Agnostic
• Diversas linguagens
• Go, Java, Node, C++, Python, etc
• Diversos Exporters
• Stackdriver, Datadog, Prometheus, Zipkin,
Jaeger
Metrics
Metrics views
Metrics views
DEMO TIME

MAY THE DEMO GODS BE WITH US
SEGUNDO PROJETO

GOPHER ROBOTIC ARM
github.com/alvarowolfx/golang-voice-iot
Explorando Go em Ambiente Embarcado
65
PCA9685
Module de 16 Canais PWM
Orange Pi Zero 🍊
4x Micro Servo Motores
MeArm
Garra robotica Open Source
COMUNICAÇÃO SERIAL
PWM - PULSE WIDTH MODULATION
68
PCA9685
Module de 16 Canais PWM
PERIPH.IO
+ = (?)
69
YOU CAN PORT AN EXISTING DRIVER
FROM ANOTHER ECOSYSTEM
ARDUINO, ANDROID THINGS, PYTHON
INFINITAS POSSIBILIDADES COM GOLANG
[2]
Abstrações
Goroutines FTW
Explorando Go em Ambiente Embarcado
Explorando Go em Ambiente Embarcado
Explorando Go em Ambiente Embarcado
Cloud IoT Core MQTT
Move Arm
DEMO TIME [2]

MAY THE DEMO GODS BE WITH US - AGAIN
Explorando Go em Ambiente Embarcado
Explorando Go em Ambiente Embarcado
PROXIMOS PASSOS
83
Próximos passos
Explorar ainda mais Golang em Ambiente embarcado
• Cgo + cross compile - Ainda não é tão fácil de fazer
• Updates Over the air (OTA) - Atualizar um device apenas com um binário
novo.
• Cenário de Gateway IoT - Alta performance na ponta coletando dados,
armazenando e sincronizando com a nuvem
• IA/ML na ponta - Usar Golang + ML em embarcado na ponta.
• Cameras e Microfones - Também são sensores
GOSTEI DE IOT
E AGORA ?
Blog posts
Dois tutoriais com arquitetura completa de IoT e Google Cloud
Explorando Go em Ambiente Embarcado
""www.iotforall.com
OBRIGADO
Alvaro Viebrantz
aviebrantz.com
@alvaroviebrantz

More Related Content

PDF
My First AMD EPYC 7251 memo
PDF
x86_64 Hardware Deep dive
PDF
SPDK benchmark memo
PPTX
Raspberry Pi I/O控制與感測器讀取
PPTX
QNAP Portafolio 2015
PPTX
QNAP Selection Guide 2015
PDF
Perl on embedded Linux with Buildroot‎
PDF
Webサービスのための 10/40Gigabit Ethernetの可能性
My First AMD EPYC 7251 memo
x86_64 Hardware Deep dive
SPDK benchmark memo
Raspberry Pi I/O控制與感測器讀取
QNAP Portafolio 2015
QNAP Selection Guide 2015
Perl on embedded Linux with Buildroot‎
Webサービスのための 10/40Gigabit Ethernetの可能性

What's hot (18)

PDF
Debian Linux on Zynq (Xilinx ARM-SoC FPGA) Setup Flow (Vivado 2015.4)
PDF
Introduction GStreamer
PDF
Red Hat, CentOS, Fedora 2019
PPT
Sensors, actuators and the Raspberry PI using Python
PDF
Control-M 800 - Infrastructure Example
PDF
LPC2019 BPF Tracing Tools
PDF
redis-benchmark with AMD RYZEN 1800X memo
PDF
Authen Free Bsd6 2
PDF
Android Development Tools
PPTX
Cpu高效编程技术
PPTX
移植FreeRTOS 之嵌入式軟體研究與開發
PDF
Linux kernel-rootkit-dev - Wonokaerun
PDF
OpenCR
PDF
Kernel development
PDF
Aula 07 pino 1 e soquetes
PDF
ERP System Implementation Kubernetes Cluster with Sticky Sessions
PPTX
Nomenclatura QNAP
ODP
La Fonera 2.0 で遊ぶ~導入編~ 2009年9月のオフな集まり(第87 回)
Debian Linux on Zynq (Xilinx ARM-SoC FPGA) Setup Flow (Vivado 2015.4)
Introduction GStreamer
Red Hat, CentOS, Fedora 2019
Sensors, actuators and the Raspberry PI using Python
Control-M 800 - Infrastructure Example
LPC2019 BPF Tracing Tools
redis-benchmark with AMD RYZEN 1800X memo
Authen Free Bsd6 2
Android Development Tools
Cpu高效编程技术
移植FreeRTOS 之嵌入式軟體研究與開發
Linux kernel-rootkit-dev - Wonokaerun
OpenCR
Kernel development
Aula 07 pino 1 e soquetes
ERP System Implementation Kubernetes Cluster with Sticky Sessions
Nomenclatura QNAP
La Fonera 2.0 で遊ぶ~導入編~ 2009年9月のオフな集まり(第87 回)
Ad

Similar to Explorando Go em Ambiente Embarcado (20)

PDF
JavaScript all the things! - FullStack 2017
PDF
Trying and evaluating the new features of GlusterFS 3.5
PPT
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...
PDF
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
PPTX
Rsockets ofa12
PDF
Ubuntu core on bubblegum 96
PDF
Ubuntu core on bubblegum 96
PDF
DAOS - Scale-Out Software-Defined Storage for HPC/Big Data/AI Convergence
PPTX
C# Production Debugging Made Easy
PDF
26.1.7 lab snort and firewall rules
PDF
Embedded. What Why How
DOC
How to put 10lbs of functionality into a 5lb package.
TXT
Readme
PDF
Android 5.0 Lollipop platform change investigation report
PDF
JavaOne 2014: Java Debugging
PDF
DEF CON 27 - GRICHTER - reverse engineering 4g hotspots for fun bugs net fina...
PDF
Chicago Docker Meetup Presentation - Mediafly
PDF
App container rkt
PDF
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
PDF
The NECSTLab Multi-Faceted Experience with AWS F1
JavaScript all the things! - FullStack 2017
Trying and evaluating the new features of GlusterFS 3.5
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
Rsockets ofa12
Ubuntu core on bubblegum 96
Ubuntu core on bubblegum 96
DAOS - Scale-Out Software-Defined Storage for HPC/Big Data/AI Convergence
C# Production Debugging Made Easy
26.1.7 lab snort and firewall rules
Embedded. What Why How
How to put 10lbs of functionality into a 5lb package.
Readme
Android 5.0 Lollipop platform change investigation report
JavaOne 2014: Java Debugging
DEF CON 27 - GRICHTER - reverse engineering 4g hotspots for fun bugs net fina...
Chicago Docker Meetup Presentation - Mediafly
App container rkt
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
The NECSTLab Multi-Faceted Experience with AWS F1
Ad

More from Alvaro Viebrantz (20)

PDF
Construindo Apps/Projetos com Generative AI
PDF
Minha jornada na ciência da computação- do diploma ao Google
PDF
BigQuery Performance Improvements Storage API
PDF
End to End IoT projects with Zephyr.pdf
PDF
Carreira de Desenvolvimento
PDF
Construindo aplicações Cloud Native em Go
PDF
Prototipação em hackathons
PDF
Building REST APIs using gRPC and Go
PDF
TinyML - IoT e Machine Learning
PDF
O que projetos de IoT precisam ?
PDF
Ambiente de CI/CD com Google Cloud
PDF
Big Query - Escalabilidade Infinita para os seus Dados
PDF
Rodando uma API Com Django Rest Framework no Google Cloud
PDF
Edge computing na prática com IoT, Machine Learning e Google Cloud
PDF
Edge computing in practice using IoT, Tensorflow and Google Cloud
PDF
Iniciando com LoRa, The Things Network e Google Cloud
PDF
Construindo projetos para o Google Assistant - I/O 2019 Recap São Paulo
PDF
Edge computing na prática com IoT, Machine Learning e Google Cloud
PDF
Construindo projetos com Google Assistant e IoT
PDF
Soluções de IoT usando Arduino e Google Cloud
Construindo Apps/Projetos com Generative AI
Minha jornada na ciência da computação- do diploma ao Google
BigQuery Performance Improvements Storage API
End to End IoT projects with Zephyr.pdf
Carreira de Desenvolvimento
Construindo aplicações Cloud Native em Go
Prototipação em hackathons
Building REST APIs using gRPC and Go
TinyML - IoT e Machine Learning
O que projetos de IoT precisam ?
Ambiente de CI/CD com Google Cloud
Big Query - Escalabilidade Infinita para os seus Dados
Rodando uma API Com Django Rest Framework no Google Cloud
Edge computing na prática com IoT, Machine Learning e Google Cloud
Edge computing in practice using IoT, Tensorflow and Google Cloud
Iniciando com LoRa, The Things Network e Google Cloud
Construindo projetos para o Google Assistant - I/O 2019 Recap São Paulo
Edge computing na prática com IoT, Machine Learning e Google Cloud
Construindo projetos com Google Assistant e IoT
Soluções de IoT usando Arduino e Google Cloud

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Machine Learning_overview_presentation.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Encapsulation theory and applications.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
A Presentation on Artificial Intelligence
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PPT
Teaching material agriculture food technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
1. Introduction to Computer Programming.pptx
Spectroscopy.pptx food analysis technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Network Security Unit 5.pdf for BCA BBA.
Big Data Technologies - Introduction.pptx
Encapsulation_ Review paper, used for researhc scholars
Machine Learning_overview_presentation.pptx
Approach and Philosophy of On baking technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Encapsulation theory and applications.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
A Presentation on Artificial Intelligence
Programs and apps: productivity, graphics, security and other tools
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
Teaching material agriculture food technology
MIND Revenue Release Quarter 2 2025 Press Release
1. Introduction to Computer Programming.pptx

Explorando Go em Ambiente Embarcado