Skip to content

Commit c02d296

Browse files
committed
rock64: introduce adaptor for PINE64-ROCK64
1 parent 4e9c832 commit c02d296

File tree

9 files changed

+666
-0
lines changed

9 files changed

+666
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ platforms are currently supported:
273273
- [Parrot Bebop](http://www.parrot.com/usa/products/bebop-drone/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/parrot/bebop)
274274
- [Parrot Minidrone](https://www.parrot.com/us/minidrones) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/parrot/minidrone)
275275
- [Pebble](https://www.getpebble.com/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/pebble)
276+
- [PINE64 ROCK64](https://pine64.org/documentation/ROCK64/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/pine64/rock64)
276277
- [Radxa Rock Pi 4](https://wiki.radxa.com/Rock4/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/rockpi)
277278
- [Raspberry Pi](http://www.raspberrypi.org/) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/raspi)
278279
- [Serial Port](https://en.wikipedia.org/wiki/Serial_port) <=> [Package](https://github.com/hybridgroup/gobot/blob/release/platforms/serialport)

examples/rock64_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/pine64/rock64"
17+
)
18+
19+
// Wiring
20+
// PWR ROCK64: 1, P5_1 (+3.3V, VCC); 2, 4, P5_2 (+5V, VDD); 6, 9, 14, 20, P5_7, P5_8, P5_15, P5_16 (GND)
21+
// GPIO ROCK64: second header P5+BUS pin 3 is input, pin 4 is normal output, pin 5 is 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 = "P5_3"
30+
outPinNum = "P5_4"
31+
outPinInvertedNum = "P5_5"
32+
debounceTime = 2 * time.Second
33+
)
34+
// note: WithGpiosOpenDrain() is optional, if using WithGpiosOpenSource() the LED's will not light up
35+
board := rock64.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/rock64_yl40.go

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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/i2c"
16+
"gobot.io/x/gobot/v2/platforms/pine64/rock64"
17+
)
18+
19+
func main() {
20+
// Wiring
21+
// PWR ROCK64: 1, P5_1 (+3.3V, VCC), 6, 9, 14, 20, P5_7, P5_8, P5_15, P5_16 (GND)
22+
// I2C0 ROCK64: 3 (SDA), 5 (SCL)
23+
// I2C1 ROCK64: 27 (SDA), 28 (SCL)
24+
// YL-40 module: wire AOUT --> AIN2 for this example
25+
//
26+
// Note: temperature measurement is often buggy, because sensor is not properly grounded
27+
// fix it by soldering a small bridge to the adjacent ground pin of brightness sensor
28+
board := rock64.NewAdaptor()
29+
yl := i2c.NewYL40Driver(board, i2c.WithBus(1))
30+
31+
work := func() {
32+
// the LED light is visible above ~1.7V
33+
writeVal, _ := yl.AOUT()
34+
35+
gobot.Every(1000*time.Millisecond, func() {
36+
if err := yl.Write(writeVal); err != nil {
37+
fmt.Println(err)
38+
} else {
39+
log.Printf(" %.1f V written", writeVal)
40+
writeVal = writeVal + 0.1
41+
if writeVal > 3.3 {
42+
writeVal = 0
43+
}
44+
}
45+
46+
if brightness, err := yl.ReadBrightness(); err != nil {
47+
fmt.Println(err)
48+
} else {
49+
log.Printf("Brightness: %.0f [0..1000]", brightness)
50+
}
51+
52+
if temperature, err := yl.ReadTemperature(); err != nil {
53+
fmt.Println(err)
54+
} else {
55+
log.Printf("Temperature: %.1f °C", temperature)
56+
}
57+
58+
if ain2, err := yl.ReadAIN2(); err != nil {
59+
fmt.Println(err)
60+
} else {
61+
log.Printf("Read back AOUT: %.1f [0..3.3]", ain2)
62+
}
63+
64+
if potiState, err := yl.ReadPotentiometer(); err != nil {
65+
fmt.Println(err)
66+
} else {
67+
log.Printf("Resistor: %.0f %% [-100..+100]", potiState)
68+
}
69+
})
70+
}
71+
72+
robot := gobot.NewRobot("yl40Bot",
73+
[]gobot.Connection{board},
74+
[]gobot.Device{yl},
75+
work,
76+
)
77+
78+
if err := robot.Start(); err != nil {
79+
panic(err)
80+
}
81+
}

platforms/pine64/rock64/LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2025 The Hybrid Group
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

platforms/pine64/rock64/README.md

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Pine ROCK64
2+
3+
The Pine ROCK64 is a single board SoC computer based on the Rockchip RK3328 arm64 processor. It has built-in GPIO and
4+
I2C interfaces. SPI is most likely not usable (not tested), because in use by the SPI FLASH 128M memory chip.
5+
6+
For more info about the Pine ROCK64, go to [https://pine64.org/documentation/ROCK64/](https://pine64.org/documentation/ROCK64/).
7+
8+
## How to Install
9+
10+
Please refer to the main [README.md](https://github.com/hybridgroup/gobot/blob/release/README.md)
11+
12+
Tested OS:
13+
14+
* [armbian](https://www.armbian.com/rock64/) with Debian
15+
16+
## Configuration steps for the OS
17+
18+
### System access and configuration basics
19+
20+
Please follow the instructions of the OS provider. A ssh access is used in this guide.
21+
22+
```sh
23+
ssh <user>@192.168.1.xxx
24+
```
25+
26+
### Enabling hardware drivers
27+
28+
Not all drivers are enabled by default. You can have a look at the configuration file, to find out what is enabled at
29+
your system:
30+
31+
```sh
32+
cat /boot/armbianEnv.txt
33+
```
34+
35+
```sh
36+
sudo apt install armbian-config
37+
sudo armbian-config
38+
```
39+
40+
## How to Use
41+
42+
The pin numbering used by your Gobot program should match the way your board is labeled right on the board itself.
43+
44+
```go
45+
r := rock64.NewAdaptor()
46+
led := gpio.NewLedDriver(r, "7")
47+
```
48+
49+
## How to Connect
50+
51+
### Compiling
52+
53+
Compile your Gobot program on your workstation like this:
54+
55+
```sh
56+
GOARCH=arm64 GOOS=linux go build -o output/ examples/rock64_blink.go
57+
```
58+
59+
Once you have compiled your code, you can upload your program and execute it on the board from your workstation
60+
using the `scp` and `ssh` commands like this:
61+
62+
```sh
63+
scp rock64_blink <user>@192.168.1.xxx:~
64+
ssh -t <user>@192.168.1.xxx "./rock64_blink"
65+
```
66+
67+
## Troubleshooting
68+
69+
### I2C-0 overlay
70+
71+
With the armbian-config sometimes the overlays can not properly applied (different open Bugs). To ensure your overlay
72+
is applied have a look into your /boot/boot.cmd and search for the name of the used shell variable(s). This name needs
73+
to be used in your /boot/armbianEnv.txt.
74+
75+
```sh cat /boot/boot.cmd | grep overlay_file
76+
for overlay_file in ${overlays}; do
77+
if load ${devtype} ${devnum}:${distro_bootpart} ${load_addr} ${prefix}dtb/rockchip/overlay/${overlay_prefix}-${overlay_file}.dtbo; then
78+
echo "Applying kernel provided DT overlay ${overlay_prefix}-${overlay_file}.dtbo"
79+
for overlay_file in ${user_overlays}; do
80+
if load ${devtype} ${devnum}:${distro_bootpart} ${load_addr} ${prefix}overlay-user/${overlay_file}.dtbo; then
81+
echo "Applying user provided DT overlay ${overlay_file}.dtbo"
82+
```
83+
84+
In the example above the variable is named `overlays`. So your /boot/armbianEnv.txt must contain this variable.
85+
86+
```sh cat /boot/armbianEnv.txt | grep overlay
87+
overlay_prefix=rockchip
88+
overlays=rk3328-i2c0
89+
```
90+
91+
In some buggy versions the variable is named "fdt_overlays", just rename the variable in your "armbianEnv.txt" to match
92+
the boot script.
93+
94+
As you can see in the boot script, the real file name is a concatenate of different variables `${overlay_prefix}-${overlay_file}.dtbo`.
95+
This file must exist in the folder `${prefix}dtb/rockchip/overlay` (prefix="/boot/"). So for the i2c-0 overlay:
96+
97+
```sh ls -la /boot/dtb/rockchip/overlay/ | grep i2c0
98+
-rw-r--r-- 1 root root 218 Nov 25 19:15 rockchip-rk3328-i2c0.dtbo
99+
-rw-r--r-- 1 root root 223 Nov 25 19:15 rockchip-rk3568-hk-i2c0.dtbo
100+
```
101+
102+
...means the entry in the armbianEnv.txt sould be set to "overlays=rk3328-i2c0".
103+
104+
The variable can contain a space separated list.
105+
106+
### PWM
107+
108+
There are 3 PWMs on the chip (pwm0, pwm1, pwm2). Unfortunately all pins are shared with the PMIC, so i2c-1 (pwm0, pwm1)
109+
can not be deactivated, because it is mandatory for the i2c communication to PMIC address 0x18. Simply an activation of
110+
pwm0 or pwm1 with an overlay leads to the Kernel can not be loaded anymore.

0 commit comments

Comments
 (0)