Skip to content

A learning project to interact with Raspberry Pi using periph.io

Notifications You must be signed in to change notification settings

oklahomer/go-raspi-training

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This repository contains some example codes and instructions to use periph.io library for Raspberry Pi interaction. Six years ago, the author used Python to work with Raspberry Pi and it worked pretty well. As a matter of fact, reading picamera's code and trying out its latest feature was a lot of fun.

Lately, the author prefers to write Golang for private project in favor of type-safety and compiled single binary. This project aims to prep the author to use Golang for Raspberry Pi interaction.

Periph.io's library is used as it has no C dependency, and hence cross-compilation is easier.

Examples

Cross Compile

Take a look at uname -a output to decide options to cross-compile Go code.

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 5.4.35-v7l+ #1314 SMP Fri May 1 17:47:34 BST 2020 armv7l GNU/Linux
pi@raspberrypi:~ $ cat /proc/cpuinfo
processor	: 0
model name	: ARMv7 Processor rev 3 (v7l)
BogoMIPS	: 135.00
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xd08
CPU revision	: 3

processor	: 1
model name	: ARMv7 Processor rev 3 (v7l)
BogoMIPS	: 135.00
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xd08
CPU revision	: 3

processor	: 2
model name	: ARMv7 Processor rev 3 (v7l)
BogoMIPS	: 135.00
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xd08
CPU revision	: 3

processor	: 3
model name	: ARMv7 Processor rev 3 (v7l)
BogoMIPS	: 135.00
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xd08
CPU revision	: 3

Hardware	: BCM2711
Revision	: b03112
Serial		: 100000002d01a8c3
Model		: Raspberry Pi 4 Model B Rev 1.2

The above output indicates the Raspberry Pi's model is ARMv7. For such model, The official GoArm wiki tells to use the GOARM value of 7 and GOARCH value of arm for build.

$ env GOOS=linux GOARCH=arm GOARM=7 go build ./example/XXX-foo-bar/main.go

To run this, scp the resulting executable to the Raspberry Pi as below. Remember the IP address varies.

scp main pi@192.168.2.111:~/main
pi@192.168.2.111's password: 
main

About

A learning project to interact with Raspberry Pi using periph.io

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages