基于mini5350的WIFI视频小车

来源:互联网 发布:4g逛淘宝费流量么 编辑:程序博客网 时间:2024/05/01 13:53


福爱迪电子WIFI视频小车说明书










版本:1.0
2015-1-9
王少华@福爱迪电子
wang.2800@163.com
QQ:1291777917

版权声明

本产品附带的电路原理图、PCB布局布线图及相关的源代码仅限于学习和科研用途,如用于商业目的并对福爱迪电子造成经济损失,福爱迪电子将保留追究法律责任的权利。
特此声明。

目 录
1 产品简介        4
1.1 产品特点        4
1.2 发货清单        4
1.3 装配步骤        4
1.4 注意事项        5
2  OpenWrt开发环境搭建        6
2.1 安装开发工具        6
2.2 下载源代码        6
2.3 OpenWrt配置        6
2.4 OpenWrt编译        8
2.5 通过OpenWrt系统更新固件        8
2.6 通过tftp方式更新固件        9
3 应用程序开发        13
3.1 WIFI视频小车固件编译        13
3.2 WIFI视频小车运行环境配置        13
3.3 搭建自己的OpenWrt软件仓库        14
3.4 HelloWorld应用程序开发        14
4 安卓端APK的编译        19
4.1 搭建安卓开发环境        19
4.2 WIFI视频小车APK应用编译        19

1 产品简介
1.1 产品特点
        安卓(Android)手机或平板通过视频控制小车的前、后、左、右运动;
        TT马达,四轮驱动,动力强劲;
        自带18650移动电源,一次充电可玩3小时左右;
        安装好的全套小车仅需299元。
1.2 发货清单
(1)智能小车一套,包括:
        Mini5350学习板 1块;
        4dbi PCB天线 1根;
        鱼嘴电源及18650电池 2套;
        L298N电机驱动模块 1个;
        TT马达四驱小车车体 1套;
        USB摄像头 1个;
(2)USB转串口线 1根;
(3)USB转DC005电源线 1根;
(4)MicroUSB充电线 1根;
(5)装配说明1份;
(6)资料包 1份(通过网络索取)。
1.3 装配步骤
(1)检查主控板的IO10、IO11、IO12、IO13、GND是否与驱动板的IN1、IN2、IN3、IN4、GND连接完好;
(2)检查主控板的5V电源接口是否正确插入,红色为5V,黑色为GND,千万不要插反了;
(3)把USB摄像头插入主控电路板USB接口;
(4)把主控板USB电源口插入主控板电源,此时主控板红色电源指示灯亮起;
(5)把驱动板USB电源口插入小车电源,此时驱动板红色LED灯亮起;
(6)大约过1分钟后,使用安卓(Android)手机搜索“iotway”WIFI信号并加入;
(7)打开手机浏览器输入http://192.168.199.1/car.apk,下载并安装apk应用;
(8)打开安装好的视频小车应用,如果一切正常应该能看到视频了,如果有问题请按照上面的步骤再检查一遍;
(9)按键按下时走,抬起时停, 开始玩吧!
(10)不玩时,可以按一下充电宝电源关闭(有的电源是按两下),再按一下是打开,由于按键开关是软件控制的,所以最好直接拔下USB供电线断电。


1.4 注意事项
(1)电源指示灯四格全亮为满电,一格是25%,当低于一格时会自动关闭,请充电,充满四格时请停止充电,尽量不要过充,尽量拔下USB电源线再充电;
(2)摄像头如果模糊,请旋转一下摄像头的镜头,调整好焦距;
(3)使用小车时,尽量不要碰撞,特别是两侧的USB电源接口;
(4)请在室温环境下使用视频小车,低温环境拿到室温环境等待5分钟;
(5)如有其它不明原因的问题,请重启小车,如仍有问题请联系QQ:1291777917。

