HarmonyOS Device Development experience based on Hi3861

Hello everyone, I am a non-famous Copy raiding lion, this should be the last Copy Raiding lion 2020 “Hello, World” — based on Harmony OS Hi3861 development board for Internet of Things application development actual situation. Copy Lion’s road to “Hello World” [1] has never been smooth, this attempt to launch (Copy) (bei) Internet of Things application also took a lot of twists and turns, finally ran through the buzzer version of “Jingle Bells”, I wish you all a happy New Year!

Development and Debugging

For detailed documentation and tutorials, please refer to HarmonyOS ‘official documentation and vendors’ open source tutorials such as HiHope’s HarmonyOS Internet of Things Application Development Video and codebase, or BearPi’s HM Nano Hongmon Season Release video and codebase. We use the Wi-Fi IoT Hi3861 kit produced by HiHope, which covers one core board (Hi3861 WLAN module) and seven expansion modules (traffic light board, colorful light board, OLED board, NFC board, robot expansion board). Contains a wealth of peripherals such as I2C (The Inter Integrated Circuit), PWM (Pulse Width Modulation), GPIO (General Purpose Input/Output) and multiplexing ADC (Analog to Digital Converter) and so on, very high playability. There are also a lot of great people in Hongmeng community who create a lot of creative ways, such as playing music through the buzzer, playing video through the OLED, playing Tetris mini-games, controlling DJI drones… Would you like to try one? Find out more about HarmonyOS Devic development along with Copy Raiders.

3.1 Start with lighting

If you notice that the HarmonyOS Device documentation provides a sample application for Hi3861, in addition to “Hello, World” and WLAN module networking, a Demo of LED peripherals control is provided in the Device development section, By calling HarmonyOS ‘NDK interface, GPIO control is implemented to achieve the LED flashing effect, which is commonly referred to as “lighting”. Download the source code in our directory: ` harmonyos/openharmony/applications/sample/wifi – iot/app/iothardware/led_example ` c [2]. Before copying the code, take a look at the source directory:

.├ ─ applications # wifi-iot Such as camera │ └ ─ ─ sample │ ├ ─ ─ ─ ─ camera # camera products │ └ ─ ─ ─ ─ wifi - iot # wifi connection products ├ ─ ─ base # based software service subsystem & hardware service subsystem ├ ─ ─ the build # │ ├─ Lite ├─ Build.py # ├─ Device # Qemu Exercises for Different kerls running in Different Single-board Exercises # docs # OpenHarmony Developer document ├─ domains # Enhance software service subsystem set │ └ ─ ─ iot ├ ─ ─ # drivers drive subsystem │ ├ ─ ─ HDF │ └ ─ ─ liteos ├ ─ ─ foundation # system infrastructure of subsystem set ├ ─ ─ the kernel # kernel subsystems ├ ─ ─ the out ├─ ├─ Exercises # ├─ Exercises # ├─ exercises # ├─ exercises # ├─ Exercises # ├─ Exercises # ├─ Exercises # ├─ Exercises # ├─ Exercises # ├─ Exercises # ├─ Exercises # ├─ Exercises # ├ ─ ─ utils commonly used tool set # └ ─ ─ vendor # manufacturers provide software ├ ─ ─ hisi └ ─ ─ huaweiCopy the code

Take a look at our development directory applications/sample/ Wifi-iot:

├ ─ ─ app │ ├ ─ ─ BUILD. Designed.the gn # entrance │ ├ ─ ─ demolink # the Hello, World │ │ ├ ─ ─ BUILD. Designed.the gn │ │ └ ─ ─ the helloworld. C │ ├ ─ ─ iothardware # Lighting Demo │ │ ├ ─ ─ BUILD. Designed.the gn │ │ └ ─ ─ led_example. C │ ├ ─ ─ samgr # service management system framework subsystem function │ │ ├ ─ ─ bootstrap_example. C │ │ ├ ─ ─ Broadcast_example. C │ │ ├ ─ ─ BUILD. Designed.the gn │ │ ├ ─ ─ example. H │ │ ├ ─ ─ feature_example. C │ │ ├ ─ ─ maintenance_example. C │ │ ├ ─ ─ Service_example. C │ │ ├ ─ ─ service_recovery_example. C │ │ ├ ─ ─ specified_task_example. C │ │ └ ─ ─ task_example. C │ └ ─ ─ ├ ─ ├ ─ press # imp #Copy the code

