Modules

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:

require("https://github.com/espruino/EspruinoDocs/blob/master/devices/PCD8544.js");

You can even look at the history of something on GitHub, and can then require a specific version of that file with:

require("https://github.com/espruino/EspruinoDocs/blob/d4996cb3179abe260c030ed02bcb0d2384db6bbd/devices/PCD8544.js");

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:

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 require("myCustomModule");.

With default Web IDE configuration, it will look for modules following this order:

  1. local minified
  2. online minified
  3. local normal
  4. 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 .min.js|.js to .js|.min.js or even myCustomModule.js|.min.js|.js to get it working.

Stand-alone Espruino

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.

Internet-enabled Espruino

Right now there isn't a way to make Espruino automatically load a module from the internet when required without the Web IDE. This may be added in the future, but the fact that require is synchronous while network connections are asynchronous makes this difficult to do reliably until yield is added into the interpreter.

Until then, the following asyncronous code will dynamically load a module from the internet on demand.

function loadModule(moduleName, callback) {
  require("http").get("http://www.espruino.com/modules/"+moduleName+".js", function(res) {
    var contents = "";
    res.on('data', function(data) { contents += data; });
    res.on('close', function() { 
      Modules.addCached(moduleName, contents); 
      if (callback) callback();
    });
  }).on('error', function(e) {
    console.log("ERROR", e);
  });
}

Existing Modules