2  OpenWrt开发环境搭建
OpenWrt 是一个嵌入式的 Linux 发行版(主流路由器固件有 dd-wrt,tomato,openwrt三类),OPENWRT系统只需要4M flash和32M SDRAM即可正常运行,硬件成本很低。OpenWrt提供opkg包管理,应用程序非常丰富,可以在线安装应用程序 ,类似于apt-get、yum等工具,系统维护起来极为方便。
推荐使用ubuntu开发环境搭建,也可以直接到www.iotway.com下载基本开发环境镜像(用户名和密码都是user),然后直接跳到第3节开始应用程序开发。
2.1 安装开发工具
sudo apt-get update
sudo apt-get install subversion
sudo apt-get install gcc g++ binutils patch bzip2 flex bison make autoconf gettext
sudo apt-get install texinfo unzip sharutils ncurses-term zlib1g-dev gawk libssl-dev

2.2 下载源代码
在用户目录下创建目录
mkdir mini5350
下载代码
svn co svn://svn.openwrt.org/openwrt/trunk
下载并安装feeds代码包
./scripts/feeds update  -a
./scripts/feeds install  -a
2.3 OpenWrt配置
rm  -rf  tmp
make  menuconfig        
做如下选择:
TargetSystem: Ralink RT288x/RT3xxx
Subtarget:RT3x5x/RT5350 based boards
TargetProfile: HAME MPR-A2
LuCI--> Collections --> luci
OpenWrt默认关闭Wifi,改成开启,修改/trunk/package/kernel/mac80211/files/lib/wifi/mac80211.sh,找到如下行:
#REMOVE THIS LINE TO ENABLE WIFI:
option disabled 1
修改为:
#REMOVE THIS LINE TO ENABLE WIFI:
#option disabled 1

周围的路由器很多使用的11信道,为了减少相互干扰,我们改成auto信道,修改trunk/package/kernel/mac80211/files/lib/wifi/mac80211.sh,找到如下行:
channel=”11”
改成
channel=”auto”

如果需要配置linux内核,可以通过以下命令:
make  kernel_menuconfig

2.4 OpenWrt编译
在trunk目录下make即可。
make
第一次编译会花很长的时间,因为还需要从网上下载很多软件包和工具,如果由于网络原因无法下载某些重要软件而导致编译失败,也可以自己找到相应的软件包放到dl目录下,比如LuaSrcDiet-0.12.1.tar.bz2源码包。
在编译过程中可能会出现错误,可通过V=s参数显示详细的编译过程:
make V=s
编译成功之后会在trunk/bin/ramips/目录下生成固件:openwrt-ramips-rt305x-mpr-a2-squashfs-sysupgrade.bin
2.5 通过OpenWrt系统更新固件
连接iotway热点,通过浏览器访问mini5350开发板,例如:192.168.199.1,选择system->flash firmware。
选择编译好的固件并上传,然后flash image。
然后 proceed执行烧写。
不要断电,等待mini5350自己重新启动。
系统重启成功后,热点名称为iotway,mini5350地址为192.168.199.1。路由器连接外网方式为自动获取IP,如果要修改成拨号上网方式可以通过浏览器登录路由器IP,设置网络->接口->WAN编辑里的协议部分,可以试一下了。
如果想通过putty用SSH协议登录mini5350,需要先设置一下root的密码,在5350上:
passwd root
设置完密码后,就可以通过SSH登录mini5350了。
这只是个基本系统,并没有wifi视频小车的应用软件。
2.6 通过tftp方式更新固件
如果自带的OPENWRT系统损坏,或其它原因无法启动,或者没有无线网卡,也可以通过TFTP软件用网线烧写固件。
(1)使用usb转串口连接mini5350和PC;
(2)通过一根网线把mini5350学习板和PC连接;
(3)最好把防火墙、360安全卫士、虚拟机等先关闭;
(4)设置主机IP为192.168.199.1;
(5)在windows环境下,把固件复制到Tftpd32.exe(在工具软件目录里)同一目录下,并打开Tftpd32.exe软件;
(6)打开串口工具putty,设置好串口号,波特率设置为57600。
(7)启动mini5350并输入2,进入烧录程序;
(8)输入Y,确保主机与mini5350在同一网段,填写好板子的IP地址、下载主机IP地址和下载的固件文件名(固件名可以复制后粘贴到putty上,以防输错);
(9)固件更新
(10)固件烧录成功后,mini5350启动到OpenWRT命令行界面,拔掉网线,连接热点即可。
注意:通过web方式烧录的固件,原系统配置文件保持不变;通过TFTP方式烧录的固件,原系统配置文件会被覆盖。


