Categories: Microcontroller circuits
Number of views: 6809
Comments on the article: 0

Programmable microcontrollers in JavaScript: which one to choose, features and capabilities

 

In our country, after about 2010, the hobby of radio enthusiasts received a second wind with the advent of the ability to program microcontrollers in high-level programming languages, far removed from iron. The first mass project was Arduino Board Family. We have repeatedly examined these microcontrollers in articles, but today we will talk about microcontrollers that are programmed in javascript. Yes! The very same language that was used mainly when writing WEB-pages.

Microcontroller programmable in javascript

Scope or are such microcontrollers needed at all?

If we consider from the point of view of electronics in those devices that we will consider below, standard microcontrollers are used. The difference from the products from the manufacturer is only that they have a preinstalled loader program, although call it what you want, which allows you to execute the program code downloaded to you, and in some cases, communicate with the computer via USB, if it is not implemented in hardware.

What are microcontrollers for javascript for and other non-traditional languages ​​for? There are debates among amateurs and professionals in the development of electronics in specialized forums, where some praise projects like "Arduino", while others humiliate and ridicule them in every possible way for the simplicity and abstractness of the developer from most issues with iron.

Important: In this part of the article we say: “Arduino”, because it has become the starting point for most lovers of electronic devices.

Arduins can be programmed in C. But is this necessary? Let's look at why in most cases the reaction speed of microcontrollers is not needed. Arduino workers often like to assemble controllers for automatic irrigation and the inclusion of lighting for the "illumination" of plants. Such a combined device will be an excellent help for those who like to grow something in apartments or greenhouses.

But what speed of control device is needed here? 15-20 years ago no one would use it here microcontroller - an amateur designer would have successfully managed a pair of operational amplifiers or logic elements. But if we talk about the suitability of the discussed microcontrollers for these projects, then here it is completely indifferent after how many milliseconds the backlight turns on or the earth begins to irrigate the water.

Automatic watering system

The next popular project is the home weather station, and it turns out that for such purposes the basic capabilities of arduins are enough to read information from sensors and display them on a character-synthesizing display.

In management examples RGB LED strip regular or smart LEDs with "pixel-by-pixel" control (an example of such a SMART tape and its marking you see in the figure below) also has enough resources.

SMART tape

But where do you need speed and are not suitable for using simplified programming languages ​​like Scratch or javascript? Everything is very simple:

  • In precision circuits;

  • In alarms and security systems;

  • In high-precision measuring instruments with the need to quickly take data from the ADC, including for normal oscilloscopes;

  • In devices with a requirement for long-term autonomous work in sleep mode;

  • In cases where you need to “shove” as many functions and code as possible into the microcontroller, but this has not become a very urgent task recently in connection with the reduction in the cost of most devices on the market.

In most of these tasks, the stumbling block is speed and memory.For optimal results, in this case it is more reasonable to use not even C / C ++, but Assembler (ASM). Indeed, if you are aiming at such projects, it means that you have a certain amount of knowledge, which means there is no need.


Conclusion?

Microcontrollers with simple languages ​​are needed where there are no strict requirements such as speed or measurement accuracy, but even in some situations they will provide accuracy for non-specialized devices intended for amateur use.



Espruino - a powerful microcontroller and a simple javascript language

The Espruino platform is a set of software and hardware for programming microcontrollers in the javascript language, it includes three elements:

1. Firmware for a microcontroller with a JS language interpreter.

2. Development environment for the Espruino Web IDE.

3. A board with a microcontroller with the firmware itself for working directly with Espruino.

Espruino

The idea was developed and implemented by Gordon Williams in 2013, and he raised funds for it using the crowdfunding platform (Kickstarter). In fact, the essence of the development was to develop the Espruino firmware (engine) for loading it into microcontrollers. It is mainly used on microcontrollers of the STM32 family, with ARM-cortex architecture. More convenient devices for operation, we will consider below.

Espruino microcontroller

To write programs for the microcontroller in javascript, you need to install the Espruino Web IDE. This is a program or extension for the popular Google Chrome Internet browser that installs in just one click.

After clicking on the "Install" button in the "services" menu, an application will appear, and you can get into this menu by typing in the address bar: chrome: // apps /

When you click on the icon with a cup of coffee, the development environment opens, which is notable not in the browser, but in a separate window.

This environment is interesting for both children and beginner users, because you can enter the code manually or use the graphical editor, based on the Scratch programming language. To do this, click on the icon that the arrow points to.

Espruino Web IDE

After that, the right side of the screen, which with the code, will change to its other representation:

Graphics editor

The interface is intuitive, in the central panel from top to bottom: open a new file, save the sketch, load it into the microcontroller.


Conclusion

Espruino boards and the like are a printed circuit board with the necessary attachments and a microcontroller, with a javascript interpreter, which processes the code and translates its commands into the language of ones and zeros directly at runtime. While in the classic form, the program for microcontrollers is loaded into the latter already in the form of machine code.

This approach gives performance in many tasks, like Arduino.


Review of the official Espruino line

Original Espruino

Specifications of this device:

  • 54x41 mm (half a credit card);

  • STM32F103RCT6 32-bit 72MHz ARM Cortex M3 CPU

  • 256KB Flash, 48KB of RAM;

  • Micro USB port

  • Input voltage range from 3.6 to 15V;

  • Battery connector (JST PHR-2 2 Pin);

  • Built-in SD card slot;

  • Three LEDs (red green and blue);

  • Platforms for installing the HC-05 Bluetooth module;

  • The distance between the mines - 0.1 "(2.54 mm);

  • 44 GPIO pins, of which 26 PWM (PWM), 16 ADC (ADC), 3 USARTs, 2 SPI, 2 I2C and 2 DACs (DAC);

  • The area on the board can be used to connect a number of devices, such as Wi-Fi modules, servos, expandable to 14 outputs with a current of up to 500 mA.

Espruino microcontroller board

The appearance of the board and the conditional division of its nodes into zones

To many, the board may seem unattractive and incomplete, but this was only its first option, then they look more familiar and progressive. Puck.JS is a miniature board in the case, it has on board Bluetooth and an infrared transmitter.

Puck.js

According to information from the official site, its technical specifications and features are as follows:

  • Bluetooth Low Energy;

  • Pre-installed Espruino javascript interpreter;

  • The heart of the board is nRF52832 SoC - 64MHz ARM Cortex M4, 64kB RAM, 512kB Flash;

  • 8 x 0.1 "GPIO ports (including PWM (PWM), SPI, I2C, UART, analog input);

  • 9 x SMD GPIO ports (including PWM, SPI, I2C, UART);

  • Housing washer made of ABS plastic;

  • Silicone cover with a key;

  • MAG3110 Magnetometer - three-axis magnetic field meter;

  • IR transmitter

  • Thermometer, light sensor and battery level;

  • Three LEDs (red, green and blue);

  • Programmable via JS NFC tag.

  • Pins can perceive touch by capacity (the principle of operation of touch screens of smartphones);

  • Weight 14 g;

  • Sizes of the plastic case: diameter 36mm, thickness - 12.5mm;

  • Board dimensions: diameter 29mm, thickness 9mm.

Demonstration of work:

The next board is Espruino Wi-Fi, as the name implies, its feature is a built-in wireless module for Wi-Fi.

Espruino Wi-Fi

Its technical characteristics:

  • Board dimensions: 30x23 mm;

  • The board has a Micro USB connector;

  • 21 GPIO: 8 analog inputs, 20 PWM, 1 Serial port, 3 SPI, 3 I2C;

  • The board has 3 LEDs, 2 of them are user-programmable, and 1 displays Wi-Fi activity;

  • The ports are compatible with Arduino in terms of voltage and support a 5 Volt signal;

  • 1 button;

  • Built on a microcontroller STM32F411CEU6 32-bit 100MHz ARM Cortex M4 CPU;

  • Memory: 512kb flash, 128kb RAM;

  • Wi-Fi communication with ESP8266 (802.11 b / g / n);

  • RTC (real time clock with an external generator).

  • A 3.3V stabilizer with a current of up to 250 mA is installed on the board, a supply voltage of 3.5 to 5 V is supported.

  • The current consumption in sleep mode is up to 0.05 mA, which allows you to work 2.5 years from a 2500mAh battery (although this is more of a marketing, but the battery itself is more likely to discharge faster).

Espruino Wi-Fi

Board demonstration:


Espruino Pico - microcontroller for javascript in USB stick format

We will consider it in a separate section, since it is most common in Russia and the near abroad, perhaps many thanks to the Amperka company. The board is convenient for training and implementing finished projects, a miniature board that is inserted directly into the USB port of your computer for programming.

Espruino Pico

Specifications:

  • Dimensions: 33x15 - taking into account the USB plug;

  • 22 GPIO ports, including: 9 analog inputs, 21 PWM, 2 Serial (serial ports), 3 SPI, 3 I2C;

  • GPIO pins support 5 V signal levels, which allows you to combine the board with shields and devices for arduino;

  • The USB Type A plug is part of the board.

  • Two LEDs and one programmable button

  • Built on a STM32F401CDU6 32-bit 84MHz ARM Cortex M4 CPU microcontroller

  • Memory: 384kb flash, 96kb RAM

  • A voltage regulator of 3.3 V 250mA is soldered on the board and allows it to be powered from 3.5 to 16 V.

  • In sleep mode, it consumes current up to 0.05 mA, and the manufacturer here claims 2.5 years of operation from 1 battery at 2500mAh;

  • Built-in field effect transistor for controlling high-current circuits.

This is the smallest board in the line. Along its edges are I / O ports. In this case, the metallization layer is present both on the holes themselves and along the end of the printed circuit board.

Espruino Pico

The contact pitch is standard, this allows you to solder standard PLS lines to it (this is the name they carry).

Pls line

Detailed review of this board:


Amperka online store and its line of boards with Javascript

Like it or not, but the largest popularizer of non-traditional programming of microcontrollers, in particular in javascript is the Amperka site. They have a channel on YouTube where they teach how to use and program their products, and also show the implementation of projects using their own line of boards from microcontrollers.

The branded line of the domestic manufacturer is ISKRA JS, the name of which reads the name of the language being discussed. Its technical characteristics:

  • Microcontroller: STM32F405RG (32-bit ARM Cortex M4);

  • Clock frequency: 168 MHz;

  • Flash memory: 1024 kB;

  • SRAM: 192 kB;

  • Rated Operational Voltage: 3.3V;

  • Recommended input voltage: 7–15 V or 3.6–12 V;

  • Maximum current from the 5V bus: 1000 mA;

  • Maximum current from the 3.3V bus: 300 mA (including microcontroller power supply);

  • Maximum current from pin or pin: 25 mA;

  • Maximum total current from pins or pins: 240 mA;

  • General Purpose I / O Ports: 26;

  • Ports with PWM support: 22;

  • ADC Ports: 12 (12 bit);

  • Ports with DAC: 2 (12 bit);

  • Available hardware interfaces: 4 × UART / Serial, 3 × I²C / TWI, 2 × SPI;

  • Dimensions: 69 × 53 mm.

ISKRA JS

Structurally, the board is very close to the Arduino Uno R3 - this means that you can use the expansion cards for it.What interesting things do we see in the technical specifications? Let's compare them with all your favorite arduino.

Comparison of Iskra JS and Arduino UNO r3

They are different in terms of memory and capabilities, and each will find its application. Although arduino in most cases is preferable, because it can be bought for a couple of hundred rubles, but a spark is not.

Amperka also sells microcontrollers and microcomputers like Raspberry Pi, as well as training kits for working with them. There is also a line of expansion cards for microcontrollers, these are the so-called Troyka modules. They are made in the same white color as the rest of the products of this company.

Like any other shields, products from Amperka contain printed circuit boards as the main functional unit - a sensor, a switching device, a master or actuator and the necessary attachments to it. We have already done a rough review of typical modules for Arduino - The most popular shields for Arduino, here everything is by analogy. On the website or in the Amperka community, you can find libraries for use with modules with Iskra JS or Arduino.

Among the three modules there are:

  • Joystick;

  • Encoder

  • Module with relay;

  • Port expansion cards (Troyka-shield);

  • Accelerometers, and other position sensors;

  • Sensors of light, proximity, current, temperature, Hall, noise, gas, alcohol and other things;

  • Receivers for reading NFC tags;

  • Equipment for engine management (H-bridges, drivers) and more.

On sale there is an interesting kit for beginners "IODO".

A separate word about a single item in the configuration is # the constructor. These are parts for assembling cases and bearing parts of your structures, they are connected like a child’s designer and allow you to make a normally stable layout with the possibility of safe carrying, as well as a turnkey solution for everyday use.

Constructor

By the way, you can put together your training kit, and the training booklet from the kit is available on the official website in electronic form and freely available.


Conclusion

To program microcontrollers in javascript, you just need to install the appropriate shell on your sample. However, not every copy has a corresponding firmware, nevertheless for popular devices can be found on thematic forums. For example, on the BBC Micro: bit microcomputer, the process of working with the environment is depicted in the following video, and the installation is performed in just a few steps.

Is javascript needed on microcontrollers? Absolutely yes! For most amateur tasks, do-it-yourselfers do not need accuracy or speed of response, and for a number of professional tasks, the capabilities of such platforms are enough. Such an approach to programming makes it possible to start developing devices with virtually no study of the structure and commands of the microcontroller. But in the classical method of programming, it was necessary to take into account a number of things, such as various types of variables, memory addresses, and so on.

See also at i.electricianexp.com:

  • PIC microcontrollers for beginners
  • Types and arrangement of AVR microcontrollers
  • Which Arduino board to choose
  • What are Nextion displays and how to work with them?
  • Connecting and programming Arduino for beginners

  •