FriendlyCore (based on ubuntu-core with Qt)

From FriendlyELEC WiKi
Revision as of 05:35, 20 July 2016 by Yftan (Talk | contribs) (Ubuntu Core 的使用)

Jump to: navigation, search

查看中文

1 Introduction

Ubuntu Core with Qt-Embedded is a light Linux system without X-windows. It uses the Qt-Embedded's GUI and is popular in industrial and enterprise applications.

Besides the regular Ubuntu core's features our Ubuntu-Core has the following additional features:

  • it supports our LCDs with both capacitive touch and resistive touch(S700, X710, S70)
  • it supports WiFi
  • it supports Ethernet
  • it supports Bluetooth and has been installed with bluez utilities
  • it supports audio playing

2 Download Image Files

Visit the product page of one of the following products and download the firmware nanopi2-ubuntucore-with-qt-embedded-sd4g.img.zip:

  • NanoPi2, NanoPi M2, NanoPi T2: Download
  • Uncompress the file and flash the image to an SD card with either dd under Linux or win32diskimager under Windows.

3 Applications under UbuntuCore

By default our UbuntuCore system brings up a Qt demo application whose GUI is as follows:
Qt-Embedded demo


3.1 WiFi

Open the following file in the command line utility from a serial terminal:

vi /etc/wpa_supplicant/wpa_supplicant.conf

Append the following lines. Replace "ESSID" and "PASSWORD" with your actual ID and password:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=CN
network={
        ssid="ESSID"
        psk="PASSWORD"
        key_mgmt=WPA-PSK
}

If your WiFi router doesn't have a password you can set "key_mgmt" to "NONE" and delete the whole line with "psk=".

Save, exit and run the following commands to restart WiFi connections:

ifdown wlan0
ifup wlan0

3.2 Ethernet Connection

默认插上网线开机,会自动连接并通过DHCP获取IP地址,你可以通过编辑以下文件更改此行为:

vi /etc/network/interfaces

3.3 使用蓝牙

如果你的开发板板载有蓝牙模块,可输入以下命令搜索周边的蓝牙设备:

hcitool scan

使用hciconfig命令来了解接口的状态。


3.4 播放音频

在串口终端执行以下aplay命令播放一段音频:

aplay -t raw -c 2 -f S16_LE -r 44100 /root/test.pcm

3.5 使用触摸屏

电容屏一般无需设置即可使用,电阻屏则需要校准,校准的行为在 /usr/bin/setqt4env 这个脚本中触发的,这个脚本非常有用,它会设置Qt相关的环境变量,会在使用电阻屏时,根据条件判断是否需要运行校准程序。

如果你需要重新校准电阻触摸屏,可以删除以下文件来实现,命令如下:

rm /etc/pointercal

删除之后重新启动系统即可。

4 开发自已的Qt应用

4.1 PC上安装Qt-Embedded

进入产品的下载页面,下载名为 target-ate-4.8.6-to-hostpc.tgz 的压缩包:

  • NanoPi2, NanoPi M2, NanoPi T2: 下载

然后在电脑上,cd到根目录进行解压:

cd /
tar xvzf  ~/target-ate-4.8.6-to-hostpc.tgz

解压完成后,执行 qmake 验证一下安装:

/usr/local/Trolltech/QtEmbedded-4.8.6-arm/bin/qmake -v

应该会得到如下输出信息:
QMake version 2.01a
Using Qt version 4.8.6 in /usr/local/Trolltech/QtEmbedded-4.8.6-arm/lib

4.2 PC上安装交叉编译器(arm-linux-gcc 4.9.3)

首先下载并解压编译器:

git clone https://github.com/friendlyarm/prebuilts.git
sudo mkdir -p /opt/FriendlyARM/toolchain
sudo tar xf prebuilts/gcc-x64/arm-cortexa9-linux-gnueabihf-4.9.3.tar.xz -C /opt/FriendlyARM/toolchain/

然后将编译器的路径加入到PATH中,用vi编辑vi ~/.bashrc,在末尾加入以下内容:

export PATH=/opt/FriendlyARM/toolchain/4.9.3/bin:$PATH
export GCC_COLORS=auto

执行一下~/.bashrc脚本让设置立即在当前shell窗口中生效,注意"."后面有个空格:

. ~/.bashrc

这个编译器是64位的,不能在32位的Linux系统上运行,安装完成后,你可以快速的验证是否安装成功:

arm-linux-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gcc
COLLECT_LTO_WRAPPER=/opt/FriendlyARM/toolchain/4.9.3/libexec/gcc/arm-cortexa9-linux-gnueabihf/4.9.3/lto-wrapper
Target: arm-cortexa9-linux-gnueabihf
Configured with: /work/toolchain/build/src/gcc-4.9.3/configure --build=x86_64-build_pc-linux-gnu
--host=x86_64-build_pc-linux-gnu --target=arm-cortexa9-linux-gnueabihf --prefix=/opt/FriendlyARM/toolchain/4.9.3
--with-sysroot=/opt/FriendlyARM/toolchain/4.9.3/arm-cortexa9-linux-gnueabihf/sys-root --enable-languages=c,c++
--with-arch=armv7-a --with-tune=cortex-a9 --with-fpu=vfpv3 --with-float=hard
...
Thread model: posix
gcc version 4.9.3 (ctng-1.21.0-229g-FA)


4.3 编写并运行Qt版本的Hello world

在PC上建立个helloqt目录并新建一个main.cpp的源文件:

cd ~
mkdir helloqt
vi main.cpp

main.cpp的代码如下:

#include <QApplication>
#include <QPushButton>
int main(int argc, char **argv)
{
        QApplication app (argc, argv);
        QPushButton button ("Hello world !");
        button.show();
        return app.exec();
}

退出vi后,执行以下命令编译:

cd ~/helloqt
/usr/local/Trolltech/QtEmbedded-4.8.6-arm/bin/qmake -project 
/usr/local/Trolltech/QtEmbedded-4.8.6-arm/bin/qmake
make

编译成功后,会得到了 helloqt 的二进制文件,将它上传到开发板后,在串口终端用以下命令运行:

. setqt4env
helloqt -qws&

4.4 开机自动运行Qt程序

以运行上一章节中的 helloqt4 程序为例,假设它放在 /root 目录,则你可以编辑 /etc/rc.local 文件,先删除以下这两行:

cd /usr/local/Trolltech/QtEmbedded-4.8.6-arm/demos/embedded/fluidlauncher
./fluidlauncher -qws&

注意需要保留 . /usr/bin/setqt4env 这一行内容,并在这一行的后面加上 /root/helloqt -qws & 即可。

4.5 开源的Qt程序

开机后显示的界面由Qt Demo换成了一个由友善之臂开发的,开源的Qt程序 (源代码位于/opt目录),该程序启动时显示系统状态信息,例如CPU和内存信息,工作温度和负载等信息,系统同时集成了 qmake,uic 等Qt工具的arm版本,这样你就可以在开发板上直接生成和编译Qt源代码。

5 常见问题

  • 编译Qt程序时出现无法链接到 libts, libz等库

原因是你的 arm-linux-gcc 4.9.3 编译器没有集成这些库,到产品的下载页面重新下载一次编译器,重新安装后即可解决。

  • UbuntuCore源码下载

我们是直接官方使用二进制的文件,UbuntuCore源码可到此链接下下载:http://packages.ubuntu.com/。