Top Related Projects
Ultra-lightweight JavaScript engine for the Internet of Things.
MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
Mongoose OS - an IoT Firmware Development Framework. Supported microcontrollers: ESP32, ESP8266, CC3220, CC3200, STM32F4, STM32L4, STM32F7. Amazon AWS IoT, Microsoft Azure, Google IoT Core integrated. Code in C or JavaScript.
Lua based interactive firmware for ESP8266, ESP8285 and ESP32
Quick Overview
Espruino is an open-source JavaScript interpreter for microcontrollers. It allows users to program and control hardware devices using JavaScript, making it easier for web developers to transition into embedded systems development. Espruino provides a rich set of APIs for interacting with various hardware components and peripherals.
Pros
- Easy to use for developers familiar with JavaScript
- Supports a wide range of microcontrollers and boards
- Real-time execution and interactive development environment
- Large community and extensive documentation
Cons
- Performance limitations compared to native C/C++ code
- Higher power consumption due to interpreted nature
- Limited support for complex JavaScript features and libraries
- May not be suitable for resource-constrained devices
Code Examples
- Blinking an LED:
var led = LED1;
setInterval(function() {
led.toggle();
}, 500);
This code toggles an LED on and off every 500 milliseconds.
- Reading an analog sensor:
var sensor = analogRead(A0);
console.log("Sensor value: " + sensor);
This code reads the value from an analog sensor connected to pin A0 and logs it to the console.
- Connecting to Wi-Fi:
var wifi = require("Wifi");
wifi.connect("SSID", {password: "PASSWORD"}, function(err) {
if (err) {
console.log("Connection error: " + err);
return;
}
console.log("Connected to Wi-Fi");
});
This code connects to a Wi-Fi network using the provided SSID and password.
Getting Started
- Install the Espruino Web IDE or command-line tools.
- Connect your Espruino board to your computer via USB.
- Open the Web IDE or use the command-line tools to connect to the board.
- Write your JavaScript code in the editor.
- Click the "Upload" button or use the appropriate command to send the code to the board.
- Your code will start running on the Espruino board immediately.
For more detailed instructions and examples, visit the official Espruino documentation at https://www.espruino.com/Quick+Start.
Competitor Comparisons
Ultra-lightweight JavaScript engine for the Internet of Things.
Pros of JerryScript
- Lightweight and optimized for resource-constrained devices
- Supports a wider range of platforms and architectures
- More active development and community support
Cons of JerryScript
- Less beginner-friendly, with a steeper learning curve
- Fewer built-in features and libraries compared to Espruino
- Requires more manual configuration and setup
Code Comparison
Espruino:
var led = LED1;
setInterval(function() {
led.toggle();
}, 500);
JerryScript:
#include "jerryscript.h"
jerry_value_t led_toggle_function;
// Additional C code required for setup and execution
JerryScript requires more low-level C code to interface with hardware and execute JavaScript, while Espruino provides a more accessible JavaScript environment out of the box. JerryScript offers greater flexibility and performance optimization potential, but at the cost of increased complexity. Espruino is better suited for rapid prototyping and educational purposes, while JerryScript is more appropriate for production-ready embedded systems with specific performance requirements.
MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
Pros of MicroPython
- Wider hardware support and more extensive standard library
- Closer to standard Python syntax and functionality
- More active community and frequent updates
Cons of MicroPython
- Larger memory footprint and slower execution compared to Espruino
- Steeper learning curve for beginners in embedded programming
Code Comparison
MicroPython:
import machine
import time
led = machine.Pin(2, machine.Pin.OUT)
while True:
led.toggle()
time.sleep(1)
Espruino:
var led = new Pin(2);
led.mode("output");
setInterval(function() {
led.write(led.read() ^ 1);
}, 1000);
Both examples blink an LED, but MicroPython uses a more Python-like syntax with explicit imports and a while loop, while Espruino uses JavaScript-style syntax with callbacks and implicit globals. MicroPython's code is more verbose but potentially more familiar to Python developers, whereas Espruino's code is more concise and event-driven.
Mongoose OS - an IoT Firmware Development Framework. Supported microcontrollers: ESP32, ESP8266, CC3220, CC3200, STM32F4, STM32L4, STM32F7. Amazon AWS IoT, Microsoft Azure, Google IoT Core integrated. Code in C or JavaScript.
Pros of Mongoose OS
- More comprehensive IoT development platform with built-in cloud integrations
- Supports a wider range of microcontrollers and development boards
- Offers over-the-air (OTA) updates and device management features
Cons of Mongoose OS
- Steeper learning curve due to more complex architecture
- Larger footprint and potentially higher resource usage
- Less focus on interactive programming compared to Espruino
Code Comparison
Mongoose OS (C):
#include "mgos.h"
enum mgos_app_init_result mgos_app_init(void) {
mgos_gpio_set_mode(LED_PIN, MGOS_GPIO_MODE_OUTPUT);
mgos_set_timer(1000, MGOS_TIMER_REPEAT, blink_timer_cb, NULL);
return MGOS_APP_INIT_SUCCESS;
}
Espruino (JavaScript):
var on = false;
setInterval(function() {
on = !on;
LED1.write(on);
}, 1000);
Mongoose OS provides a more structured C-based approach with built-in system functions, while Espruino offers a simpler JavaScript environment for rapid prototyping and interactive development. Mongoose OS is better suited for complex IoT projects with cloud integration, while Espruino excels in quick, interactive programming for microcontrollers.
Lua based interactive firmware for ESP8266, ESP8285 and ESP32
Pros of NodeMCU Firmware
- Supports Lua scripting, which is easier for beginners to learn
- Larger community and more extensive documentation
- Built-in support for various IoT protocols like MQTT
Cons of NodeMCU Firmware
- Limited to ESP8266 and ESP32 platforms
- Higher memory footprint compared to Espruino
- Less efficient for low-power applications
Code Comparison
NodeMCU Firmware (Lua):
gpio.mode(4, gpio.OUTPUT)
tmr.create():alarm(1000, tmr.ALARM_AUTO, function()
gpio.write(4, gpio.read(4) == gpio.HIGH and gpio.LOW or gpio.HIGH)
end)
Espruino (JavaScript):
var pin = D4;
pinMode(pin, 'output');
setInterval(function() {
digitalPulse(pin, 1, 500);
}, 1000);
Both examples demonstrate blinking an LED, showcasing the syntax differences between Lua and JavaScript. NodeMCU uses the gpio module and a timer, while Espruino leverages JavaScript's setInterval function and the built-in digitalPulse method for more concise code.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Espruino JavaScript for Microcontrollers
_____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |_____|___| _|_| |___|_|_|_|___| |_|
About
Espruino is a JavaScript interpreter for microcontrollers. It is designed for devices with as little as 128kB Flash and 8kB RAM.
Please support Espruino by ordering one of our official boards or donating.
Documentation
If you have an Espruino board, please read the Quick Start Guide first.
Browse the Espruino Website (try using search in the top right), and read the FAQ.
There's also a Reference for JavaScript commands as well as Tutorials. However the documentation on the Espruino website will match the version available for download but not the latest version on GitHub.
Builds for the Espruino Board and Pico Board (built automatically for each Git commit) are available from here.
Other documentation of use is:
- The Forum
- FAQ
- Troubleshooting
- Performance Notes
- Implementation Notes
- Build Process Notes
- Building Espruino
- Making your own libraries
- Hardware Debugging Notes
Support / Bugs
First, please try and check that your problem hasn't already been found or covered on our forum.
Submit bugs with clear steps to reproduce them: a small test case (not your whole program), and an actual and expected result. If you can't come up with these, please post on the forum first as it may just be something in your code that we can help out with.
Work on Espruino is supported by sales of our boards.
If your board isn't made by us but came pre-installed with Espruino then you should contact the manufacturers.
We try and support users of the boards we sell, but if you bought a non-official board your issue may not get addressed. In this case, please consider donating to help cover the time it takes to fix problems (even so, we can't guarantee to fix every problem).
License
Please see the LICENSE file.
Building
Check out the page on building Espruino.
Testing
There are a bunch of tests in the tests
directory. See tests/README.md
for examples on how to run them.
Current State
The officially supported boards are the best supported. They come pre-installed with Espruino and you are able to easily download and flash the latest versions of Espruino to them.
While Espruino can run on other boards, we make no money from them and so cannot afford to test, fix or support the firmware on them. We're dependent on the community.
You can download binaries from https://www.espruino.com/Download.
If you are a board manufacturer interested in getting your board officially supported, please check out this page.
For a list of supported boards, please see the boards folder.
Main supported platforms are:
- STM32 (F1, F3, F4, L4)
- nRF52
- nRF51
- ESP8266
- ESP32
- Linux
Espruino has been ported to other boards and platforms (such as EFM32 and SAMD), but these have a habit of being contributed and then never maintained. All boards that this has happened to reside in the UNMAINTAINED_BOARDS branch.
Modification
Check out the documentation on the build process first - this should clear up a lot of potential questions about the Espruino architecture.
Please see CONTRIBUTING.md for some hints about code style/etc.
You can auto-build documentation for all source files - see doxygen/README.md
Any more questions? ask on the forum.
Porting to new devices
If you're using an existing architecture everything can be done from boards/BOARDNAME.py
. See a similar board's .py
file as an example.
However for a new architecture there are a bunch of different files to modify.
boards/*.py
files describe the CPU, available pins, and connections - so the relevant linker script, headers + docs can be createdboards/pins/*.csv
are copies of the 'pin definitions' table in the chip's datasheet. They are read in for STM32 chips by theboards/*.py
files, but they are not required - seeboards/MICROBIT.py
for an example.- Global build options are handled in
Makefile
- The
make
directory contains arch-specific Makefile fragments - Extra libraries like USB/LCD/filesystem are in
Makefile
- Processor-specific code in
targets/ARCH
- eg.targets/stm32
,targets/linux
- Processor-specific libs (like the SDK) in
targetlibs/ARCH
src/jshardware.h
is effectively a simple abstraction layer for SPI/I2C/etc, which should be implemented intargets/ARCH/jshardware.c
Adding libraries
- Create
jswrap_mylib.c/h
inlibs/
- Create library functions (see examples in other jswrap files, also the comments in
scripts/common.py
)
See libs/README.md for a short tutorial on how to add your own libraries.
Using Espruino in your Projects
If you're using Espruino for your own personal projects - go ahead, we hope you have fun - and please let us know what you do with it on https://www.espruino.com/Forum!
If you're planning on selling the Espruino software on your own board, please:
- Let us know, we might be able to help.
- Read the terms of the MPLv2 Licence that Espruino is distributed under, and make sure you comply with it
- MPLv2 dictates that any files that you modify must be made available in source form. New files that you create don't need to be made available (although we'd encourage it!)
- You won't be able to call your board an 'Espruino' board unless it's agreed with us (we own the trademark)
- You must explain clearly in your documentation that your device uses Espruino internally
- Please don't fork Espruino - improvements get very hard to share, and in the long run everyone loses.
- Please give something back to the project - be it code improvements, documentation or support.
We spend a lot of time supporting Espruino on the forums, but can only do so because we make money from the sales of Espruino boards. If your users request support from us then we have absolutely no obligation to help them. However, we'll be a lot more motivated if you're actively helping to improve Espruino for all its users (not just your own).
Top Related Projects
Ultra-lightweight JavaScript engine for the Internet of Things.
MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
Mongoose OS - an IoT Firmware Development Framework. Supported microcontrollers: ESP32, ESP8266, CC3220, CC3200, STM32F4, STM32L4, STM32F7. Amazon AWS IoT, Microsoft Azure, Google IoT Core integrated. Code in C or JavaScript.
Lua based interactive firmware for ESP8266, ESP8285 and ESP32
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot