NanoPi R1

From FriendlyELEC WiKi
Revision as of 03:18, 17 January 2019 by Yftan (Talk | contribs)

Jump to: navigation, search

查看中文

1 Introduction

Overview
Front
Back
  • The NanoPi R1("R1") is a complete open source board developed by FriendlyElec for makers, hobbyists, fans and etc.
  • The NanoPi R1 has one Gbps Ethernet port and one Fast Ethernet port. It has an onboard 2.4G Wi-Fi module. FriendlyElec ported OpenWRT to the R1. With some additional settings it will work like a router.Its good networking performance and features make it a good platform for various network applications.

2 Hardware Spec

  • CPU: Allwinner H3, Quad-core Cortex-A7 Up to 1.2GHz
  • DDR3 RAM: 512MB/1GB
  • Storage: NC/8GB eMMC
  • Network:
    • 10/100/1000M Ethernet x 1,
    • 10/100M Ethernet x 1
  • WiFi: 802.11b/g/n, with SMA antenna interface
  • Bluetooth:4.0 dual mode
  • USB Host: Type-A x2
  • MicroSD Slot x 1
  • MicroUSB: for OTG and power input
  • Debug Serial Port: 3Pin 2.54mm pitch pin-header
  • UART: 4Pin 2.54mm pitch pin-header
  • LED: LED x 3
  • KEY: KEY x 1
  • PC Size: 50.5 x 60mm
  • Power Supply: DC 5V/2A
  • Temperature measuring range: -40℃ to 80℃
  • OS/Software: U-boot,Ubuntu-Core,OpenWRT
  • Weight: xxg

3 Diagram, Layout and Dimension

3.1 Layout

NanoPi R1 Layout

3.2 Board Dimension

NanoPi R1-dimensions.png

For more details refer to:NanoPi_R1 pcb file in dxf format

4 Get Started

4.1 Essentials You Need

Before starting to use your NanoPi R1 get the following items ready

  • NanoPi R1
  • MicroSD Card/TF Card: Class 10 or Above, minimum 8GB SDHC
  • MicroUSB 5V/2A power adapter
  • A host computer running Ubuntu 16.04 64-bit system

4.2 TF Cards We Tested

To make your NanoPi R1 boot and run fast we highly recommend you use a Class10 8GB SDHC TF card or a better one. The following cards are what we used in all our test cases presented here:

  • SanDisk TF 8G Class10 Micro/SD High Speed TF card:

SanDisk microSD 8G

  • SanDisk TF128G MicroSDXC TF 128G Class10 48MB/S:

SanDisk microSD 128G

  • 川宇 8G C10 High Speed class10 micro SD card:

chuanyu microSD 8G

4.3 Install OS

4.3.1 Download Image Files

Go to download link to download the image files under the officail-ROMs directory and the flashing utility under the tools directory:

Image Files
nanopi-r1_sd_friendlycore-xenial_4.14_armhf_YYYYMMDD.img.zip FriendlyCore based on UbuntuCore and Linux-4.14 kernel
nanopi-r1_sd_openwrt_4.14_armhf_YYYYMMDD.img.zip OpenWrt and Linux-4.14 kernel
nanopi-r1_eflasher_friendlycore-xenial_4.14_armhf_YYYYMMDD.img.zip eflasher image which is used to install FriendlyCore(Linux-4.14) to eMMC
nanopi-r1_eflasher_openwrt_4.14_armhf_YYYYMMDD.img.zip eflasher image which is used to install OpenWrt(Linux-4.14) to eMMC
Flashing Utility
win32diskimager.rar Windows utility. Under Linux users can use "dd"


4.3.1.1 Flash to eMMC
4.3.1.1.1 Flash OS with eflasher Utility
  • For more details about eflasher refer to the wiki link: EFlasher
  • Extract the eflasher Image and win32diskimager.rar files. Insert a TF card(at least 4G) into a Windows PC and run the win32diskimager utility as administrator. On the utility's main window select your TF card's drive, the wanted image file and click on "write" to start flashing the TF card.
  • Insert this card into your board's BOOT slot and power on (with a 5V/2A power source). If the green LED is on and the blue LED is blinking this indicates your board has successfully booted.
  • If your board doesn't support HDMI or no monitor is connected you can select an OS by running the following command:
