ESP8266 with Typescript and esptool
Intro
This tutorial describes the minimals steps required to execute yours firsts typescript lines of code on the ESP8266 board. At the end of this post you will be able to execute a “blink” sketch just to test that your stack is up and running.
Typescript is a JavaScript that scales. It supports type annotation, can deduce types. It can compile upper versions of ECMAScript to lower versions like ES5.
ESP8266 is a low-cost Wi-Fi microchip with full TCP/IP stack and microcontroller capability.
Environment
The steps described in this post have been tested with (and refer to) the stack below, but should work (with minors modifications) in other environments as well:
- Ubuntu 18.04 [kernel 4.15.0-38-generic]
- Node 8.9.4
- Typescript 3.1.3
- Espruino/esptool 1.87
The boards used for this essay:
- Wemos D1 R1 mini
Requirements
- python 2.7+
- gulp-cli (npm i -g gulp-cli)
Esptool
Install
pip install esptool cd esptool
Connect the Esp Board.
Flash
Assuming your board is on /dev/ttyUSB0 and accept 115200 baud:
python esptool.py --port /dev/ttyUSB0 erase_flash python esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash --flash_freq 80m --flash_mode qio --flash_size 32m 0x0000 "boot_v1.4(b1).bin" 0x1000 espruino_esp8266_user1.bin 0x37E000 blank.bin
Test
screen /dev/ttyUSB0 115200
and then:
process.memory()
should result in something like:
={ "free": 1654, "usage": 46, "total": 1700, "history": 15 }
Blink Project
Clone
git clone https://github.com/PostTenebrasLab/espruino-ts-quickstart cd espruino-ts-quickstart
Console
On one terminal execute:
gulp espruino-console
Build & Flash
On another terminal:
gulp build gulp send-to-espruino-console
The board should, hopefully, blink.
Repeat
Modify the constant blinkInterval in the src/app.ts file.
gulp build gulp send-to-espruino-console