Skip to content

Commit d5e4ee9

Browse files
authored
nanopct6: introduce adaptor for FriendlyELEC NanoPC-T6 (hybridgroup#1126)
1 parent 270044e commit d5e4ee9

31 files changed

+990
-375
lines changed

MIGRATION.md

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ are listed here and a migration strategy is provided.
99

1010
## Switch from version 2.4.0 (applications using the gpiod options affected)
1111

12+
### NanoPi NEO adaptor was moved to friendlyelec folder
13+
14+
With introduce of FriendlyELEC NanoPC-T6 a second adaptor from FriendlyELEC (formerly friendlarm) now exists. Please
15+
search and replace to change the import path as follows.
16+
17+
```go
18+
// old
19+
...
20+
"gobot.io/x/gobot/v2/platforms/nanopi"
21+
...
22+
23+
// new
24+
...
25+
"gobot.io/x/gobot/v2/platforms/friendlyelec/nanopi"
26+
...
27+
```
28+
1229
### The term gpiod was renamed to cdev
1330

1431
Using the term "cdev" (short for character device Kernel ABI for GPIO access) is more suitable than using "gpiod" (the

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ platforms are currently supported:
252252
- [DJI Tello](https://www.ryzerobotics.com/tello) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/dji/tello)
253253
- [DragonBoard](https://developer.qualcomm.com/hardware/dragonboard-410c) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/dragonboard)
254254
- [ESP8266](http://esp8266.net/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/firmata)
255+
- [FriendlyELEC NanoPi NEO](https://wiki.friendlyelec.com/wiki/index.php/NanoPi_NEO) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/friendlyelec/nanopi)
256+
- [FriendlyELEC NanoPC-T6](https://wiki.friendlyelec.com/wiki/index.php/NanoPC-T6) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/friendlyelec/nanopct6)
255257
- [GoPiGo 3](https://www.dexterindustries.com/gopigo3/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/dexter/gopigo3)
256258
- [Intel Curie](https://www.intel.com/content/www/us/en/products/boards-kits/curie.html) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/intel-iot/curie)
257259
- [Intel Edison](http://www.intel.com/content/www/us/en/do-it-yourself/edison.html) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/intel-iot/edison)
@@ -264,7 +266,6 @@ platforms are currently supported:
264266
- [MegaPi](http://www.makeblock.com/megapi) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/megapi)
265267
- [Microbit](http://microbit.org/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/microbit)
266268
- [MQTT](http://mqtt.org/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/mqtt)
267-
- [NanoPi NEO](https://wiki.friendlyelec.com/wiki/index.php/NanoPi_NEO) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/nanopi)
268269
- [NATS](http://nats.io/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/nats)
269270
- [Neurosky](http://neurosky.com/products-markets/eeg-biosensors/hardware/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/neurosky)
270271
- [OpenCV](http://opencv.org/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/opencv)

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 36 is input, pin 37 used as normal output, pin 38 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 = "36"
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)