433.92Mhz Transmitter and Receiver433.92Mhz Transmitter and ReceiverADNS5050 Optical Mouse SensorADNS5050 Optical Mouse SensorArduino Pico adaptor boardArduino Pico adaptor boardCC3000 WiFi ModuleCC3000 WiFi ModuleCMUcam5 PixyCMUcam5 PixyDCF77 DCF77 DS18B20 Temperature SensorDS18B20 Temperature SensorESP8266 WiFi ModuleESP8266 WiFi ModuleEspruino Parallel to Serial Shifting-In with a CD4021BEEspruino Parallel to Serial Shifting-In with a CD4021BEFontsFontsGPS ModuleGPS ModuleGraph LibraryGraph LibraryHC-SR04 Ultrasonic Distance SensorHC-SR04 Ultrasonic Distance SensorHD44780 Character LCDHD44780 Character LCDHP03S pressure sensor moduleHP03S pressure sensor moduleILI9163 LCD controllerILI9163 LCD controllerILI9341 LCD controllerILI9341 LCD controllerINA226 Current/Voltage Measurement ICINA226 Current/Voltage Measurement ICInfrared 'Pronto Hex' decoderInfrared 'Pronto Hex' decoderInfrared Remote Control Receiver ModuleInfrared Remote Control Receiver ModuleKeyPad MatrixKeyPad MatrixLPD-6416 LED Matrix DisplayLPD-6416 LED Matrix DisplayLPRS easyRadio (eRIC) Radio ModulesLPRS easyRadio (eRIC) Radio ModulesMAG3110 3-axis magnetometerMAG3110 3-axis magnetometerMAX6675 Thermocouple ControllerMAX6675 Thermocouple ControllerMAX7219 7 segment display driverMAX7219 7 segment display driverMLX90614 Infra Red thermometerMLX90614 Infra Red thermometerMQ135 Air Quality SensorMQ135 Air Quality SensorMS5803 Pressure SensorMS5803 Pressure SensorMidiMidiNRF24L01+ Wireless ModuleNRF24L01+ Wireless ModulePCD8544 LCD driver (Nokia 5110)PCD8544 LCD driver (Nokia 5110)PN532 NFC/RFID modulePN532 NFC/RFID modulePuck.js MIDIPuck.js MIDIPuck.js and BLE PrintersPuck.js and BLE PrintersPuck.js and BLE UARTsPuck.js and BLE UARTsPuck.js and Eddystone BeaconsPuck.js and Eddystone BeaconsPuck.js and HID KeyboardsPuck.js and HID KeyboardsPuck.js and HTTP ProxiesPuck.js and HTTP ProxiesPuck.js and iBeaconsPuck.js and iBeaconsQuectel M35 Quad-band GSM/GPRS module ModuleQuectel M35 Quad-band GSM/GPRS module ModuleRuuvitagRuuvitagSH1106 OLED driverSH1106 OLED driverSMS Send and ReceiveSMS Send and ReceiveSSD1306 OLED driverSSD1306 OLED driverSSD1351 OLED display driverSSD1351 OLED display driverSSD1606 e-Paper display driverSSD1606 e-Paper display driverSeeed Wio LTESeeed Wio LTESeeedStudio Grove SystemSeeedStudio Grove SystemServo MotorsServo MotorsSharp Memory LCDSharp Memory LCDVL53L0X VL53L0X VT100 Terminal EmulatorVT100 Terminal EmulatorWIZnet WIZ550io/W5500 Ethernet moduleWIZnet WIZ550io/W5500 Ethernet moduleWebSocketsWebSocketsWii NunchuckWii NunchuckWriting and Submitting Modules (or changes)Writing and Submitting Modules (or changes)nRF52 Low Level Interface LibrarynRF52 Low Level Interface LibraryADS1x15 programmable gain ADCADS1x15 programmable gain ADCADS7843 TouchscreenADS7843 TouchscreenADXL335 AccelerometerADXL335 AccelerometerADXL345 AccelerometerADXL345 AccelerometerAT Command HandlerAT Command HandlerAT24Cxxx I2C EEPROM and FRAM (incl. M24M02, MB85RCxx, FT24Cxxx, 24LCxxx, CAT24Cxxx, BR24Gxxx)AT24Cxxx I2C EEPROM and FRAM (incl. M24M02, MB85RCxx, FT24Cxxx, 24LCxxx, CAT24Cxxx, BR24Gxxx)AT25xxx SPI EEPROMs (incl. M95xxx, 25AAxxx, 25LCxxx, CAT25xxx, BR25Sxxx)AT25xxx SPI EEPROMs (incl. M95xxx, 25AAxxx, 25LCxxx, CAT25xxx, BR25Sxxx)Analog RGB LED Control Analog RGB LED Control BH1745 Digital Color SensorBH1745 Digital Color SensorBH1750 I2C Light SensorBH1750 I2C Light SensorBME280 Environment sensorBME280 Environment sensorBME680 Environment sensorBME680 Environment sensorBMP085/BMP180 digital pressure sensorBMP085/BMP180 digital pressure sensorBMP280 Environment sensorBMP280 Environment sensorBitmap file (BMP) Loader ModuleBitmap file (BMP) Loader ModuleCAP1188 capacitive touch breakoutCAP1188 capacitive touch breakoutCCS811 Digital Air Quality SensorCCS811 Digital Air Quality SensorCharlieplexed LED ModuleCharlieplexed LED ModuleClock ModuleClock ModuleDHT11 Temperature and RH SensorDHT11 Temperature and RH SensorDHT22/AM230x/RHT0x Temperature and RH SensorDHT22/AM230x/RHT0x Temperature and RH SensorDMXDMXDS2xxx OneWire EEPROMs (DS24B33, DS2431, DS28EC20 etc)DS2xxx OneWire EEPROMs (DS24B33, DS2431, DS28EC20 etc)DS3231 RTCDS3231 RTCDate ModuleDate ModuleDigole LCD driver (monochrome)Digole LCD driver (monochrome)EEPROM on FlashEEPROM on FlashEasyVR Voice Recognition BoardEasyVR Voice Recognition BoardEspruino InfluxDB moduleEspruino InfluxDB moduleEspruino WebServer ModuleEspruino WebServer ModuleGraphical MenuGraphical MenuHMAC ModuleHMAC ModuleHMC5883 Compass/MagnetometerHMC5883 Compass/MagnetometerHTS221 humidity and temperature sensorHTS221 humidity and temperature sensorHTU21D Temperature and RH SensorHTU21D Temperature and RH SensorHopeRF RFM69 Wireless ModuleHopeRF RFM69 Wireless ModuleInitialStateInitialStateLIS2DH12 AccelerometerLIS2DH12 AccelerometerLIS2MDL MagnetometerLIS2MDL MagnetometerLIS3DH AccelerometerLIS3DH AccelerometerLPS22HB pressure sensorLPS22HB pressure sensorLPS25HB pressure sensorLPS25HB pressure sensorLSM6DSL Accelerometer and 3D Gyroscope
LSM6DSL Accelerometer and 3D Gyroscope Local Date ExtensionsLocal Date ExtensionsLosantLosantMAX31855 Thermocouple ControllerMAX31855 Thermocouple ControllerMCP23xxx I2C and SPI port expandersMCP23xxx I2C and SPI port expandersMCP4xxx I2C and SPI digital potentiometersMCP4xxx I2C and SPI digital potentiometersMCP4xxx0 SPI digital potentiometersMCP4xxx0 SPI digital potentiometersMCP9808 precision I2C temperature sensorMCP9808 precision I2C temperature sensorMFRC522 NFC/RFID moduleMFRC522 NFC/RFID moduleMMC212xMG Dual-axis Magnetic Sensor from MEMSIC used in HDMM01 breakout from PollinMMC212xMG Dual-axis Magnetic Sensor from MEMSIC used in HDMM01 breakout from PollinMPL115A2, I2C digital barometer and temperature sensorMPL115A2, I2C digital barometer and temperature sensorMPL3115A2 Digital Altitude / Pressure / Temperature SensorMPL3115A2 Digital Altitude / Pressure / Temperature SensorMPU6050 accelerometer and gyroMPU6050 accelerometer and gyroMQTT ClientMQTT ClientModule for the MPR121 12-Channel Capacitive Sensor (I2C)Module for the MPR121 12-Channel Capacitive Sensor (I2C)MySensors Client/GatewayMySensors Client/GatewayNeuroSky ThinkGear ASIC moduleNeuroSky ThinkGear ASIC moduleOPT3001 Light SensorOPT3001 Light SensorPingPingQuectel UG9x GSM/GPRS/EDGE and UMTS/HSPA ModuleQuectel UG9x GSM/GPRS/EDGE and UMTS/HSPA ModuleRN2483 LoRa ModulesRN2483 LoRa ModulesRotary EncoderRotary EncoderSI7021(-A20) I2C Temperature and Humidity SensorSI7021(-A20) I2C Temperature and Humidity SensorSIMCom SIM800/SIM900 GSM/GPRS ModuleSIMCom SIM800/SIM900 GSM/GPRS ModuleST7565/ST7567 128x64 Monochrome LCD driverST7565/ST7567 128x64 Monochrome LCD driverSTM32F1 Flash Memory ModuleSTM32F1 Flash Memory ModuleSX1276/77/78/79 LoRa ModulesSX1276/77/78/79 LoRa ModulesSensirion SHT10 SHT11 & SHT15 Temperature and Relative Humidity Sensor ModuleSensirion SHT10 SHT11 & SHT15 Temperature and Relative Humidity Sensor ModuleSensirion SHT20, SHT21 & SHT25 Temperature and Relative Humidity SensorSensirion SHT20, SHT21 & SHT25 Temperature and Relative Humidity SensorSimple Finite State MachineSimple Finite State MachineSimple Linux-like Cron systemSimple Linux-like Cron systemSmartNixie Nixie Tube driverSmartNixie Nixie Tube driverTCS3200 Light SensorTCS3200 Light SensorTCS3472x I2C Color SensorTCS3472x I2C Color SensorTLE94112TLE94112TM1640 8x8 Matrix LED Shield driverTM1640 8x8 Matrix LED Shield driverTSL2561 Luminosity sensorTSL2561 Luminosity sensorThermistor Temperature SensorThermistor Temperature SensorTouchscreenTouchscreenVec3 - 3 element VectorVec3 - 3 element VectorViziblesViziblesVizibles (Español)Vizibles (Español)nRF905 Wireless TransceivernRF905 Wireless TransceiverxBee radio modulexBee radio module

