I’m going to focus mostly on some design decisions and how I went about writing an SPI interface using Go on a Raspberry Pi. I assume my readers have a basic understanding of what a Raspberry Pi is, and how basic electronics work. If not, read on anyway and I will be sure to include some valuable resources below. Why Go? In a past life, I worked on hardware interfacing software, and the first thing I can tell you is that I hate C. Don’t get me wrong, I understand the appeal of having lightning-fast code and the ability to manipulate memory and low-level functions. I also understand the headache of writing concurrent C code, and anyone familiar with Go knows that this is where it shines. The project that first got me interested in using Go for embedded applications was one where we decided to use a Raspberry Pi Compute Module 3 to interact with ADC (analog to digital converter) components, and collect data using several of these components. I quickly threw together a prototype in Python using the standard , and was satisfied with the initial results. It was apparent however that for a more industrial solution we needed an application that was: Python GPIO library — Able to support more operations per second at lower memory and CPU usage. — We didn’t want anyone to be able to pop out the Compute Module and steal our source code. — We had a very small team, and none of us were very experienced with firmware so we wanted to abstract up a bit if possible. Faster Compiled Maintainable I considered C++ at first. C++ is about as fast as it gets, and is a compiled language. I’m quite comfortable in C++ and have written many applications using it, but we ultimately decided on Go instead for the simple fact the concurrent programming in Go is as easy as it gets. C++ may run a bit faster, but we knew that if we wrote this particular program in Go, it would likely be about half the size (in lines of code) and we were more confident in our ability to keep the code clean and maintainable. It is important to note that the program in question was doing a lot more than just the data collection via SPI interface with an ADC component. There were user inputs, data displays, etc. It was to be a highly concurrent program. What is SPI? http://www.circuitbasics.com/basics-of-the-spi-communication-protocol/ SPI stands for serial peripheral interface. I don’t want to get too far off track, but basically it is just a protocol for a master (your program) to communicate with the hardware (like a thermometer or analog to digital converter). If you want to learn more check out the link in the picture’s caption. My Environment Device: Raspberry Pi 3B (We used the compute module for production) IDE: VS Code Remote Editing: Check out this tutorial to edit code on the pi using VS Code remotely Hardware: Breadboard, jumper wires, an ADC that uses an SPI interface OS: Raspbian Implementation First things first, I needed a great GPIO package. For this project, we built the code to be able to use any of the GPIO pins on the Pi. I used Dave Cheney’s library: https://github.com/davecheney/gpio The code below should build and run. Please keep in mind that if you are going to use this code, you will need to change the pin numbers to match the pins you used to connect your GPIOs to your ADC. <code style="box-sizing: border-box; font-family: Consolas, &quot;Andale Mono WT&quot;, &quot;Andale Mono&quot;, &quot;Lucida Console&quot;, &quot;Lucida Sans Typewriter&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Liberation Mono&quot;, &quot;Nimbus Mono L&quot;, Monaco, &quot;Courier New&quot;, Courier, monospace; color: rgb(255, 255, 255); background-color: transparent; border: 0px; padding: 0px; font-size: 0.85em; border-radius: 3px;">package main ( "fmt" "time" "github.com/davecheney/gpio" ) // AdcRead represents the data needed a operation the ADC component AdcRead struct { Cs gpio.Pin Clock gpio.Pin Miso gpio.Pin NumBits ResultsChan chan uint32 } // Exec reads the stored the ADC register func (reader AdcRead) Exec() { // the CS Low the reader.Cs.Clear() // Initialize an impty uint32 store the we are reading var result uint32 // the the component sends back (The number varies // component component, the datasheet) i := ; i &lt; reader.NumBits; i++ { // the clock logic high reader.Clock. () // , it high, a "1" our rightmost := reader.Miso. () { result |= } // Shift Left the next be i != reader.NumBits { result &lt;&lt;= } // The clock will pulse low, high again the next reader.Clock.Clear() } // chip low the reader.Cs. () // Send the result back through the channel whatever part our // application cares about it reader.ResultsChan &lt;- result } func main() { // necessary pins. The numbers here are examples, they should be changed based // which pins you use const csPinNumber = const clockPinNumber = const misoPinNumber = csPin, err := gpio.OpenPin(csPinNumber, gpio.ModeOutput) err != nil { fmt.Printf("Error opening cs pin: %v\n", err) } clockPin, err := gpio.OpenPin(clockPinNumber, gpio.ModeOutput) err != nil { fmt.Printf("Error opening clock pin: %v\n", err) } misoPin, err := gpio.OpenPin(misoPinNumber, gpio.ModeInput) err != nil { fmt.Printf("Error opening miso pin: %v\n", err) } resultsChan := make(chan uint32, ) adcReader := AdcRead{ Cs: csPin, Clock: clockPin, Miso: misoPin, NumBits: , // Our ADC component sends a ResultsChan: resultsChan, } // at Hz c := .Tick( .Duration( ) * .Millisecond) go func() { range c { adcReader.Exec() } }() // Print everything that comes through the results channel { result := &lt;-resultsChan fmt.Println(result) } }</code> import to perform read on type int current value in Start to begin read to value Loop over each bit depends from to read for 0 Set to Set Read 1 bit in if is then add to bit bit Get if bit 0x1 to get to bit to read if -1 1 then to get bit Set select to end read Set to of Open on 5 6 7 if if if 1 32 32 bit value Execute each read 10 time time 100 time for for true View repository: https://github.com/lane-c-wagner/spi Thanks For Reading Lane on Twitter: @wagslane Lane on Dev.to: wagslane Download Qvault: https://qvault.io Star our Github: https://github.com/q-vault/qvault (Originally published ) here ( : ) Disclaimer The Author is the Founder at qvault