1
0
Fork 0
mirror of https://github.com/kidoman/embd synced 2025-07-03 03:47:33 +02:00

spi: finishing touches

This commit is contained in:
kunalpowar 2014-05-22 02:19:01 +05:30
parent 0f23150374
commit 67d316851a
7 changed files with 49 additions and 45 deletions

View file

@ -1,5 +1,6 @@
// +build ignore
// this sample uses the mcp3008 package to interface with the 8-bit ADC and works without code change on bbb and rpi
package main
import (
@ -7,9 +8,9 @@ import (
"fmt"
"time"
"github.com/kidoman/embd/convertors/mcp3008"
"github.com/kidoman/embd"
"github.com/kidoman/embd/convertors/mcp3008"
_ "github.com/kidoman/embd/host/all"
)
func main() {
@ -21,7 +22,11 @@ func main() {
}
defer embd.CloseSPI()
spiBus := embd.NewSPIBus(embd.SpiMode0, 0, 1000000, 8, 0)
channel := 0
speed := 1000000
bpw := 8
delay := 0
spiBus := embd.NewSPIBus(embd.SPIMode0, channel, speed, bpw, delay)
defer spiBus.Close()
adc := mcp3008.New(mcp3008.SingleMode, spiBus)

View file

@ -6,7 +6,6 @@ import (
"fmt"
"github.com/kidoman/embd"
_ "github.com/kidoman/embd/host/all"
)
@ -16,7 +15,7 @@ func main() {
}
defer embd.CloseSPI()
spiBus := embd.NewSPIBus(embd.SpiMode0, 0, 1000000, 8, 0)
spiBus := embd.NewSPIBus(embd.SPIMode0, 0, 1000000, 8, 0)
defer spiBus.Close()
dataBuf := []uint8{1, 2, 3}

View file

@ -18,12 +18,19 @@ func main() {
}
defer embd.CloseSPI()
bus := embd.NewSPIBus(embd.SpiMode0, 0, 1000000, 8, 0)
channel := 0
speed := 1000000
bpw := 8
delay := 0
bus := embd.NewSPIBus(embd.SPIMode0, channel, speed, bpw, delay)
defer bus.Close()
for i := 0; i < 30; i++ {
time.Sleep(1 * time.Second)
val, _ := getSensorValue(bus)
val, err := getSensorValue(bus)
if err != nil {
panic(err)
}
fmt.Printf("value is: %v\n", val)
}
}