Skip to content

Commit

Permalink
nanopct6: introduce adaptor for FriendlyELEC NanoPC-T6
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2thomas committed Jan 18, 2025
1 parent 50da9ae commit f5b17ca
Show file tree
Hide file tree
Showing 31 changed files with 990 additions and 375 deletions.
17 changes: 17 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ are listed here and a migration strategy is provided.

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

### NanoPi NEO adaptor was moved to friendlyelec folder

With introduce of FriendlyELEC NanoPC-T6 a second adaptor from FriendlyELEC (formerly friendlarm) now exists. Please
search and replace to change the import path as follows.

```go
// old
...
"gobot.io/x/gobot/v2/platforms/nanopi"
...

// new
...
"gobot.io/x/gobot/v2/platforms/friendlyelec/nanopi"
...
```

### The term gpiod was renamed to cdev

Using the term "cdev" (short for character device Kernel ABI for GPIO access) is more suitable than using "gpiod" (the
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ platforms are currently supported:
- [DJI Tello](https://www.ryzerobotics.com/tello) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/dji/tello)
- [DragonBoard](https://developer.qualcomm.com/hardware/dragonboard-410c) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/dragonboard)
- [ESP8266](http://esp8266.net/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/firmata)
- [FriendlyELEC NanoPi NEO](https://wiki.friendlyelec.com/wiki/index.php/NanoPi_NEO) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/friendlyelec/nanopi)
- [FriendlyELEC NanoPC-T6](https://wiki.friendlyelec.com/wiki/index.php/NanoPC-T6) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/friendlyelec/nanopct6)
- [GoPiGo 3](https://www.dexterindustries.com/gopigo3/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/dexter/gopigo3)
- [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)
- [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)
Expand All @@ -264,7 +266,6 @@ platforms are currently supported:
- [MegaPi](http://www.makeblock.com/megapi) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/megapi)
- [Microbit](http://microbit.org/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/microbit)
- [MQTT](http://mqtt.org/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/mqtt)
- [NanoPi NEO](https://wiki.friendlyelec.com/wiki/index.php/NanoPi_NEO) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/nanopi)
- [NATS](http://nats.io/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/nats)
- [Neurosky](http://neurosky.com/products-markets/eeg-biosensors/hardware/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/neurosky)
- [OpenCV](http://opencv.org/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/opencv)
Expand Down
39 changes: 0 additions & 39 deletions examples/edison_grove_blink.go

This file was deleted.

40 changes: 0 additions & 40 deletions examples/edison_grove_button.go

This file was deleted.

39 changes: 0 additions & 39 deletions examples/edison_grove_led.go

This file was deleted.

40 changes: 0 additions & 40 deletions examples/edison_grove_touch.go

This file was deleted.

84 changes: 84 additions & 0 deletions examples/nanopct6_direct_pin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//go:build example
// +build example

//
// Do not build by default.

package main

import (
"fmt"
"time"

"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/platforms/adaptors"
"gobot.io/x/gobot/v2/platforms/friendlyelec/nanopct6"
)

// Wiring
// PWR : 1, 17 (+3.3V, VCC), 2, 4 (+5V), 6, 9, 14, 20, 25, 30, 34, 39 (GND)
// GPIO : header pin 21 is input, pin 24 used as normal output, pin 26 used as inverted output
// Button: the input pin is wired with a button to GND, the internal pull up resistor is used
// LED's: the output pins are wired to the cathode of the LED, the anode is wired with a resistor (70-130Ohm for 20mA)
// to VCC
// Expected behavior: always one LED is on, the other in opposite state, if button is pressed for >2 seconds the state
// changes
func main() {
const (
inPinNum = "40"
outPinNum = "37"
outPinInvertedNum = "38"
debounceTime = 2 * time.Second
)
// note: WithGpiosOpenDrain() is optional, if using WithGpiosOpenSource() the LED's will not light up
board := nanopct6.NewAdaptor(adaptors.WithGpiosActiveLow(outPinInvertedNum),
adaptors.WithGpiosOpenDrain(outPinNum, outPinInvertedNum),
adaptors.WithGpiosPullUp(inPinNum),
adaptors.WithGpioDebounce(inPinNum, debounceTime))

inPin := gpio.NewDirectPinDriver(board, inPinNum)
outPin := gpio.NewDirectPinDriver(board, outPinNum)
outPinInverted := gpio.NewDirectPinDriver(board, outPinInvertedNum)

work := func() {
level := byte(1)

gobot.Every(500*time.Millisecond, func() {
read, err := inPin.DigitalRead()
fmt.Printf("pin %s state is %d\n", inPinNum, read)
if err != nil {
fmt.Println(err)
if level == 1 {
level = 0
} else {
level = 1
}
} else {
level = byte(read)
}

err = outPin.DigitalWrite(level)
fmt.Printf("pin %s is now %d\n", outPinNum, level)
if err != nil {
fmt.Println(err)
}

err = outPinInverted.DigitalWrite(level)
fmt.Printf("pin %s is now not %d\n", outPinInvertedNum, level)
if err != nil {
fmt.Println(err)
}
})
}

robot := gobot.NewRobot("pinBot",
[]gobot.Connection{board},
[]gobot.Device{inPin, outPin, outPinInverted},
work,
)

if err := robot.Start(); err != nil {
panic(err)
}
}
80 changes: 80 additions & 0 deletions examples/nanopct6_ds18b20.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//go:build example
// +build example

//
// Do not build by default.

package main

import (
"fmt"
"log"
"time"

"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/onewire"
"gobot.io/x/gobot/v2/platforms/friendlyelec/nanopct6"
)

// Preparation: see /gobot/system/ONEWIRE.md
//
// Wiring:
// PWR : 1, 17 (+3.3V, VCC), 6, 9, 14, 20, 25, 30, 34, 39 (GND)
// 1-wire : 16 (DQ) - resistor to VCC, ~1.5kOhm ... 5kOhm
// DS18B20: 1 (GND), 2 (DQ), 3 (VDD, +3 ... 5.5V) for local power mode
func main() {
adaptor := nanopct6.NewAdaptor()
// resolution change not supported by all devices
temp0 := onewire.NewDS18B20Driver(adaptor, 0xde5e710a6461, onewire.WithResolution(12))
temp1 := onewire.NewDS18B20Driver(adaptor, 0x1e40710a6461, onewire.WithFahrenheit(), onewire.WithConversionTime(500))

work := func() {
time0, err := temp0.ConversionTime()
if err != nil {
log.Printf("Err CT0: %v\n", err)
}
res0, err := temp0.Resolution()
if err != nil {
log.Printf("Err R0: %v\n", err)
}
log.Printf("Conversion time @%d bit for Temp 0: %d ms\n", res0, time0)

time1, err := temp1.ConversionTime()
if err != nil {
log.Printf("Err CT1: %v\n", err)
}
res1, err := temp1.Resolution()
if err != nil {
log.Printf("Err R1: %v\n", err)
}
log.Printf("Conversion time @%d bit for Temp 0: %d ms\n", res1, time1)

gobot.Every(10*(time.Duration(time0))*time.Millisecond, func() {
t0, err := temp0.Temperature()
if err != nil {
log.Printf("Err Temp 0: %v\n", err)
}

fmt.Printf("Temp 0: %2.1f °C\n", t0)
})

gobot.Every(10*(time.Duration(time1))*time.Millisecond, func() {
t1, err := temp1.Temperature()
if err != nil {
log.Printf("Err Temp 1: %v\n", err)
}

fmt.Printf("Temp 1: %2.3f °F\n", t1)
})
}

robot := gobot.NewRobot("onewireBot",
[]gobot.Connection{adaptor},
[]gobot.Device{temp0, temp1},
work,
)

if err := robot.Start(); err != nil {
panic(err)
}
}
Loading

0 comments on commit f5b17ca

Please sign in to comment.