In Espruino, Modules are pieces of pre-written code (libraries) that perform common tasks, such as interfacing to different bits of hardware.
They can currently be used in a few different ways:
Working with Modules
Espruino Web IDE
If you're using the Espruino Web IDE, simply write
require("modulename") on the right-hand side - as you would have seen in the reference pages. When you click the Send to Espruino button, the Web IDE will automatically look online for minified versions of the modules you need, download them, and load them onto the board. You don't need an SD card or an internet connection to the Espruino board itself.
Load Module - the default mechanism
If you are using the Web IDE as is, the modules will be loaded from http://www.espruino.com/modules/. This URL can be changed in Web IDE settings.
To save space, most modules are provided as a minified version and the Web IDE tries to load minified versions first with default configuration.
For example, using
require("ADNS5050"); will make the Web IDE loading the minified module from http://www.espruino.com/modules/ADNS5050.min.js.
Load Module from Github
For now, as you can type a URL into require, you can actually just pull a module right off GitHub. For instance you could look at the history of something on GitHub, and could then just require a specific version of that file with:
The URL comes from clicking
<> by the commit you were interested in.
Load Module from NPM
If you activate this option in Web IDE, you can load modules from the NPM repository. Right now it:
- only loads the latest version there.
- only works if the module contains a single file.
- can cause some confusion with Espruino's modules, for instance clock.
For example using
require("async"); will make the Web IDE loading the tar.gz file (with automatic extraction) of the module from http://registry.npmjs.org/async.
Load Module from local folder
If you are using a local project folder, the Web IDE will automatically create an empty modules folder inside. Put a module there and you can load it with
With default Web IDE configuration, it will look for modules following this order:
- local minified
- online minified
- local normal
- online normal
If your own module has the same name as one of the existing ones, the Web IDE will use the minified version from online first.
If you need it anyway, you can provide a local minified version or you can change the Web IDE configuration from
.js|.min.js or even
myCustomModule.js|.min.js|.js to get it working.
If you have an Espruino with an SD card (but you're not using the Web IDE), you can copy the modules you need into a directory called 'node_modules' on the SD card. Now, whenever you write
require("modulename") the module will be used.
We're working on this - but soon: If you have a WiFi-enabled Espruino and it is connected to the internet, writing
require("mymodule") will cause it to look on the internet for the module with the name you have given.
- 433.92Mhz Transmitter and Receiver
- ADNS5050 Optical Mouse Sensor
- ADS1x15 programmable gain ADC
- ADS7843 Touchscreen
- ADXL335 Accelerometer
- ADXL345 Accelerometer
- AT Command Handler
- Analog RGB LED Control
- Arduino Pico adaptor board
- BH1750 I2C Light Sensor
- BMP Loader Module
- BMP085/BMP180 digital pressure sensor
- CAP1188 capacitive touch breakout
- CMUcam5 Pixy
- Charlieplexed LED Module
- Clock Module
- DHT11 Temperature and RH Sensor
- DHT22/AM230x/RHT0x Temperature and RH Sensor
- DS18B20 Temperature Sensor
- DS3231 RTC
- Date Module
- Digole LCD driver (monochrome)
- EEPROM on Flash
- EasyVR Voice Recognition Board
- Espruino Parallel to Serial Shifting-In with a CD4021BE
- Espruino module for BME280
- HC-SR04 Ultrasonic Distance Sensor
- HD44780 Character LCD
- HMAC Module
- HMC5883 Compass/Magnetometer
- HP03S pressure sensor module
- HTS221 pressure sensor
- HTU21D Temperature and RH Sensor
- HopeRF RFM69 Wireless Module
- I2C EEPROMs (like AT24C256)
- ILI9163 LCD controller
- ILI9341 LCD controller
- KeyPad Matrix
- LPD-6416 LED Matrix Display
- LPRS easyRadio (eRIC) Radio Modules
- LPS25HB pressure sensor
- MAG3110 3-axis magnetometer
- MAX31855 Thermocouple Controller
- MAX7219 7 segment display driver
- MCP23xxx I2C and SPI port expanders
- MCP4xxx I2C and SPI digital potentiometers
- MCP4xxx0 SPI digital potentiometers
- MCP9808 precision I2C temperature sensor
- MFRC522 NFC/RFID module
- MLX90614 Infra Red thermometer
- MMC212xMG Dual-axis Magnetic Sensor from MEMSIC used in HDMM01 breakout from Pollin
- MPL115A2, I2C digital barometer and temperature sensor
- MPL3115A2 Digital Altitude / Pressure / Temperature Sensor
- MPU6050 accelerometer and gyro
- MQ135 Air Quality Sensor
- MQTT Client
- MySensors Client/Gateway
- NRF24L01+ Wireless Module
- NeuroSky ThinkGear ASIC module
- OneWire EEPROMs (like DS24B33)
- PCD8544 LCD driver (Nokia 5110)
- PN532 NFC/RFID module
- Puck.js and BLE Printers
- Puck.js and BLE UARTs
- Puck.js and Eddystone Beacons
- Puck.js and HID Keyboards
- Puck.js and HTTP Proxies
- RN2483 LoRa Modules
- Rotary Encoder
- SH1106 OLED driver
- SPI EEPROMs (like AT25256)
- SSD1306 OLED driver
- SSD1351 OLED display driver
- SSD1606 e-Paper display driver
- ST7565/ST7567 128x64 Monochrome LCD driver
- STM32F1 Flash Memory Module
- SX1276/77/78/79 LoRa Modules
- Sensirion SHT10 SHT11 & SHT15 Temperature and Relative Humidity Sensor Module
- Servo Motors
- Sharp Memory LCD
- SmartNixie Nixie Tube driver
- TCS3200 driver
- TCS3472x I2C Color Sensor
- TSL2561 Luminosity sensor
- Thermistor Temperature Sensor
- VT100 Terminal Emulator
- WIZnet WIZ550io/W5500 Ethernet module
- Wii Nunchuck
- Writing and Submitting Modules (or changes)
- nRF905 Wireless Transceiver
- xBee radio module
Espruino also contains many built-in modules and classes that provide a lot of functionality:
- Analog IO
- Analog to Digital Converter
- CC3000 WiFi Module
- Digital to Analog Converter
- ESP8266 WiFi Module
- Graphics Library
- Inline Assembler
- Internet (HTTP)
- Pulse Width Modulation
- Serial Peripheral Interface (SPI)
- Servo Motors
- USART / UART / Serial Port
- WIZnet WIZ550io/W5500 Ethernet module
- WS2811/WS2812 LED String/Strip
You don't need a module to be able to interface to hardware - sometimes it just makes it easier. If you want to interface to a device that isn't listed here, please check out the Tutorials page, or Search for it.
Frequently Asked Questions
Why don't modules work when typing
require on the left-hand side of the Web IDE (or from a terminal window)?
When you type
require("modulename") on the right-hand side and click Send to Espruino, the Espruino Web IDE scans your code for
require statements and loads the relevant modules off the internet. Because the left-hand side of the Web IDE (or a terminal window) sends each character direct to Espruino, by the time you have pressed enter to execute your command, it's then too late to load the module.
Instead, Espruino defaults to what is mentioned under the Stand-alone Espruino heading above - it looks on an SD card (if inserted) for the module. This is why you might get a
ERROR: Unable to read file : NOT_READY error written to the console.
If I load modules from an SD card, will the SD card always need to be inserted?
No. As long as you have used
require('module') at least once for each module before you type
save(), all the information that is needed will be cached inside Espruino.
Can I dynamically load (and unload) modules?
Yes. By default each module that is loaded will be cached (to avoid loading modules twice). However you can call
Modules.removeCached('modulename') which will remove the module from the cache and free the memory that it uses.
How do I make my own modules?
It's easy! See the Writing Modules page...