3 应用程序开发
3.1 WIFI视频小车固件编译
示例程序里的openwrt-ramips-rt305x-mpr-a2-squashfs-sysupgrade.bin是稳定版本固件,而提供的源代码都是功能版本,是有BUG的,仅用于学习用途。
把资料示例代码里的gpio驱动代码复制到(windows下复制ubuntu下粘贴即可)开发环境的trunk/package/kernel目录下;
把示例代码里car-server、yuv2jpeg代码复制到开发环境的trunk/package/utils目录下;
make menuconfig
到kernel modules->USB support里把kmod-video-core和kmod-video-uvc编译进固件(按两下空格变成星花*);
到kernel modules->Other modules里把kmod-gpio编译进固件;
到utilities里把car-server和yuv2jpeg编译进固件;
make 重新生成固件后(编译时会自动联网下载libjpeg,请保持网络畅通),通过第2节中讲述的方法烧录固件。

3.2 WIFI视频小车运行环境配置
通过USB转串口连接视频小车的mini5350电路板,做如下配置:
vi /etc/config/network
修改interface ‘lan’中的ip为192.168.199.1
vi /etc/config/wireless
修改wifi-iface中的ssid为iotway
vi /etc/rc.local
在exit 0之前添加:
rmmod /lib/modules/3.14.18/ehci-platform.ko
modprobe ehci-platform
modprobe gpio
sleep 1
car-server > /dev/NULL &
yuv2jpeg > /dev/NULL &
/etc/init.d/firewall disable &

重新启动WIFI小车系统,使用安卓手机试一下WIFI视频小车是不是运行起来了!
3.3 搭建自己的OpenWrt软件仓库
PC连接mini5350生成的wifi热点,设置虚拟机网络为桥接模式,把openwrt开发环境PC设置成与mini5350处于同一网段:
sudo ifconfig eth0 192.168.199.10 netmask 255.255.255.0
sudo route add default gw 192.168.199.1
安装lighttpd服务器,并设置opkg软件仓库:
sudo apt-get install lighttpd
sudo ln -s ~/mini5350/trunk/bin/ramips/packages /var/www/package
修改mini5350的仓库源:
vi /etc/opkg.conf
修改为:

在mini5350电路板上:
opkg update
opkg remove car-server
opkg install car-server

如果只想编译安装单个应用程序,比如car-server,在trunk目录下:
make package/utils/car-server/clean
make package/utils/car-server/compile
make package/utils/car-server/install
make package/index
再通过opkg安装就可以了。
3.4 HelloWorld应用程序开发
在package/utils文件夹里面新建helloworld源码包(也可以从示例代码里直接复制到package/utils下):
cd package/utils
mkdir helloworld
cd helloworld
mkdir src
touch src/Makefile   /* helloworld 编译Makefile */
touch ./Makefile /*建立顶层Makefile,这个Makefile文件是描述包信息的*/
touch src/helloworld.c /*创建helloworld.c源代码*/

helloworld.c程序:
/***************** helloworld.c*****************/

#include <stdio.h>
#include <unistd.h>
int main(void)
{
     printf("Hello world\n");
     return 0;
}

编辑helloworld的编译src/Makefile:(注意TAB键,不是空格)
# build helloworld executable when user executes "make"

helloworld: helloworld.o
$(CC) $(LDFLAGS) helloworld.o -o helloworld

helloworld.o: helloworld.c
$(CC) $(CFLAGS) -c helloworld.c

# remove object files and executable when user executes "make clean"
clean:
rm *.o helloworld

