Alibaba Cloud HaaS100 IoT development board study notes (3) Preliminary light application-use js to make the small lights flash

Abstract: It is really cool to let JavaScript applications run on the haas100 development board. This method is called "light applications" by Alibaba Cloud. This article will take you to start from scratch, first understand what a light application is, then set up the environment, and then run a simplest "light application" step by step on the haas100 development board. The effect achieved is that after the js code is downloaded to the development board, the designated small light flashes.

table of Contents

Purpose

1 Operation steps

1.1 Setting up a programming environment

1.2 Learn about the light application operating mode

1.3 Compile light application to run firmware

1.4 Burn

1.5 Prepare the environment for writing light applications

1.6 Connect the USB serial port module

1.7 Prepare js program

2. Programming effect

3. Conclusion

4. Extended reading: JavaScript engine for embedded devices

Basic steps for beginners to get started with Alibaba Cloud Haas100 development board

How to adapt the source code of Alibaba Cloud haas100 development board to python3.7 version

Alibaba Cloud HaaS100 IoT Development Board Study Notes (1) Introduction to Hardware Resources

Alibaba Cloud HaaS100 IoT development board study notes (2) Preliminary hardware control-make the lights flash


Hardware: HaaS100 IoT development board

Software: amp-win (command line version), a0s-cube (command line version), win7 x64 system

Purpose

Use the "light application" method to program a single LED light to blink.

1 Operation steps

1.1 Setting up a programming environment

Please refer to the link below for detailed steps. If you have successfully compiled and downloaded helloworld_demo, it proves that you have mastered the basic operations. Please ignore the step of setting up a programming environment.

Basic steps for beginners to get started with Alibaba Cloud Haas100 development board

1.2 Learn about the light application operating mode

Why write knowledge of operating mode as a step?

It is because this knowledge is too important, and not understanding really affects the operation of the next steps.

In the help document of Alibaba Cloud, the following figure describes the operation principle of light application. It may be a bit difficult for students with weak basic knowledge to understand.

I use the following figure to describe the light application. Light application is essentially to burn a java script runtime environment in the development board. This environment can accept js programs on the top, and directly operate the hardware on the bottom. So as to realize complex functions with simple codes.

1.3 Compile light application to run firmware

The name of the firmware is amp_app. It is not certain that the three letters amp are the abbreviations of those words. I guess what kind of operating environment it is, or it supports firmware.


On November 12, 2020, I found out what is amp from the readme file in the C:\Users\Administrator\AliOS-Things\components\amp folder

AliOS Things Mini Program (AMP) is a lightweight application software framework that runs on resource-constrained devices.


Located in the C:\Users\Administrator\AliOS-Things\application\example\amp_app folder.

 

Compile this program like the helloworld program. After this program is programmed into the development board, it does not directly start to perform hardware operations, but starts to parse the js program. In other words, when js asks it to do, it starts to act.

First open the command line.

Then use the cd command to go to the alios-things directory

cd alios-things

Then run the configuration command

aos make amp-app@haas100 -c config

Then compile

aos make

The interface is like the following figure. If the compilation is not successful, please refer to the basic steps of getting started with Alibaba Cloud Haas100 development board for beginners

1.4 Burn

First, ensure that the development board is powered, and connect the Micro USB cable to the computer, and ensure that the USB driver is successfully installed.

Enter the directory C:\Users\Administrator\AliOS-Things\platform\mcu\haas1000\release\write_flash_gui

Find burning tool

Double click to open

Set the serial port number

Select burn

You can press the reset button (the one with the short key handle) to start programming. After successful burning, the preparation of light application firmware is completed.

 

1.5 Prepare the environment for writing light applications

In fact, it is a tool that runs on the windows command line.

Please click the blue font below to download. Or click to download through Alibaba Cloud official documents.

Alibaba Cloud officially recommends light application command line tools

The content of the folder after decompression is

This tool is called the "command line" tool. It runs under the command line. If you double-click the green icon amp, a command line window will pop up and then flash back.

Before using it, it is recommended to copy this directory to my document directory, which is the directory directly entered after the cmd command line is opened.

For example, the location I copied is C:\Users\Administrator\amp-win

After entering the amp-win directory through the cd command, enter the following command.

amp device list

 

Note that it is not the command with dots and slashes in the Alibaba Cloud help document, and it does not need to have the exe suffix.