Based on the existing code, to complete the “light up” practice, we just need to modify the entry file build.gn in VSCode Remote:

import("//build/lite/config/component/lite_component.gni")

lite_component("app") {

    features = [

        "iothardware:led_example"

    ]

}

Copy the code

Then open a new VSCode window to configure and record DevEco Device Tool. After recording, you can view the output of the development board through the serial port Tool. After resetting the development board, the LED light flashes along with the rhythm sound.

HarmonyOS Devic Environment – Lighting experience development and Commissioning

In order to simplify the operation, I installed the serial debugging tool SSCOM, so before each firing I first close the serial port in SSCOM, after firing, I open the serial port in SSCOM, convenient point is that you do not have to input the serial port every time, when sending operation instructions more quickly. It is worth noting that the serial port must be closed before firing, otherwise it will prompt that the serial port is busy and cannot be fired normally.

HarmonyOS Devic Environment setup – Serial port debugging tool

Here light Demo through GPIO (general-purpose input/output, General type input/output), also can realize the operation of “red, yellow and green” LED and buzzer on the traffic light board. Our buzzer version of Jingle Bells is also based on GPIO.

3.2 To the road of Copy

In the interconnected world of everything, sensors undertake most of the data collection work. The dazzling light board in the WIFI-IOTHI3861 kit contains photosensitive and human infrared, and the environment detection board contains temperature and humidity sensors and gas sensors. This part mainly involves ADC and I2C, so when we are developing sensor applications, Need to give special attention to the common base in the library wifiiot_adc. H and wifiiot_i2c. J h, documents are located in [openharmony/base/iot_hardware/interfaces/kits/wifiiot_lite] (HTTP: / / https://gitee .com/openharmony/iothardware_interfaces_kits_wifiiot_lite “Openharmony/base/iot_hardware/interfaces/kits/wifiiot_lite”) directory. In addition, if the peripheral interface is used during compilation, it is necessary to pay attention to whether the corresponding configuration has been set properly. For example, if I use I2C, then in the compilation configuration file vendor\hisi\hi3861\hi3861\build\config\usr_config.mk, # CONFIG_I2C_SUPPORT is not set to CONFIG_I2C_SUPPORT=y… Of course, I didn’t know these “tricks” until I went down the Copy path in HarmonyOS Device development, which I’ll never go back to. I’m like these sensors, gathering “knowledge” in a given program…

In the spirit of learning, I clone the HiHope warehouse directly into my Harmonyos/OpenHarmony directory. Of course, since it is Copy, I will use it according to the LICENSE rules. If I do not comply with the LICENSE rules, I will only use it for personal learning, so I will not be “condemned” [3]. Please start Copy:

cd /root/harmonyos/openharmony/applications/sample/wifi-iot

git clone https://gitee.com/hihopeorg/HarmonyOS-IoT-Application-Development.git

mv HarmonyOS-IoT-Application-Development/* ./

Copy the code
HarmonyOS Devic Environment setup – Obtain learning materials

As a result, in the department of front-end development of Copy siege lion ticket circle and more dynamic development of the Internet of things, “amateurs watch the fun, professionals see jokes”, but ask yourself, such a Copy, I am still very willing to try – zero basis can also play, good! After the Copy operation, I began to try to compile and burn each Demo. Although it was difficult to read the code (I was too white), some key codes could be changed reluctantly, such as “1 to 2″… In general, I experienced the pleasure of hands-on practice. Especially when I saw the buzzer version of “Two Tigers”, I instantly thought of that Christmas Eve. After working overtime late at night in a strange city, my shadow was stretched long under the street lamp. I swept a shared bike as usual, and the moment it was unlocked, the music sounded…

The resources

[1]

“Hello World” Copy siege puma road: https://juejin.cn/post/6901366425241190407


[2]

harmonyos/openharmony/applications/sample/wifi-iot/app/iothardware/led_example.c: https://gitee.com/openharmony/applications_sample_wifi_iot/blob/master/app/iothardware/led_example.c


[3]

“Condemned” : https://harmonyos.51cto.com/posts/2030