-
-
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.
zero: introduce adaptor for Radxa Zero (#1128)
- Loading branch information
1 parent
c986109
commit cda3dbc
Showing
10 changed files
with
870 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//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/aio" | ||
"gobot.io/x/gobot/v2/platforms/radxa/zero" | ||
) | ||
|
||
// Wiring: | ||
// PWR : 1, 17 (+3.3V, VCC), 2, 4 (+5V), 6, 9, 14, 20, 25, 30, 34, 39 (GND) | ||
// ADC (max. 1.8V): header pin 15 is input for channel 1, pin 26 is input for channel 2 | ||
func main() { | ||
const ( | ||
inPin0 = "15_mean" | ||
inPin1 = "26" | ||
inVoltageScale = 0.439453125 // see README.md of the platform | ||
) | ||
|
||
scaler := aio.AnalogSensorLinearScaler(0, 4095, 0, 1.8) | ||
|
||
adaptor := zero.NewAdaptor() | ||
ana0 := aio.NewAnalogSensorDriver(adaptor, inPin0, aio.WithSensorScaler(scaler)) | ||
ana1 := aio.NewAnalogSensorDriver(adaptor, inPin1) | ||
|
||
work := func() { | ||
gobot.Every(500*time.Millisecond, func() { | ||
v0, err := ana0.Read() | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
v1, err := ana1.Read() | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
fmt.Printf("%s: %1.3f V, %s: %2.0f (%4.0f mV)\n", inPin0, v0, inPin1, v1, v1*inVoltageScale) | ||
}) | ||
} | ||
|
||
robot := gobot.NewRobot("adcBot", | ||
[]gobot.Connection{adaptor}, | ||
[]gobot.Device{ana0, ana1}, | ||
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" | ||
"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/radxa/zero" | ||
) | ||
|
||
// Wiring | ||
// PWR : 1, 17 (+3.3V, VCC), 2, 4 (+5V), 6, 9, 14, 20, 25, 30, 34, 39 (GND) | ||
// GPIO : header pin 24 is input, pin 32 used as normal output, pin 36 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 the state changes | ||
func main() { | ||
const ( | ||
inPinNum = "24" | ||
outPinNum = "32" | ||
outPinInvertedNum = "36" | ||
) | ||
// note: WithGpiosOpenDrain() is optional, if using WithGpiosOpenSource() the LED's will not light up | ||
board := zero.NewAdaptor(adaptors.WithGpiosActiveLow(outPinInvertedNum), | ||
adaptors.WithGpiosOpenDrain(outPinNum, outPinInvertedNum), adaptors.WithGpiosPullUp(inPinNum)) | ||
|
||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright (c) 2025 The Hybrid Group | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
Oops, something went wrong.