Skip to content

Commit d3ef28b

Browse files
committed
nanopct6: introduce adaptor for FriendlyELEC NanoPC-T6
1 parent 50da9ae commit d3ef28b

18 files changed

+956
-359
lines changed

examples/edison_grove_blink.go

-39
This file was deleted.

examples/edison_grove_button.go

-40
This file was deleted.

examples/edison_grove_led.go

-39
This file was deleted.

examples/edison_grove_touch.go

-40
This file was deleted.

examples/nanopct6_direct_pin.go

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//go:build example
2+
// +build example
3+
4+
//
5+
// Do not build by default.
6+
7+
package main
8+
9+
import (
10+
"fmt"
11+
"time"
12+
13+
"gobot.io/x/gobot/v2"
14+
"gobot.io/x/gobot/v2/drivers/gpio"
15+
"gobot.io/x/gobot/v2/platforms/adaptors"
16+
"gobot.io/x/gobot/v2/platforms/friendlyelec/nanopct6"
17+
)
18+
19+
// Wiring
20+
// PWR : 1, 17 (+3.3V, VCC), 2, 4 (+5V), 6, 9, 14, 20, 25, 30, 34, 39 (GND)
21+
// GPIO : header pin 21 is input, pin 24 used as normal output, pin 26 used as inverted output
22+
// Button: the input pin is wired with a button to GND, the internal pull up resistor is used
23+
// LED's: the output pins are wired to the cathode of the LED, the anode is wired with a resistor (70-130Ohm for 20mA)
24+
// to VCC
25+
// Expected behavior: always one LED is on, the other in opposite state, if button is pressed for >2 seconds the state
26+
// changes
27+
func main() {
28+
const (
29+
inPinNum = "40"
30+
outPinNum = "37"
31+
outPinInvertedNum = "38"
32+
debounceTime = 2 * time.Second
33+
)
34+
// note: WithGpiosOpenDrain() is optional, if using WithGpiosOpenSource() the LED's will not light up
35+
board := nanopct6.NewAdaptor(adaptors.WithGpiosActiveLow(outPinInvertedNum),
36+
adaptors.WithGpiosOpenDrain(outPinNum, outPinInvertedNum),
37+
adaptors.WithGpiosPullUp(inPinNum),
38+
adaptors.WithGpioDebounce(inPinNum, debounceTime))
39+
40+
inPin := gpio.NewDirectPinDriver(board, inPinNum)
41+
outPin := gpio.NewDirectPinDriver(board, outPinNum)
42+
outPinInverted := gpio.NewDirectPinDriver(board, outPinInvertedNum)
43+
44+
work := func() {
45+
level := byte(1)
46+
47+
gobot.Every(500*time.Millisecond, func() {
48+
read, err := inPin.DigitalRead()
49+
fmt.Printf("pin %s state is %d\n", inPinNum, read)
50+
if err != nil {
51+
fmt.Println(err)
52+
if level == 1 {
53+
level = 0
54+
} else {
55+
level = 1
56+
}
57+
} else {
58+
level = byte(read)
59+
}
60+
61+
err = outPin.DigitalWrite(level)
62+
fmt.Printf("pin %s is now %d\n", outPinNum, level)
63+
if err != nil {
64+
fmt.Println(err)
65+
}
66+
67+
err = outPinInverted.DigitalWrite(level)
68+
fmt.Printf("pin %s is now not %d\n", outPinInvertedNum, level)
69+
if err != nil {
70+
fmt.Println(err)
71+
}
72+
})
73+
}
74+
75+
robot := gobot.NewRobot("pinBot",
76+
[]gobot.Connection{board},
77+
[]gobot.Device{inPin, outPin, outPinInverted},
78+
work,
79+
)
80+
81+
if err := robot.Start(); err != nil {
82+
panic(err)
83+
}
84+
}

examples/nanopct6_ds18b20.go

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//go:build example
2+
// +build example
3+
4+
//
5+
// Do not build by default.
6+
7+
package main
8+
9+
import (
10+
"fmt"
11+
"log"
12+
"time"
13+
14+
"gobot.io/x/gobot/v2"
15+
"gobot.io/x/gobot/v2/drivers/onewire"
16+
"gobot.io/x/gobot/v2/platforms/friendlyelec/nanopct6"
17+
)
18+
19+
// Preparation: see /gobot/system/ONEWIRE.md
20+
//
21+
// Wiring:
22+
// PWR : 1, 17 (+3.3V, VCC), 6, 9, 14, 20, 25, 30, 34, 39 (GND)
23+
// 1-wire : 16 (DQ) - resistor to VCC, ~1.5kOhm ... 5kOhm
24+
// DS18B20: 1 (GND), 2 (DQ), 3 (VDD, +3 ... 5.5V) for local power mode
25+
func main() {
26+
adaptor := nanopct6.NewAdaptor()
27+
// resolution change not supported by all devices
28+
temp0 := onewire.NewDS18B20Driver(adaptor, 0xde5e710a6461, onewire.WithResolution(12))
29+
temp1 := onewire.NewDS18B20Driver(adaptor, 0x1e40710a6461, onewire.WithFahrenheit(), onewire.WithConversionTime(500))
30+
31+
work := func() {
32+
time0, err := temp0.ConversionTime()
33+
if err != nil {
34+
log.Printf("Err CT0: %v\n", err)
35+
}
36+
res0, err := temp0.Resolution()
37+
if err != nil {
38+
log.Printf("Err R0: %v\n", err)
39+
}
40+
log.Printf("Conversion time @%d bit for Temp 0: %d ms\n", res0, time0)
41+
42+
time1, err := temp1.ConversionTime()
43+
if err != nil {
44+
log.Printf("Err CT1: %v\n", err)
45+
}
46+
res1, err := temp1.Resolution()
47+
if err != nil {
48+
log.Printf("Err R1: %v\n", err)
49+
}
50+
log.Printf("Conversion time @%d bit for Temp 0: %d ms\n", res1, time1)
51+
52+
gobot.Every(10*(time.Duration(time0))*time.Millisecond, func() {
53+
t0, err := temp0.Temperature()
54+
if err != nil {
55+
log.Printf("Err Temp 0: %v\n", err)
56+
}
57+
58+
fmt.Printf("Temp 0: %2.1f °C\n", t0)
59+
})
60+
61+
gobot.Every(10*(time.Duration(time1))*time.Millisecond, func() {
62+
t1, err := temp1.Temperature()
63+
if err != nil {
64+
log.Printf("Err Temp 1: %v\n", err)
65+
}
66+
67+
fmt.Printf("Temp 1: %2.3f °F\n", t1)
68+
})
69+
}
70+
71+
robot := gobot.NewRobot("onewireBot",
72+
[]gobot.Connection{adaptor},
73+
[]gobot.Device{temp0, temp1},
74+
work,
75+
)
76+
77+
if err := robot.Start(); err != nil {
78+
panic(err)
79+
}
80+
}

0 commit comments

Comments
 (0)