$ su root
$ eflasher

The password for "root" is "fa".

We take "nanopi-r1_eflasher_friendlycore-xenial_4.14_armhf_YYYYMMDD.img" as an example. After you run the "eflasher" command you will see the following messages:

eflasher_friendlycore1
Type "1", select writing friendlycore system to eMMC you will see the following messages:

eflasher_friendlycore2_h3
Type "yes" to start installation:

eflasher_friendlycore3
After it is done power off the system, take off the TF card, power on again your system will be booted from eMMC.

  • If you want to flash other system to eMMC you can download the whole images-for-eflasher directory and extract the package under that directory to the FRIENDLYARM partition of an installation SD card.

eflasher_friendlyarm_h3

5 How to Use OpenWrt

5.1 Introduction

OpenWrt is a highly extensible GNU/Linux variant for embedded devices. Unlike many other distributions for routers, OpenWrt is built from the ground up to be a full-featured, easily modifiable OS for a router. In practice this means you can have all the features with none of the bloat, powered by a Linux kernel that is more recent than most other distributions. For more details you can refer to OpenWrt website.

5.2 Login OpenWrt

  • Login from serial port

Here is a hardware setup to connect your board to a serial device:
1) Connect your board to a FriendlyElec's PSU_ONECOM module. Both the module's DC port and the board's MicroUSB need to be powered by a 5V/2A power supply.Note: insufficient power supply may not make the system work normally.
PSU_ONECOM-R1
2) Connect your board to a FriendlyElec's Matrix-USB2UART module. The board's MicroUSB needs to be powered by a 5V/2A power supply
USB2UART-R1
By default a user logs in as "root" and doesn't need a password for "root". You can set a password for "root" by using the "passwd" command.
R1-login
When your board is booted for the first time it will automatically extend its TF card's rootfs file system to its max available space:
resize_rootfs
This will take a while and you need to wait for the process to complete.

  • Login via SSH

A NanoPi R1 that runs FriendlyElec's OpenWrt by default is configured as a secondary router. Its Gbps Ethernet(eth0) is configured as WAN and Fast Ethernet(eth1) is configured as LAN.
If you want to login via SSH you need to connect your R1's Gbps Ethernet to a master router's LAN port. Here is a hardware setup:
r1_lan_connected
We assume the IP address for the board's Gbps Ethernet(eth0) is 192.168.1.163. Run the following command to login via SSH:

$ ssh root@192.168.1.163

By default a user logs in as "root" without a password.

  • Login from Web

OpenWrt supports system login from a LuCI Web page. You can refer to <Login via SSH> to configure your system. We assume the IP address for your board's Gbps Ethernet is 192.168.1.163. After type in the IP address in a browser's address bar you will be able to login. Here is what you should see:
R1-OpenWrt-LuCI
By default a users logs in as "root" without a password. Click on the "Login" button you will login.

5.3 Connect to R1's WiFi Hotspot

By default a NanoPi R1 that runs OpenWrt is configured as a secondary router. To achieve better performance you need to install a WiFi antenna to your board. By default the board's WiFi module AP6212 works in the AP mode and its hotspot's name is "OpenWrt". You can use a smart phone to connect to this hotspot without a password and browse the internet.
After your smart phone is successfully connected to the board's WiFi hotspot you can go to "LuCI" -> "Netwrok" -> "Wireless" to check your connection:
openwrt_wifiap_connected
By default the WiFi hotspot falls into 192.168.2.x and you can open a browser on your phone and type 192.168.2.1 in the browser's address bar to visit LuCI:
phone_luci

5.4 Connect to R1's LAN Port

By default a NanoPi R1 that runs OpenWrt is configured as a secondary router.Its Fast Ethernet(eth1) is configured as LAN. You can connect a device to R1's LAN port and browse the internet:
r1_lan_connected
You can browser the internet from a NanoPi NEO:

$ ping www.baidu.com
64 bytes from 14.215.177.38: icmp_seq=2 ttl=56 time=19.5 ms

5.5 Manage Software Packages

OpenWrt uses the opkg utility to manage software packages. You can run the following command to get help:

