-
-
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.
rock64: introduce adaptor for PINE64-ROCK64
- Loading branch information
1 parent
4e9c832
commit c02d296
Showing
9 changed files
with
666 additions
and
0 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
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/pine64/rock64" | ||
) | ||
|
||
// Wiring | ||
// 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) | ||
// GPIO ROCK64: second header P5+BUS pin 3 is input, pin 4 is normal output, pin 5 is 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 = "P5_3" | ||
outPinNum = "P5_4" | ||
outPinInvertedNum = "P5_5" | ||
debounceTime = 2 * time.Second | ||
) | ||
// note: WithGpiosOpenDrain() is optional, if using WithGpiosOpenSource() the LED's will not light up | ||
board := rock64.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,81 @@ | ||
//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/i2c" | ||
"gobot.io/x/gobot/v2/platforms/pine64/rock64" | ||
) | ||
|
||
func main() { | ||
// Wiring | ||
// PWR ROCK64: 1, P5_1 (+3.3V, VCC), 6, 9, 14, 20, P5_7, P5_8, P5_15, P5_16 (GND) | ||
// I2C0 ROCK64: 3 (SDA), 5 (SCL) | ||
// I2C1 ROCK64: 27 (SDA), 28 (SCL) | ||
// YL-40 module: wire AOUT --> AIN2 for this example | ||
// | ||
// Note: temperature measurement is often buggy, because sensor is not properly grounded | ||
// fix it by soldering a small bridge to the adjacent ground pin of brightness sensor | ||
board := rock64.NewAdaptor() | ||
yl := i2c.NewYL40Driver(board, i2c.WithBus(1)) | ||
|
||
work := func() { | ||
// the LED light is visible above ~1.7V | ||
writeVal, _ := yl.AOUT() | ||
|
||
gobot.Every(1000*time.Millisecond, func() { | ||
if err := yl.Write(writeVal); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
log.Printf(" %.1f V written", writeVal) | ||
writeVal = writeVal + 0.1 | ||
if writeVal > 3.3 { | ||
writeVal = 0 | ||
} | ||
} | ||
|
||
if brightness, err := yl.ReadBrightness(); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
log.Printf("Brightness: %.0f [0..1000]", brightness) | ||
} | ||
|
||
if temperature, err := yl.ReadTemperature(); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
log.Printf("Temperature: %.1f °C", temperature) | ||
} | ||
|
||
if ain2, err := yl.ReadAIN2(); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
log.Printf("Read back AOUT: %.1f [0..3.3]", ain2) | ||
} | ||
|
||
if potiState, err := yl.ReadPotentiometer(); err != nil { | ||
fmt.Println(err) | ||
} else { | ||
log.Printf("Resistor: %.0f %% [-100..+100]", potiState) | ||
} | ||
}) | ||
} | ||
|
||
robot := gobot.NewRobot("yl40Bot", | ||
[]gobot.Connection{board}, | ||
[]gobot.Device{yl}, | ||
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,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. |
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,110 @@ | ||
# Pine ROCK64 | ||
|
||
The Pine ROCK64 is a single board SoC computer based on the Rockchip RK3328 arm64 processor. It has built-in GPIO and | ||
I2C interfaces. SPI is most likely not usable (not tested), because in use by the SPI FLASH 128M memory chip. | ||
|
||
For more info about the Pine ROCK64, go to [https://pine64.org/documentation/ROCK64/](https://pine64.org/documentation/ROCK64/). | ||
|
||
## How to Install | ||
|
||
Please refer to the main [README.md](https://github.com/hybridgroup/gobot/blob/release/README.md) | ||
|
||
Tested OS: | ||
|
||
* [armbian](https://www.armbian.com/rock64/) with Debian | ||
|
||
## Configuration steps for the OS | ||
|
||
### System access and configuration basics | ||
|
||
Please follow the instructions of the OS provider. A ssh access is used in this guide. | ||
|
||
```sh | ||
ssh <user>@192.168.1.xxx | ||
``` | ||
|
||
### Enabling hardware drivers | ||
|
||
Not all drivers are enabled by default. You can have a look at the configuration file, to find out what is enabled at | ||
your system: | ||
|
||
```sh | ||
cat /boot/armbianEnv.txt | ||
``` | ||
|
||
```sh | ||
sudo apt install armbian-config | ||
sudo armbian-config | ||
``` | ||
|
||
## How to Use | ||
|
||
The pin numbering used by your Gobot program should match the way your board is labeled right on the board itself. | ||
|
||
```go | ||
r := rock64.NewAdaptor() | ||
led := gpio.NewLedDriver(r, "7") | ||
``` | ||
|
||
## How to Connect | ||
|
||
### Compiling | ||
|
||
Compile your Gobot program on your workstation like this: | ||
|
||
```sh | ||
GOARCH=arm64 GOOS=linux go build -o output/ examples/rock64_blink.go | ||
``` | ||
|
||
Once you have compiled your code, you can upload your program and execute it on the board from your workstation | ||
using the `scp` and `ssh` commands like this: | ||
|
||
```sh | ||
scp rock64_blink <user>@192.168.1.xxx:~ | ||
ssh -t <user>@192.168.1.xxx "./rock64_blink" | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
### I2C-0 overlay | ||
|
||
With the armbian-config sometimes the overlays can not properly applied (different open Bugs). To ensure your overlay | ||
is applied have a look into your /boot/boot.cmd and search for the name of the used shell variable(s). This name needs | ||
to be used in your /boot/armbianEnv.txt. | ||
|
||
```sh cat /boot/boot.cmd | grep overlay_file | ||
for overlay_file in ${overlays}; do | ||
if load ${devtype} ${devnum}:${distro_bootpart} ${load_addr} ${prefix}dtb/rockchip/overlay/${overlay_prefix}-${overlay_file}.dtbo; then | ||
echo "Applying kernel provided DT overlay ${overlay_prefix}-${overlay_file}.dtbo" | ||
for overlay_file in ${user_overlays}; do | ||
if load ${devtype} ${devnum}:${distro_bootpart} ${load_addr} ${prefix}overlay-user/${overlay_file}.dtbo; then | ||
echo "Applying user provided DT overlay ${overlay_file}.dtbo" | ||
``` | ||
In the example above the variable is named `overlays`. So your /boot/armbianEnv.txt must contain this variable. | ||
```sh cat /boot/armbianEnv.txt | grep overlay | ||
overlay_prefix=rockchip | ||
overlays=rk3328-i2c0 | ||
``` | ||
In some buggy versions the variable is named "fdt_overlays", just rename the variable in your "armbianEnv.txt" to match | ||
the boot script. | ||
As you can see in the boot script, the real file name is a concatenate of different variables `${overlay_prefix}-${overlay_file}.dtbo`. | ||
This file must exist in the folder `${prefix}dtb/rockchip/overlay` (prefix="/boot/"). So for the i2c-0 overlay: | ||
```sh ls -la /boot/dtb/rockchip/overlay/ | grep i2c0 | ||
-rw-r--r-- 1 root root 218 Nov 25 19:15 rockchip-rk3328-i2c0.dtbo | ||
-rw-r--r-- 1 root root 223 Nov 25 19:15 rockchip-rk3568-hk-i2c0.dtbo | ||
``` | ||
...means the entry in the armbianEnv.txt sould be set to "overlays=rk3328-i2c0". | ||
The variable can contain a space separated list. | ||
### PWM | ||
There are 3 PWMs on the chip (pwm0, pwm1, pwm2). Unfortunately all pins are shared with the PMIC, so i2c-1 (pwm0, pwm1) | ||
can not be deactivated, because it is mandatory for the i2c communication to PMIC address 0x18. Simply an activation of | ||
pwm0 or pwm1 with an overlay leads to the Kernel can not be loaded anymore. |
Oops, something went wrong.