编写包的描述Makefile,(注意TAB键,不是空格)
Makefile文件模板内容如下:
##############################################
# OpenWrt Makefile for helloworld program#
#
# Most of the variables used here are defined in
# the include directives below. We just need to
# specify a basic description of the package,
# where to build our program, where to find
# the source files, and where to install the
# compiled program on the router.
#
# Be very careful of spacing in this file.
# Indents should be tabs, not spaces, and
# there should be no trailing whitespace in
# lines that are not commented.
#
##############################################
include $(TOPDIR)/rules.mk
# Name and release number of this package
PKG_NAME:=helloworld
PKG_RELEASE:=1

# This specifies the directory where we're going to build the program.
# The root build directory, $(BUILD_DIR), is by default the build_mipsel
# directory in your OpenWrt SDK directory
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

# Specify package information for this program.
# The variables defined here should be self explanatory.
# If you are running Kamikaze, delete the DESCRIPTION
# variable below and uncomment the Kamikaze define
# directive for the description below
define Package/helloworld
        SECTION:=utils
        CATEGORY:= Utilities
        TITLE:=Helloworld -- prints a snarky message
endef

# Uncomment portion below for Kamikaze and delete DESCRIPTION variable above
define Package/helloworld/description
        If you can't figure out what this program does, you're probably
        brain-dead and need immediate medical attention.
endef

# Specify what needs to be done to prepare for building the package.
# In our case, we need to copy the source files to the build directory.
# This is NOT the default.  The default uses the PKG_SOURCE_URL and the
# PKG_SOURCE which is not defined here to download the source from the web.
# In order to just build a simple program that we have just written, it is
# much easier to do it this way.
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

# We do not need to define Build/Configure or Build/Compile directives
# The defaults are appropriate for compiling a simple program such as this one

# Specify where and how to install the program. Since we only have one file,
# the helloworld executable, install it by copying it to the /bin directory on
# the router. The $(1) variable represents the root directory on the router running
# OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
# directory if it does not already exist.  Likewise $(INSTALL_BIN) contains the
# command to copy the binary file from its current location (in our case the build
# directory) to the install directory.
define Package/helloworld/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
endef

# This line executes the necessary commands to compile our program.
# The above define directives specify all the information needed, but this
# line calls BuildPackage which in turn actually uses this information to
# build a package.
$(eval $(call BuildPackage,helloworld))

返回trunk目录
make menuconfig
在utilities中把helloworld选中为模块,保存.config。
Make package/utils/helloworld/compile
make package/utils/helloworld/install
make package/index

编译结果helloworld_1_ramips_24kec.ipk会放在bin/ramips/packages/base目录下,使用前面搭建的软件仓库,在Mini5350上:
opkg update
opkg install helloworld
./helloworld

总结一下开发应用程序步骤:
(1)        在package目录下的分类目录里创建自己的包目录;
(2)        写包的Makefile(都是包的信息,可以跟怎样编译关系不大,可以参考helloworld的Makefile模板);
(3)创建src目录及C源代码;
(4)写编译Makefile;
(5)make menuconfig选中;
(6)编译;
(7)安装。
你的源码怎样编译可以完全取决于src目录中Makefile,只要在此Makefile中写好依赖的共享库路径、名、头文件名。已经编译好的包生成的共享库都在staging_dir目录里,自己找到添加到Makefile即可,比如一个需要链接别的库的编译Makefile如下:
iot-server: iot-server.o
        $(CC) $(LDFLAGS) iot-server.o -o iot-server -L$(STAGING_DIR)/usr/lib/mysql -lmysqlclient

iot-server.o: iot-server.c
        $(CC) $(CFLAGS) -c iot-server.c

# remove object files and executable when user executes "make clean"
clean:
        rm *.o iot-server

4 安卓端APK的编译
4.1 搭建安卓开发环境
安装JDK、Eclipse、ADT、Android SDK,这个网络上有大把的资料,这里不再赘述。
4.2 WIFI视频小车APK应用编译
安装好开发环境后,把示例程序目录下的com.example.car.MainActivity导入安卓开发环境,在eclipse的file菜单里import导入工程。
然后编译安卓端程序,在工程的bin目录下生成com.example.car.MainActivity.apk,可以把生成的apk文件直接安装到手机,也可以把apk文件上传到mini5350的/www目录下,这样就可以通过手机下载安装了。

0 0
原创粉丝点击