$ opkg
Package Manipulation:
        update                  Update list of available packages
        upgrade <pkgs>          Upgrade packages
        install <pkgs>          Install package(s)
        configure <pkgs>        Configure unpacked package(s)
        remove <pkgs|regexp>    Remove package(s)
        flag <flag> <pkgs>      Flag package(s)
         <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation)
 
Informational Commands:
        list                    List available packages
        list-installed          List installed packages
        list-upgradable         List installed and upgradable packages
        list-changed-conffiles  List user modified configuration files
        files <pkg>             List files belonging to <pkg>
        search <file|regexp>    List package providing <file>
        find <regexp>           List packages whose name or description matches <regexp>
        info [pkg|regexp]       Display all info for <pkg>
        status [pkg|regexp]     Display all status for <pkg>
        download <pkg>          Download <pkg> to current directory
...

The is just part of a complete list. Here we list some popular commands:

  • Update Package List

Before you install packages you'd better update your system's package list by running the following command:

$ opkg update
  • List available packages for installation:
$ opkg list
  • List installed packages:
$ opkg list-installed
  • Install/Remove packages:
$ opkg install <pkgs>
$ opkg remove <pkgs>
  • List package files:
$ opkg files <pkg>
  • Install LuCI's language packages for Chinese:
$ opkg install luci-i18n-base-zh-cn
  • List changed files:
$ opkg list-changed-conffiles

5.6 Check CPU's Status

  • List CPU's temperature and frequency:
$ cpu_freq
CPU0 online=1 temp=26581 governor=ondemand cur_freq=480000
CPU1 online=1 temp=26581 governor=ondemand cur_freq=480000
CPU2 online=1 temp=26581 governor=ondemand cur_freq=480000
CPU3 online=1 temp=26581 governor=ondemand cur_freq=480000

This information shows there are four CPU cores working and each one's temperature is around 26.5 degrees C. Each one's frequency scaling policy is "ondemand". Each one's frequency is 480MHz.

  • Check System Status on OpenWrt-LuCI Web:

After login OpenWrt-LuCI and click on "Statistics" ---> "Graphs" you will see nearly every component's statistics in the system, e.g:
1) System Load:
statistics_system_load
2) RAM:
statistics_memory
3) CPU Temperature:
statistics_thermal
This page comes from the "luci-app-statistics" package. "luci-app-statistics" uses the "Collectd" utility to collect statistics and uses the "RRDtool" utility to display them.
You can install the "collectd-mod-*" packages to get more statistics. All the "collectd-mod-*" packages use the same configuration file: /etc/config/luci_statistics。

5.7 查看LED的配置

  • 登录OpenWrt-LuCI界面后,点击顶部的 System ---> LED Configuration,可以查看当前LED的功能配置:

R1_openwrt_led

  • 默认LED的功能配置如下:
LED1 系统心跳灯,如果该LED不闪烁了,则表示系统死机了,必须断电重启系统。
LED2 千兆以太网eth0 WAN口的状态灯,如果WAN口网线连接正常,则LED亮,反之则LED灭。用户可以通过勾选复选框"Transmit" / "Receive"以设置当发送 / 接收到数据时LED闪烁。
LED3 百兆以太网eth1 LAN口的状态灯,如果LAN口网线连接正常,则LED亮,反之则LED灭。用户可以通过勾选复选框"Transmit" / "Receive"以设置当发送 / 接收到数据时LED闪烁。

5.8 查看BUTTON的配置

FriendlyElec的OpenWrt系统使用软件包triggerhappy配置按键的功能,默认的配置为按下按键就会触发系统执行reboot操作。 如果系统发生了异常需要重启,建议使用该按键触发软件reboot,这样可以有效地避免由于断电而造成的文件系统损坏的问题。
triggerhappy对应的配置文件为/etc/triggerhappy/triggers.d/example.conf。

5.9 查看Network->Interfaces的配置

  • 登录OpenWrt-LuCI界面后,点击顶部的 Network ---> Interfaces ,可以查看当前有线网络接口的功能配置:

R1_Interfaces
其中,千兆以太网eth0 被配置为WAN 功能,百兆以太网eth1 被配置为LAN 功能。

  • 点击顶部的“WAN” 和“LAN” 可对WAN口和LAN口进行设置。

R1_Interfaces_WAN R1_Interfaces_LAN

  • Network->Interfaces界面的配置会保存在文件/etc/config/network中。

5.10 查看Netwrok->Wireless的配置

  • 登录OpenWrt-LuCI界面后,点击顶部的 Network ---> Wireless,可以查看WiFi 热点的设置界面:

R1-Wireless
默认的WiFi 热点名称为“OpenWrt”,手机可以直接连接该热点然后访问互联网,无需密码。

  • 点击“Edit” 按钮,更改Interface Configuration ---> General Setup ---> ESSID 可以更改WiFi热点的名字,点击Save & Apply 保存。

R1-Wireless-ESSID

  • 在Interface Configuration ---> Wireless Security 的 Encryption 可以设置WiFi 热点的加密方式,在Key 设置WiFi热点的密码,点击Save & Apply 保存。

R1-Wireless-Key

  • 在 Network ---> Wireless 页面的 Associated Stations 可以查看当前连接到WiFi 热点的设备。

R1-Wireless-Associated Stations

  • Network->Wireless界面的配置会保存在文件/etc/config/wireless中。

6 Work with FriendlyCore

6.1 Introduction

FriendlyCore is a light Linux system without X-windows, based on ubuntu core, It uses the Qt-Embedded's GUI and is popular in industrial and enterprise applications.

Besides the regular Ubuntu Core's features FriendlyCore has the following additional features:

  • it integrates Qt4.8;
  • it integrates NetworkManager;
  • it has bluez and Bluetooth related packages;
  • it has alsa packages;
  • it has npi-config;
  • it has RPiGPIO, a Python GPIO module;
  • it has some Python/C demo in /root/ directory;
  • it enables 512M-swap partition;

6.2 System Login

  • If your board is connected to an HDMI monitor you need to use a USB mouse and keyboard.
  • If you want to do kernel development you need to use a serial communication board, ie a PSU-ONECOM board, which will

allow you to operate the board via a serial terminal.Here is a setup where we connect a board to a PC via the PSU-ONECOM and you can power on your board from either the PSU-ONECOM or its MicroUSB: PSU-ONECOM-R1.jpg
You can use a USB to Serial conversion board too.
Make sure you use a 5V/2A power to power your board from its MicroUSB port:
Matrix-USB2UART nanopi R1.jpg

  • FriendlyCore User Accounts:

Non-root User:

   User Name: pi
   Password: pi

Root:

   User Name: root
   Password: fa

The system is automatically logged in as "pi". You can do "sudo npi-config" to disable auto login.

  • Update packages
$ sudo apt-get update

6.3 Configure System with npi-config

The npi-config is a commandline utility which can be used to initialize system configurations such as user password, system language, time zone, Hostname, SSH switch , Auto login and etc. Type the following command to run this utility.

$ sudo npi-config

Here is how npi-config's GUI looks like:
npi-config

6.4 Develop Qt Application

Please refer to: How to Build and Install Qt Application for FriendlyELEC Boards

6.5 Setup Program to AutoRun

You can setup a program to autorun on system boot with npi-config:

sudo npi-config

Go to Boot Options -> Autologin -> Qt/Embedded, select Enable and reboot.

6.6 Extend TF Card's Section

When FriendlyCore is loaded the TF card's section will be automatically extended.You can check the section's size by running the following command:

$ df -h

6.7 Transfer files using Bluetooth

Take the example of transferring files to the mobile phone. First, set your mobile phone Bluetooth to detectable status, then execute the following command to start Bluetooth search.:

hcitool scan


Search results look like:

Scanning ...
    2C:8A:72:1D:46:02   HTC6525LVW

This means that a mobile phone named HTC6525LVW is searched. We write down the MAC address in front of the phone name, and then use the sdptool command to view the Bluetooth service supported by the phone:

sdptool browser 2C:8A:72:1D:46:02

Note: Please replace the MAC address in the above command with the actual Bluetooth MAC address of the mobile phone.
This command will detail the protocols supported by Bluetooth for mobile phones. What we need to care about is a file transfer service called OBEX Object Push. Take the HTC6525LVW mobile phone as an example. The results are as follows:

