gobot.io/x/gobot/v2@v2.1.0/platforms/tinkerboard/README.md (about)

     1  # Tinker Board
     2  
     3  The ASUS Tinker Board is a single board SoC computer based on the Rockchip RK3288 processor. It has built-in GPIO, PWM,
     4  SPI, and I2C interfaces.
     5  
     6  For more info about the Tinker Board, go to [https://www.asus.com/uk/Single-Board-Computer/Tinker-Board/](https://www.asus.com/uk/Single-Board-Computer/Tinker-Board/).
     7  
     8  ## How to Install
     9  
    10  Tested OS:
    11  
    12  * [Debian TinkerOS](https://github.com/TinkerBoard/debian_kernel/releases)
    13  * [armbian](https://www.armbian.com/tinkerboard/) with Debian or Ubuntu
    14  
    15  > The latest "Tinker Board Debian 10 V3.0.11" is official discontinued. Nevertheless it is well tested with gobot. There
    16  > is a known i2c issue with the Kernel 4.4.194 if using block reads. armbian is known to work in this area.
    17  
    18  You would normally install Go and Gobot on your workstation. Once installed, cross compile your program on your
    19  workstation, transfer the final executable to your Tinker Board, and run the program on the Tinker Board as documented here.
    20  
    21  ```sh
    22  go get -d -u gobot.io/x/gobot/v2/...
    23  ```
    24  
    25  ### System access and configuration basics
    26  
    27  Some configuration steps are needed to enable drivers and simplify the interaction with your Tinker Board. Once your
    28  Tinker Board has been configured, you do not need to do so again.
    29  
    30  Note that these configuration steps must be performed on the Tinker Board itself. The easiest is to login to the Tinker
    31  Board via SSH (option "-4" is used to force IPv4, which is needed for some versions of TinkerOS):
    32  
    33  ```sh
    34  ssh -4 linaro@192.168.1.xxx
    35  ```
    36  
    37  ### Enabling hardware drivers
    38  
    39  Not all drivers are enabled by default. You can have a look at the configuration file, to find out what is enabled at
    40  your system:
    41  
    42  ```sh
    43  cat /boot/config.txt
    44  ```
    45  
    46  This file can be modified by "vi" or "nano", it is self explanatory:
    47  
    48  ```sh
    49  sudo vi /boot/config.txt
    50  ```
    51  
    52  Newer versions of Tinker Board provide an user interface for configuration with:
    53  
    54  ```sh
    55  sudo tinker-config
    56  ```
    57  
    58  After configuration was changed, an reboot is necessary.
    59  
    60  ```sh
    61  sudo reboot
    62  ```
    63  
    64  ### Enabling GPIO pins
    65  
    66  #### Create a group "gpio"
    67  
    68  Create a Linux group named "gpio" by running the following command:
    69  
    70  ```sh
    71  sudo groupadd -f --system gpio
    72  ```
    73  
    74  If you already have a "gpio" group, you can skip to the next step.
    75  
    76  #### Add the "linaro" user to the new "gpio" group
    77  
    78  Add the user "linaro" to be a member of the Linux group named "gpio" by running the following command:
    79  
    80  ```sh
    81  sudo usermod -a -G gpio linaro
    82  ```
    83  
    84  If you already have added the "gpio" group, you can skip to the next step.
    85  
    86  #### Add a "udev" rules file for gpio
    87  
    88  Create a new "udev" rules file for the GPIO on the Tinker Board by running the following command:
    89  
    90  ```sh
    91  sudo vi /etc/udev/rules.d/91-gpio.rules
    92  ```
    93  
    94  And add the following contents to the file:
    95  
    96  ```txt
    97  SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
    98  SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"
    99  ```
   100  
   101  Press the "Esc" key, then press the ":" key and then the "q" key, and then press the "Enter" key. This should save your
   102  file. After rebooting your Tinker Board, you should be able to run your Gobot code that uses GPIO.
   103  
   104  ### Enabling I2C
   105  
   106  #### Create a group "i2c"
   107  
   108  If you already have a "i2c" group, you can skip to the next step.  
   109  
   110  Create a Linux group named "i2c" by running the following command:
   111  
   112  ```sh
   113  sudo groupadd -f --system i2c
   114  ```
   115  
   116  #### Add the "linaro" user to the new "i2c" group
   117  
   118  If you already have added the "i2c" group, you can skip to the next step.  
   119  
   120  Add the user "linaro" to be a member of the Linux group named "i2c" by running the following command:
   121  
   122  ```sh
   123  sudo usermod -a -G gpio linaro
   124  ```
   125  
   126  #### Add a "udev" rules file for I2C
   127  
   128  Create a new "udev" rules file for the I2C on the Tinker Board by running the following command:
   129  
   130  ```sh
   131  sudo vi /etc/udev/rules.d/92-i2c.rules
   132  ```
   133  
   134  And add the following contents to the file:
   135  
   136  ```txt
   137  KERNEL=="i2c-0"     , GROUP="i2c", MODE="0660"
   138  KERNEL=="i2c-[1-9]*", GROUP="i2c", MODE="0666"
   139  ```
   140  
   141  Press the "Esc" key, then press the ":" key and then the "q" key, and then press the "Enter" key. This should save your
   142  file. After rebooting your Tinker Board, you should be able to run your Gobot code that uses I2C.
   143  
   144  ## How to Use
   145  
   146  The pin numbering used by your Gobot program should match the way your board is labeled right on the board itself.
   147  
   148  ```go
   149  r := tinkerboard.NewAdaptor()
   150  led := gpio.NewLedDriver(r, "7")
   151  ```
   152  
   153  ## How to Connect
   154  
   155  ### Compiling
   156  
   157  Compile your Gobot program on your workstation like this:
   158  
   159  ```sh
   160  GOARM=7 GOARCH=arm GOOS=linux go build examples/tinkerboard_blink.go
   161  ```
   162  
   163  Once you have compiled your code, you can upload your program and execute it on the Tinkerboard from your workstation
   164  using the `scp` and `ssh` commands like this:
   165  
   166  ```sh
   167  scp tinkerboard_blink linaro@192.168.1.xxx:/home/linaro/
   168  ssh -t linaro@192.168.1.xxx "./tinkerboard_blink"
   169  ```
   170  
   171  ## Troubleshooting
   172  
   173  ### PWM
   174  
   175  #### Investigate state
   176  
   177  ```sh
   178  # ls -la /sys/class/pwm/
   179  total 0
   180  drwxr-xr-x  2 root root 0 Apr 24 14:11 .
   181  drwxr-xr-x 66 root root 0 Apr 24 14:09 ..
   182  lrwxrwxrwx  1 root root 0 Apr 24 14:09 pwmchip0 -> ../../devices/platform/ff680000.pwm/pwm/pwmchip0
   183  ```
   184  
   185  looking for one of the following items in the path:
   186  ff680000 => internally, not usable
   187  ff680010 => internally, not usable
   188  ff680020 => pwm2, pin33
   189  ff680030 => pwm3, pin32
   190  
   191  #### Activate
   192  
   193  When there is no pwm2, pwm3, this can be activated.
   194  Open the file /boot/config.txt and add lines/remove comment sign and adjust:
   195  
   196  intf:pwm2=on
   197  intf:pwm3=on
   198  
   199  Then save the file, close and reboot.
   200  
   201  After reboot check the state:
   202  
   203  ```sh
   204  # ls -la /sys/class/pwm/
   205  total 0
   206  drwxr-xr-x  2 root root 0 Apr 24 14:11 .
   207  drwxr-xr-x 66 root root 0 Apr 24 14:09 ..
   208  lrwxrwxrwx  1 root root 0 Apr 24 14:09 pwmchip0 -> ../../devices/platform/ff680000.pwm/pwm/pwmchip0
   209  lrwxrwxrwx  1 root root 0 Apr 24 14:09 pwmchip1 -> ../../devices/platform/ff680010.pwm/pwm/pwmchip1
   210  lrwxrwxrwx  1 root root 0 Apr 24 14:09 pwmchip2 -> ../../devices/platform/ff680030.pwm/pwm/pwmchip2
   211  ```
   212  
   213  #### Test
   214  
   215  For example only pwm3 was activated to use pin32. Connect an oscilloscope or at least a meter to the pin 32.
   216  
   217  switch to root user by "su -"
   218  
   219  investigate state:
   220  
   221  ```sh
   222  # ls -la /sys/class/pwm/pwmchip2/
   223  total 0
   224  drwxr-xr-x 3 root root    0 Apr 24 14:17 .
   225  drwxr-xr-x 3 root root    0 Apr 24 14:17 ..
   226  lrwxrwxrwx 1 root root    0 Apr 24 14:17 device -> ../../../ff680030.pwm
   227  --w------- 1 root root 4096 Apr 24 14:17 export
   228  -r--r--r-- 1 root root 4096 Apr 24 14:17 npwm
   229  drwxr-xr-x 2 root root    0 Apr 24 14:17 power
   230  lrwxrwxrwx 1 root root    0 Apr 24 14:17 subsystem -> ../../../../../class/pwm
   231  -rw-r--r-- 1 root root 4096 Apr 24 14:17 uevent
   232  --w------- 1 root root 4096 Apr 24 14:17 unexport
   233  ```
   234  
   235  #### Creating pwm0
   236  
   237  `echo 0 > /sys/class/pwm/pwmchip2/enable`
   238  
   239  investigate result:
   240  
   241  ```sh
   242  # ls /sys/class/pwm/pwmchip2/
   243  device  export  npwm  power  pwm0  subsystem  uevent  unexport
   244  # ls /sys/class/pwm/pwmchip2/pwm0/
   245  capture  duty_cycle  enable  period  polarity  power  uevent
   246  # cat /sys/class/pwm/pwmchip2/pwm0/period 
   247  0
   248  # cat /sys/class/pwm/pwmchip2/pwm0/duty_cycle 
   249  0
   250  # cat /sys/class/pwm/pwmchip2/pwm0/enable 
   251  0
   252  # cat /sys/class/pwm/pwmchip2/pwm0/polarity 
   253  inversed
   254  ```
   255  
   256  #### Initialization
   257  
   258  Note: Before writing the period all other write actions will cause an error "-bash: echo: write error: Invalid argument"
   259  
   260  ```sh
   261  echo 10000000 > /sys/class/pwm/pwmchip2/pwm0/period # this is a frequency divider for 1GHz (1000 will produce a frequency of 1MHz, 1000000 will cause a frequency of 1kHz, her we got 100Hz)
   262  echo "normal" > /sys/class/pwm/pwmchip2/pwm0/polarity
   263  echo 3000000 > /sys/class/pwm/pwmchip2/pwm0/duty_cycle # this means 30%
   264  echo 1  > /sys/class/pwm/pwmchip2/pwm0/enable
   265  ```
   266  
   267  Now we should measure a value of around 1V with the meter, because the basis value is 3.3V and 30% leads to 1V.
   268  
   269  Try to inverse the sequence:
   270  `echo "inversed" > /sys/class/pwm/pwmchip2/pwm0/polarity`
   271  Now we should measure a value of around 2.3V with the meter, which is the difference of 1V to 3.3V.
   272  
   273  If we have attached an oscilloscope we can play around with the values for period and duty_cycle and see what happen.