How to stop being afraid and love mbed [Part 1]

    We supply electronic components. To do our job well, it’s not enough just to be able to bring and sell electronic components - it’s still important to be able to demonstrate their advantages. That is why we not only write review articles, but also create guidelines for the use of various "pieces of iron" and develop small demonstration projects.

    I’ll tell you about the history of creating one of these demonstration projects - I will consistently describe the process of creating a prototype device equipped with a capacitive touch screen and designed to measure relative humidity and temperature.

    Of particular interest is the approach to writing firmware - the software is completely written in the mbed online IDE. That is, the program for the microcontroller was created on a single Google Chrome tab and works equally on debug boards from different manufacturers.

    Content of the publication cycle:

    The first part is under the cut.

    So, the device consists of three main components:

    • HYT-271 Digital Relative Humidity Sensor from IST
    • Riverdi TFT display with integrated FTD01 graphic controller from FTDI
    • debug board with ARM Cortex microcontroller and mbed support

    The main characters of the play are the Riverdi display and the IST sensor, since the project is designed to demonstrate their capabilities. But as a control unit, any debug board can be used on which the necessary interfaces are implemented and displayed - SPI for a TFT display and I2C for a sensor. In my case, when I really want to play with mbed, its support in the mbed IDE is added to the requirements for the microcontroller platform.

    Silicon Labs SLSTK3400A board with an EFM32 Gecko series controller on board was chosen as the base platform. In the first photo she is in the center. However, my goal is to create such a program in mbed that would work on other mbed debug boards. Therefore, at each stage of development, different debugs from SiLabs, Atmel, and Wiznet will be included as a control module.

    Now consider the components in more detail.

    Digital relative humidity sensor HYT-271 from IST

    Sensors of the HYT series have already been covered in an article on Habré ; today I will give a less detailed description.

    HYT-271 is a digital relative humidity sensor with I2C interface, which is produced by the Swiss company IST. Like most modern sensors of relative humidity, it has a capacitive sensitive element and is equipped with an additional temperature sensor. The latter is primarily necessary for the automatic thermal compensation of humidity measurement results, however, it is also an independent sensitive element from which data on the ambient temperature can be obtained.
     Relative humidityTemperature 
    Measuring rangefrom 0 to 100% RH -40 to +125 ° C
    Accuracy (maximum accuracy)± 1.8% RH (in the range 0 ... 80% RH)± 0.2 ° C (in the range 0 ... 60 ° C) 
    Response timeHYT 271 <4 secHYT 271 <5 sec
    Repeatability ± 0.2% RH± 0.1 ° C
    Hysteresis <± 1% RH 
    Long-term drift of characteristics<± 0.5% RH / year<± 0.05 ° C / year
    Supply voltage2.7 - 5.5 V

    The key advantages of the HYT-271 sensor are its high accuracy in measuring moisture and its very fast response. Such characteristics are in demand in the control of such technological processes as drying, evaporation and distillation - this is the widest class of tasks from the manufacture of pasta to the control of hardening of concrete structures.

    High-quality sensors are also needed in devices for measuring residual moisture, or, for example, in climate control rooms where moisture-sensitive materials such as wood or grain are stored. Among the target applications are also incubators, medical equipment and other critical tasks , among which there is no home weather station !!!

    The price of sensors of this class in the Russian Federation is from 40 to 100 dollars. We offer HYT-271 individually from stock for 37 euros, and for bulk purchases, the price, of course, is reduced. For example, when ordering 50 sensors, the price will be about 30 euros per sensor. Well, there are discounts, please contact .

    Integrated sensors with a digital interface are factory calibrated, so for operation it is usually enough to connect the sensor to the control controller (in our case, via the I2C interface) and master the data exchange protocol. The data exchange protocol describes the format of control commands and data packets. We will turn to the software implementation of the HYT-271 sensor interrogation procedure in one of the following articles.

    HYT Series Sensor Documentation

    Riverdi TFT Touchscreen and FT801 Graphics Controller

    Riverdi is a Polish manufacturer of TFT modules, i.e. TFT displays with integrated graphics controllers.

    Displays differ in size, matrix parameters, the presence of a capacitive or resistive touch screen and additional options like a mounting frame. Most modern Riverdi displays are equipped with FTDI graphics controllers - FT80x and FT81x chips, which execute commands for rendering graphic primitives and process data from the touch input and audio channels. In other words, FTDI microcircuits play the role of a graphic coprocessor, onto which all complex resource-intensive tasks are transferred from the main microcontroller. The program, which “spins” on the control microcontroller, uses libraries from FTDI and with their help generates simple commands for controlling the graphic module. For communication between the central controller and the FT80x / FT81x, a serial I2C or SPI interface is used.

    The procedure for controlling the graphic controller and the features of FTDI development software will also be discussed in the following articles.

    An assortment of TFT modules can be found on the manufacturer’s website and on our website. Special prices are available

    for 2.83 ", 5" and 7 "displays . For the demonstration project, the uxTouch series RVT43ULFNWC00 TFT module is used. It has a diagonal of 4.3 '', a capacitive touch screen and an integrated FT801 graphic controller.

    UxTouch displays are the prettiest Riverdi modules available. They are made in a decorative frame, covered with protective glass and do not have external mounting mounts and holes. An adhesive surface is provided for mounting the display in the housing, which is located on the rear side of the decorative frame around the entire perimeter of the display. It all looks really cool - when you twist the module in your hands, your hands and eyes used to the ipad don't feel any catch.

    Debug board and mbed

    To interrogate the sensor and display data on the TFT display, in the presence of the FT801 chip, the high-performance microcontroller is not required. Most often, even an 8-bit chip is enough, this is actually the trick of using a graphics controller from FTDI.

    However, for the sake of my desire to get acquainted with mbed, I still use the ARM Cortex-M platform - I take the SLSTK3400A as the main work board, and Atmel and WIZwiki-W7500P from Wiznet as alternatives to the ATSAMD21-XPRO. In addition to the necessary I2C and SPI interfaces, the target controllers have a fairly decent amount of memory - at least 64 KB Flash. This bonus will allow you to implement not only a beautiful display of information received from the sensor, but also, for example, image storage.

    On debug boards, we don’t need most of the available peripherals. SiLabs energy measurement circuits, Wiznet hardware Ethernet, as well as endless controllers, touch and mechanical buttons, LEDs and LCDs - everything goes in the woods. We pay attention only to the presence of a built-in USB debugger and the outputs of the necessary digital signals.

    Now about mbed.

    Mbed is a software platform for developing IoT devices based on microcontrollers with an ARM Cortex-M core. The platform is being developed by ARM itself and microcontroller manufacturers. I will not touch on many of the tools included in mbed (cloud services, encryption tools, mbed OS, etc.). Only online IDEs, the "base" mbed library, and drivers for pairing the debug board with other devices will be considered.

    The mbed libraries provide an abstraction layer at which a program is written not for a specific STM32 / Atmel / NXP controller, but immediately for any platform supported by mbed. Platform support means that mbed calls correctly refer to the entire HAL of the target microcontroller, that mbed understands the topology of the debug board, and that the debug board is recognized on the PC as an external drive and is flashed by simply copying the binary file to this disk.

    Detailed instructions on how to register on, compile and run the demo program have already been written. Here , for example, is a guide on blinking the LED of my authorship.

    Therefore, we immediately proceed to the preparation of the future project - a simple program for outputting the counter of seconds to the serial port.

    #include "mbed.h"
    Serial              pc(USBTX, USBRX);
    Ticker              timeKeeping;
    volatile uint64_t     seconds = 0;
    void secondsCallback(void) {
        pc.printf("Number of seconds: %x\r\n", seconds);
        seconds ++;
    int main() {
        timeKeeping.attach(&secondsCallback, 1.0f);
        while(1) {}

    We create a project consisting of the main.cpp file and the mbed library package, compile the program, get the automatically downloaded binary file and copy it to the SLSTK3400A board, which is detected by the computer as an external drive.

    Now, by launching Terminal, we get the desired data from the controller.

    In order to generate firmware for the boards from Atmel and Wiznet, it is enough to change the target platform.After

    that, compile the project again and copy the resulting file to the appropriate disk - XPLAINED or MBED (yes, the Koreans distinguished themselves in inventing names).

    On the poppy, the program immediately started working on all three boards, and on Windows it was necessary to install the mbed-o COM port driver. Without it, only the SiLabs board wanted to communicate on the serial interface. However, this is a regular situation, well described by ARM itself.

    Here it’s time to notice one of the main disadvantages of mbed: printf is, in fact, the only debugging tool available. In addition to debugging with breakpoints and access to microcontroller registers, mbed has other obvious limitations. For example, universal peripheral drivers, by definition, cannot support all the peripheral features of each controller, that is, mbed may not have libraries for unusual modules or support for some non-standard operating modes of the peripheral devices of your microcontroller. And these may be precisely those modes and modules, because of which you have chosen your cristall.

    Also, of course, mbed is not the best tool for creating complex applications related to task scheduling and multithreading (although I am not aware of what the new mbed OS 5 can do). Well and in the end, the list of supported hardware platforms is far from complete.

    To love mbed, you need to have a good understanding of the range of tasks for which it is intended (thanks, captain). In my opinion, the mbed platform is best suited:

    a) for prototyping and rapid development of new components,
    b) for acquaintance with microcontroller programming.

    The key features of mbed are the versatility, accessibility and ease of use of software libraries, as well as the ability to export software written in mbed to “adult” IDEs.

    When prototyping, the scenario becomes possible: "quickly launched a working solution out of the box -> exported the program to the familiar IDE and brought it to mind", and for mastering the programming of microcontrollers, the transition from flashing the LED on the arduino to more serious things is simplified.

    Another advantage of mbed is integration into the compiler of the version control system, as well as the very idea of ​​a simple exchange of software modules. Embedded developers are believed to be reluctant to use version control systems. Mbed is a great excuse to finally feel the benefits of using version control if your hands haven’t reached before. As for the publication of our own developments and the use of foreign libraries and projects, taking into account the iron independence of mbed-programs, the idea of ​​opensource for embedded looks much more attractive than usual.

    Returning to my project, I’ll say right away that the final program, originally written for the SiLabs microcontroller, works absolutely correctly on Atmel and Wiznet boards. In theory, everything should work out on other available microcontroller platforms, a full list of which is available on .

    It also makes sense to check out the list of supported components . A library and an example of its use are available for all of the above displays, servos, sensors, wireless controllers and other modules. For my Riverdi TFT-module (more precisely for FT800 series controllers) such a library has already been created by one of the users, but the driver for the HYT sensor was written during the development of this project.

    The application development process will be described in succession in the following articles, and I can show the video with the working assembly now.


    In conclusion, I traditionally thank the reader for his attention and remind you that questions about the use of the products that we write about on the Habré can also be sent to the email address specified in my profile.

    Also popular now: