本页目录
系统环境
第一个轻应用示例
附录
更多示例代码
HaaS600 Kit
HaaS600 Kit 是一款基于 HaaS600系列模组评估的高性价比开发板。可应用于共享控制、金融支付、智能语音、泛工业等场景的智能硬件产品开发。
HaaS600 Kit 套件包含以下物料:
· 开发板 x 1
· micro-USB线缆 x 1
· 5V/2A电源适配器 x 1
· 4G天线 x 1
· GPS天线 x 1
系统环境
连接设备
按照下图所示将开发电脑跟设备的调试/用户串口通过MicroUSB连接,连接后,将在PC设备管理器中出现两个串口,分别用于调试和用户串口输入输出。
安装USB转串口驱动
· Windows XP/Vista
· Windows7/8/8.1
· Windows10
· MacOS
安装完成之后,在设备管理器中可以看到以下虚拟串口:
Windows
MacOS
Note:
1.不同的电脑生成的串口号和名称不一样,以实际生成的为准。
2.生成的两个串口,一个是debug串口(查看运行日志,只读),另一个是用户串口(JavaScript交互式解释器或其他用途)
开发工具
轻应用开发使用一套命令行工具管理和推送应用脚本到设备。
下载命令行工具:
· Mac版
· Windows版
Note:
Mac版需要设置执行权限:chmod +x ./amp
请参考:命令行工具
将命令行工具解压到工作目录,如图所示对应文件
├── amp # 命令行工具
├── app # 示例代码(hello world)
│ ├── app.json
│ └── app.js
└── bindings.node # 本地更新库码
第一个轻应用示例
· 查看设备连接状态
在命令行工具下使用该命令查看设备连接状态
./amp.exe seriallist
COM194
COM195
Note:
如果返回值跟设备管理器中生成的一致,说明设备连接和命令行工具运行正常
命令行工具默认示例代码运行hello world程序,此处使用LED Blink来作为第一个轻应用示例来介绍。
使用下面的app.js 和 app.json文件替换命令行工具示例代码目录下的同名文件,如下:
LED Blink app.json
{
"version": "1.0.0",
"io": {
"D13": {
"type": "GPIO",
"port": 33,
"dir": "output",
"pull": "pulldown"
}
},
"debugLevel": "DEBUG"
}
LED Blink app.js:
var gpio = require('gpio');
var led = gpio.open({
id: 'D13'
});
var vol = 0;
setInterval(function() {
vol = 1 - vol;
led.writeValue(vol);
console.log('gpio: led set value ' + vol);
vol = led.readValue();
console.log('gpio: led get value ' + vol);
}, 1000);
本地热更新
· 切换到下载模式
将下载/运行模式切换开关(MODE)拨到DL侧,并通过电源选择开关(POWER SWITCH)断电重启,稍等片刻待AMP_STU指示灯间歇性双闪,如下图,说明设备已经进入本地下载模式。
· 通过amp工具推送应用代码到设备
./amp.exe seriallist
COM194
COM195
./amp.exe serialput ./app COM194
Note:
Windows环境下,热更新命令的串口号需要大写。
· 切换到运行模式(RUN)并复位
· 运行效果如图:
在线热更新
在已插SIM卡有网络连接的情况下,也可参考在线应用热更新推送轻应用代码到目标设备。
附录
硬件资源介绍
硬件资源映射表
功能列表(部分)
· 文件系统 FS
· 系统信息 SYSTEM
· 键值对存储 KV
· 电源管理 PM
· 硬件I/O
UART
GPIO
I2C
SPI
ADC
DAC
PWM
TIMER
RTC
WDG
· 网络协议
UDP
TCP
MQTT
HTTP
· 高阶功能
IoT 阿里云IoT平台连接组件
audioplayer 音频播放组件
app.json 参考示例
{
"version": "1.0.0",
"io": {
"I2C0": {
"type": "I2C",
"port": 0,
"addrWidth": 7,
"freq": 400000,
"mode": "master",
"devAddr": 72
},
"ADC0": {
"type": "ADC",
"port": 0,
"sampling": 12000000
},
"ADC1": {
"type": "ADC",
"port": 1,
"sampling": 12000000
},
"UART1": {
"type": "UART",
"port": 1,
"dataWidth": 8,
"baudRate": 9600,
"stopBits": 1,
"flowControl": "cts",
"parity": "none"
},
"UART2": {
"type": "UART",
"port": 2,
"dataWidth": 8,
"baudRate": 115200,
"stopBits": 1,
"flowControl": "disable",
"parity": "none"
},
"SPI1": {
"type": "SPI",
"port": 1,
"mode": "master",
"freq": 3250000
},
"PWM0": {
"type": "PWM",
"port": 31,
"mode": "master",
"freq": 3250000
},
"PWM1": {
"type": "PWM",
"port": 32,
"mode": "master",
"freq": 3250000
},
"D0": {
"type": "GPIO",
"port": 51,
"dir": "output",
"pull": "pulldown"
},
"D1": {
"type": "GPIO",
"port": 52,
"dir": "output",
"pull": "pulldown"
},
"D2": {
"type": "GPIO",
"port": 17,
"dir": "irq",
"pull": "pulldown",
"intMode": "both"
},
"D3": {
"type": "GPIO",
"port": 16,
"dir": "irq",
"pull": "pullup",
"intMode": "both"
},
"D4": {
"type": "GPIO",
"port": 59,
"dir": "output",
"pull": "pulldown"
},
"D5": {
"type": "GPIO",
"port": 121,
"dir": "output",
"pull": "pulldown"
},
"D6": {
"type": "GPIO",
"port": 54,
"dir": "output",
"pull": "pulldown"
},
"D7": {
"type": "GPIO",
"port": 53,
"dir": "output",
"pull": "pulldown"
},
"D8": {
"type": "GPIO",
"port": 124,
"dir": "output",
"pull": "pulldown"
},
"D9": {
"type": "GPIO",
"port": 122,
"dir": "output",
"pull": "pulldown"
},
"D10": {
"type": "GPIO",
"port": 34,
"dir": "output",
"pull": "pulldown"
},
"D11": {
"type": "GPIO",
"port": 36,
"dir": "output",
"pull": "pulldown"
},
"D12": {
"type": "GPIO",
"port": 35,
"dir": "output",
"pull": "pulldown"
},
"D13": {
"type": "GPIO",
"port": 33,
"dir": "output",
"pull": "pulldown"
},
"D14": {
"type": "GPIO",
"port": 57,
"dir": "output",
"pull": "pulldown"
},
"D15": {
"type": "GPIO",
"port": 32,
"dir": "output",
"pull": "pulldown"
},
"D16": {
"type": "GPIO",
"port": 31,
"dir": "output",
"pull": "pulldown"
},
"D17": {
"type": "GPIO",
"port": 76,
"dir": "output",
"pull": "pulldown"
}
},
"debugLevel": "DEBUG",
"repl": "disable"
}
更多示例代码
· 打包下载(需注册gitee账号):
https://gitee.com/alios-things/amp-examples/repository/archive/master.zip