-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nanopct6: introduce adaptor for FriendlyELEC NanoPC-T6
- Loading branch information
1 parent
50da9ae
commit f5b17ca
Showing
31 changed files
with
990 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.