The result of the operation is as follows. At this time, the development board is only connected to the USB cable for debugging information, and not to the USB serial port module. Despite the red message, it at least proves that the tool is running.

1.6 Connect the USB serial port module

The module I use is as shown below. Two data lines are connected externally: TXD and RXD, which provide sending and receiving functions respectively. Others do not need to be connected, because the serial port information line has been connected to the computer, and the GND is already at the same level.

Connect according to the USB serial port transceiver and HAAS100 development board transceiver connection. And connect GPIO47 to 3.3V through DuPont line.

The physical connection diagram is shown in the figure below. Pulling up to 3.3V is to make the development board ready to receive the js program sent by the computer. The purpose of using the USB serial port module is to not conflict with the information serial port.

Press the reset button, if the red LED double flashes intermittently, it proves that the firmware runs successfully.

1.7 Prepare js program

Open the app folder in the amp-win directory

 

Modify the app.js and app.json files separately

 

app.js code is as follows

var gpio = require('gpio');

var led3 = gpio.open({
  id: 'LED3',
  success: function() {
      console.log('gpio: open led success')
  },
  fail: function() {
      console.log('gpio: open led failed')
  }
});

var vol = 0;

setInterval(function() {
  vol = 1 - vol;
  led3.writeValue(vol);
  console.log('led set value ' + vol);
}, 1000);

app.json code is as follows

{
    "version": "1.0.0",
    "io": {
	 "LED3": {
            "type": "GPIO",
            "port": 36,
            "dir": "output",
            "pull": "pulldown"
			}
	},
    "debugLevel": "DEBUG"
}

After editing, be sure to click Save.

 

1.8 Use the amp command line tool to transfer the program to the development board

The two instructions used are:

The first command is to display the current serial port number

amp seriallist

The second command is to burn with the serial number corresponding to the USB serial port

amp serialput app com14

When the following interface appears, the programming is successful.

 

2. Programming effect

As shown in the figure below, the LED selected in the red frame blinks.

 

3. Conclusion

The development of haas100 in a light application method has several advantages: first, you don’t need to repeatedly modify the underlying code, just modify the js program directly; second, the code is very simple; third, you can burn the hardware firmware once; Fourth, it has an online hot update function, laying the foundation for the development of mature products. After mastering the basic steps of building a basic environment and light application operations, using this development method will greatly improve development efficiency.

 

4. Extended reading: JavaScript engine for embedded devices

Why choose javascript for IOT development?

A better explanation is: IOT lacks a key system---application.

IoT (Internet of Things) is the future recognized by everyone. But what is embarrassing is that these cool products that represent the future only seem to exist in the PPT of industry insiders. What really enters the lives of ordinary people is mostly just some "ordinary hardware with Wi-Fi". Like most of the problems encountered in the process of ecological popularization, IoT lacks a key system-application. The lack of applications makes it difficult to create a user ecology. However, this is not entirely the responsibility of the developer. In most cases, developers are in a state that their concubines cannot do, because "embedded development" involving hardware requires a lot of underlying hardware code base, which makes the majority The software program is daunting. (See the link https://www.sohu.com/a/71527621_114877 ).

Previously, the performance of embedded processors was relatively weak, not enough to support the operation of javascript engine. After all, JavaScript ("JS" for short) is an interpreted or just-in-time compiled high-level programming language. This feature of interpreting and executing on the CPU The requirements are higher.

Nowadays, CPUs are getting stronger and stronger, so the convenient development features of javascript will definitely become more and more popular (graphical development tools will speed up this process).

Searching for javascript engines on the Internet, I found many. For example, the picture below

There is also the following, duktape is open source on gitee, interested students can download and study.

The link is https://gitee.com/mirrors/duktape/tree/66287cfb4f6afc1db0e647bc423e64f79c4b90f4

Please refer to other supporting documents

 

Basic steps for beginners to get started with Alibaba Cloud Haas100 development board

How to adapt the source code of Alibaba Cloud haas100 development board to python3.7 version

Alibaba Cloud HaaS100 IoT Development Board Study Notes (1) Introduction to Hardware Resources

Alibaba Cloud HaaS100 IoT development board study notes (2) Preliminary hardware control-make the lights flash

 

 

 

Guess you like

Origin blog.csdn.net/youngwah292/article/details/109540717