Service Name: OBEX Object Push
Service RecHandle: 0x1000b
Service Class ID List:
  "OBEX Object Push" (0x1105)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 12
  "OBEX" (0x0008)
Profile Descriptor List:
  "OBEX Object Push" (0x1105)
    Version: 0x0100

As can be seen from the above information, the channel used by the OBEX Object Push service of this mobile phone is 12, we need to pass it to the obexftp command, and finally the command to initiate the file transfer request is as follows:

obexftp --nopath --noconn --uuid none --bluetooth -b 2C:8A:72:1D:46:02 -B 12 -put example.jpg

Note: Please replace the MAC address, channel and file name in the above command with the actual one.

After executing the above commands, please pay attention to the screen of the mobile phone. The mobile phone will pop up a prompt for pairing and receiving files. After confirming, the file transfer will start.

Bluetooth FAQ:
1) Bluetooth device not found on the development board, try to open Bluetooth with the following command:

rfkill unblock 0

2) Prompt can not find the relevant command, you can try to install related software with the following command:

apt-get install bluetooth bluez obexftp openobex-apps python-gobject ussp-push

6.8 WiFi

For either an SD WiFi or a USB WiFi you can connect it to your board in the same way. The APXX series WiFi chips are SD WiFi chips. By default FriendlyElec's system supports most popular USB WiFi modules. Here is a list of the USB WiFi modules we tested:

Index Model
1 RTL8188CUS/8188EU 802.11n WLAN Adapter
2 RT2070 Wireless Adapter
3 RT2870/RT3070 Wireless Adapter
4 RTL8192CU Wireless Adapter
5 mi WiFi mt7601
6 5G USB WiFi RTL8821CU
7 5G USB WiFi RTL8812AU

You can use the NetworkManager utility to manage network. You can run "nmcli" in the commandline utility to start it. Here are the commands to start a WiFi connection:

  • Change to root
$ su root
  • Check device list
$ nmcli dev

Note: if the status of a device is "unmanaged" it means that device cannot be accessed by NetworkManager. To make it accessed you need to clear the settings under "/etc/network/interfaces" and reboot your system.

  • Start WiFi
$ nmcli r wifi on
  • Scan Surrounding WiFi Sources
$ nmcli dev wifi
  • Connect to a WiFi Source
$ nmcli dev wifi connect "SSID" password "PASSWORD" ifname wlan0

The "SSID" and "PASSWORD" need to be replaced with your actual SSID and password.If you have multiple WiFi devices you need to specify the one you want to connect to a WiFi source with iface
If a connection succeeds it will be automatically setup on next system reboot.

For more details about NetworkManager refer to this link: Use NetworkManager to configure network settings

If your USB WiFi module doesn't work most likely your system doesn't have its driver. For a Debian system you can get a driver from Debian-WiFi and install it on your system. For a Ubuntu system you can install a driver by running the following commands:

$ apt-get install linux-firmware

In general all WiFi drivers are located at the "/lib/firmware" directory.


6.9 Ethernet Connection

If a board is connected to a network via Ethernet before it is powered on it will automatically obtain an IP with DHCP activated after it is powered up. If you want to set up a static IP refer to: Use NetworkManager to configure network settings


6.10 Custom welcome message

The welcome message is printed from the script in this directory:

/etc/update-motd.d/

For example, to change the FriendlyELEC LOGO, you can change the file /etc/update-motd.d/10-header. For example, to change the LOGO to HELLO, you can change the following line:

TERM=linux toilet -f standard -F metal $BOARD_VENDOR

To:

TERM=linux toilet -f standard -F metal HELLO

6.11 Modify timezone

For exampe, change to Shanghai timezone:

sudo rm /etc/localtime
sudo ln -ls /usr/share/zoneinfo/Asia/Shanghai /etc/localtime




6.12 Connect to USB Camera(FA-CAM202)

The FA-CAM202 is a 200M USB camera. Connect your board to camera module. Then boot OS, connect your board to a network, log into the board as root and run "mjpg-streamer":

$ cd /root/C/mjpg-streamer
$ make
$ ./start.sh

You need to change the start.sh script and make sure it uses a correct /dev/videoX node. You can check your camera's node by running the following commands:

$ apt-get install v4l-utils
$ v4l2-ctl -d /dev/video0 -D
Driver Info (not using libv4l2):
        Driver name   : uvcvideo
        Card type     : HC 3358+2100: HC 3358+2100  / USB 2.0 Camera: USB 2.0 Camera
        Bus info      : usb-1c1b000.usb-1
	...

The above messages indicate that "/dev/video0" is camera's device node.The mjpg-streamer application is an open source video steam server. After it is successfully started the following messages will be popped up:

 
$ ./start.sh
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 1280 x 720
 i: Frames Per Second.: 30
 i: Format............: YUV
 i: JPEG Quality......: 90
 o: www-folder-path...: ./www/
 o: HTTP TCP port.....: 8080
 o: username:password.: disabled
 o: commands..........: enabled

start.sh runs the following two commands:

export LD_LIBRARY_PATH="$(pwd)"
./mjpg_streamer -i "./input_uvc.so -d /dev/video0 -y 1 -r 1280x720 -f 30 -q 90 -n -fb 0" -o "./output_http.so -w ./www"

Here are some details for mjpg_streamer's major options:
-i: input device. For example "input_uvc.so" means it takes input from a camera;
-o: output device. For example "output_http.so" means the it transmits data via http;
-d: input device's subparameter. It defines a camera's device node;
-y: input device's subparameter. It defines a camera's data format: 1:yuyv, 2:yvyu, 3:uyvy 4:vyuy. If this option isn't defined MJPEG will be set as the data format;
-r: input device's subparameter. It defines a camera's resolution;
-f: input device's subparameter. It defines a camera's fps. But whether this fps is supported depends on its driver;
-q: input device's subparameter. It defines the quality of an image generated by libjpeg soft-encoding;
-n: input device's subparameter. It disables the dynctrls function;
-fb: input device's subparameter. It specifies whether an input image is displayed at "/dev/fbX";
-w: output device's subparameter. It defines a directory to hold web pages;

In our case the board's IP address was 192.168.1.230. We typed 192.168.1.230:8080 in a browser and were able to view the images taken from the camera's. Here is what you would expect to observe:
mjpg-streamer-cam500a

6.13 Check CPU's Working Temperature

You can get CPU's working temperature by running the following command:

$ cpu_freq 
Aavailable frequency(KHz):
        480000 624000 816000 1008000
Current frequency(KHz):
        CPU0 online=1 temp=26548C governor=ondemand freq=624000KHz
        CPU1 online=1 temp=26548C governor=ondemand freq=624000KHz
        CPU2 online=1 temp=26548C governor=ondemand freq=624000KHz
        CPU3 online=1 temp=26548C governor=ondemand freq=624000KHz

This message means there are currently four CPUs working. All of their working temperature is 26.5 degree in Celsius and each one's clock is 624MHz.
Set CPU frequency:

$ cpu_freq -s 1008000
Aavailable frequency(KHz):
        480000 624000 816000 1008000
Current frequency(KHz):
        CPU0 online=1 temp=36702C governor=userspace freq=1008000KHz
        CPU1 online=1 temp=36702C governor=userspace freq=1008000KHz
        CPU2 online=1 temp=36702C governor=userspace freq=1008000KHz
        CPU3 online=1 temp=36702C governor=userspace freq=1008000KHz




6.14 How to install and use docker (for armhf system)

6.14.1 How to Install Docker

Run the following commands:

sudo apt-get update
sudo apt-get install docker.io

6.14.2 Test Docker installation

Test that your installation works by running the simple docker image:

git clone https://github.com/friendlyarm/debian-jessie-arm-docker
cd debian-jessie-arm-docker
./rebuild-image.sh
./run.sh

6.15 Using RTC

NanoPi-R1提供了RTC电池接口,使用系统的RTC功能需要连接CR2032带线RTC纽扣电池给板子的RTC电路供电,电池连接如下图所示:
File:NanoPi R1-RTC-BAT-en.png
Dimensional diagram of on board RTC battery connector

      • 待完善****

7 Developer's Guide

8 Resources

8.1 Schematics and Datasheets

9 Update Log

9.1 Jan-02-2019

  • Released English Version