Built-in Functionality

Espruino also contains many built-in modules and classes that provide a lot of functionality:

Analog IOAnalog IOAnalog to Digital ConverterAnalog to Digital ConverterBluetoothBluetoothCC3000 WiFi ModuleCC3000 WiFi ModuleDigital to Analog ConverterDigital to Analog ConverterESP8266 WiFi ModuleESP8266 WiFi ModuleGraphics LibraryGraphics LibraryI2C - Inter-Integrated CircuitI2C - Inter-Integrated CircuitInternet (HTTP)Internet (HTTP)OneWireOneWirePulse Width ModulationPulse Width ModulationSPI - Serial Peripheral InterfaceSPI - Serial Peripheral InterfaceServo MotorsServo MotorsUSART / UART / Serial PortUSART / UART / Serial PortWIZnet WIZ550io/W5500 Ethernet moduleWIZnet WIZ550io/W5500 Ethernet moduleWS2811/WS2812/WS2812B/APA104/APA106/SK6812 LED String/StripWS2811/WS2812/WS2812B/APA104/APA106/SK6812 LED String/StripWaveformsWaveformsEspruino Performance NotesEspruino Performance NotesInline AssemblerInline AssemblerInline C codeInline C codeJavaScript CompilationJavaScript CompilationSaving code on EspruinoSaving code on Espruino

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...

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.