Modules
Содержание:
save()
If you type on the left-hand side of the IDE after your code is
uploaded, the contents of Espruino’s RAM at that point will be compressed
and written in to flash memory.
This includes:
- All variables and functions
- Any watches created with
- Timeouts and intervals created with and
- All Pin states
When power is next applied, Espruino will load the information back out of
flash and will resume where it left off. You can think of this a bit like
‘hibernate’ on a PC.
This is the standard way of saving code in normal Espruino devices (it is
not suitable for Bangle.js), and it means that
you can interact with your code on the left-hand side of the IDE, changing
variables and functions, and can then save everything — including your changes.
For instance, if you upload the code and type
, will contain the temperature of the device at the time that
you uploaded — not at the time the device started, or even the time you
typed .
However, this means that any code that was executed at upload time will not
be re-executed. For instance you may have some external hardware like an LCD
display connected to Espruino — after applying power, the LCD will need to be
initialised (since it can not remember its state). In this case you can
create a function called (or add a
listener) that is automatically called by the interpreter when it
initialises.
Once code is saved, you can return the interpreter to a ‘clean’ state
with . This won’t clear out any of the saved data in flash, so
if you reboot the device (or call ) it will re-load your previously
saved state. To completely clear out saved code, run and then
run to save the clean state back into flash memory.
Pros
- Once you have your software working, you can just and it will keep working
- You can make changes to d code and can then type again to save your changes
- JS code isn’t stored in flash as plain text, so is harder for a malicious user to extract
- will allow JavaScript code in RAM to be heavily compacted, and to execute more quickly.
Cons
- Not as memory efficient since everything is stored in RAM
- Some formatting of the code inside functions may change, and comments outside functions won’t be saved
- Any code that has to be run at startup needs to be placed in a function called , or a event handler
Gotchas
- Unless you use or , code won’t run at boot time.
- Since and are remembered, if you call them in and then multiple times, you can end up with multiple copies. You can use and in to avoid that.
- When uploading code with an or function the function won’t be called at upload time and to test you’ll have to either or call manually.
Режим HID, эмуляция клавиатуры
Espruino поддерживает работу через USB в режиме (Human Interface Device), что позволяет эмулировать клавиатуру, мышь или планшет (подробнее — здесь).
Для эмуляции USB-клавиатуры необходимо подключить внешний модуль . Введем в правой части окна в текстовом редакторе:
Espruino Web IDE определит, что используется внешний модуль, и произведет его поиск в подкаталоге каталога проекта (его предварительно необходимо задать в настройках) и в каталоге на сайте Espruino, минифицирует его (в соответствии с настройками), затем вместе с текстом программы загрузит в Espruino. Можно указать не только имя модуля, можно указать URL файла с его исходным текстом, в этом случае модуль будет загружен с указанного ресурса.
Вариант 1. Присоединись к сообществу «Xakep.ru», чтобы читать все материалы на сайте
Членство в сообществе в течение указанного срока откроет тебе доступ ко ВСЕМ материалам «Хакера», увеличит личную накопительную скидку и позволит накапливать профессиональный рейтинг Xakep Score!
Подробнее
Вариант 2. Открой один материал
Заинтересовала статья, но нет возможности стать членом клуба «Xakep.ru»? Тогда этот вариант для тебя!
Обрати внимание: этот способ подходит только для статей, опубликованных более двух месяцев назад.
Я уже участник «Xakep.ru»
Advanced Reflashing
In very rare cases (if you are experimenting with writing to Flash Memory), you may be able to damage the bootloader, which will effecitively ‘brick’ the Pico.
To fix this, you’ll have to use the hard-wired USB DFU (Device Firmware Upgrade) bootloader. You can also use this method for flashing non-Espruino firmwares to Espruino.
Just:
- Short out the solder jumper on the back of the board — you can do this by drawing over it with a pencil.
- Install ST’s DFU utility on Windows, or dfu-util for Mac or Linux
- Download the latest Espruino Pico binary from espruino.com/binaries
- Hold down the Pico’s button while plugging it into USB
- Use the DFU tool to flash the firmware. Using the GUI on windows, or with the command for on Mac/Linux.
- Un-short the jumper to re-use the original Espruino Bootloader. If you used a Pencil mark then you may need to use cleaning fluid and a small brush to totally clear out the graphite.
Note: If you can’t access the bottom side of the board (maybe it is soldered down), on rev 1v3 boards BOOT0 is available via a gold teardrop-shaped pad on the top of the board. Short this to 3.3v while applying power to enable DFU mode (holding down the button is then not required).
Boot Process
To understand how best to save data, it’s best to know how Espruino
loads saved code.
When Espruino starts up, it does a few things:
- If is pressed or if it reset because of a call to , it sets to .
- If wasn’t set, it looks for a compressed image ( ) of the interpreter’s state that was saved with . If it exists it unpacks it into RAM.
- (v2.0 and later) It looks for files named , , and and executes them in sequence.
- If wasn’t set, it looks for a file named and executes it (see below)
- If was set, it looks for a file named and executes it (see below)
- Initialises any previously-initialised peripherals
- Runs any handlers registered with
- Runs a function called if it exists.
If Espruino is reset with it follows the same steps as above, with to .
However in Espruino 2v05 and later, will follow the same steps but will load the
specified file instead of /.
There are two main ways to save code with Espruino:
Job File
A job file simplifies specifying the command-line and provides a future record of the run setup. Specifying the -j option without a job file name will generate a job file automatically using the given JS code file as the base name and any commandline arguments specified.
For example,
espruino -j -t -w test.js; // will create test.json
The following table provides a guide for setting configuration fields, but consult the code for certainty. Module/pluggin values generally override other keys. It is not necessary to include any fields except the ones you want.
| Commandline Argument | JSON Key 1,2 | Module/Pluggin 2,3 |
|---|---|---|
| file_to_upload.js | file («») | |
| -b baudrate | baudRate (0) | BAUD_RATE (9600) |
| -c | color (false) | |
| -e command | expr («») | |
| -f firmware.bin | updateFirmware («») | |
| firmwareFlashOffset(0) | ||
| —list | showDevices (false) | |
| -m,-minify | minify (false) | MINIFICATION_LEVEL («») |
| MINIFICATION_Mangle (true) 4 | ||
| -no-ble | no-ble (false) | BLUETOOTH_LOW_ENERGY (true) |
| -o out.js | outputJS («») | |
| -p,—port /dev/ttyX | ports () | |
| -q,—quiet | quiet (false) | |
| -t,—time | setTime (false) | SET_TIME_ON_WRITE (false) |
| -v,—verbose | verbose (false) | |
| -w,—watch | watchFile (false) | |
| BOARD_JSON_URL («http://www.espruino.com/json») | ||
| COMPILATION (true) | ||
| COMPILATION_URL («http://www.espruino.com:32766») | ||
| ENV_ON_CONNECT (true) | ||
| MODULE_AS_FUNCTION (false) | ||
| MODULE_EXTENSIONS («.min.js | ||
| MODULE_MINIFICATION_LEVEL («») | ||
| MODULE_URL («http://www.espruino.com/modules») 5 | ||
| NPM_MODULES (false) | ||
| RESET_BEFORE_SEND (true) | ||
| SAVE_ON_SEND (0) | ||
| SERIAL_AUDIO (0) | ||
| SERIAL_TCPIP («») | ||
| SERIAL_THROTTLE_SEND (false) | ||
| STORE_LINE_NUMBERS (true) | ||
| UI_MODE («Normal») | ||
| WEB_BLUETOOTH (true) |
Notes:
- JSON keys equate to internal args variable keys.
- Default values shown in parentheses or see configDefaults.json file under node_modules/espruino folder. Check code directly for issues.
- Recommended for advanced users only. Module and plugin keys equate to internal Espruino.Config variable keys stored in job file as subkeys under espruino key. Consult code for possible values.
- Minification parameters only work if level set, e.g. MINIFICATION_LEVEL: «ESPRIMA».
- MODULE_URL accepts a pipe delimited (|) list of URLS, including local servers and absolute or relative paths based on the code file. For example, «../../modules|http://localhost:8080/modules|http://www.espruino.com/modules» will first look in the module folder located two folders up from the code, then query the localhost server, and then look in the Espruino repository.
Plugging in
Please check that there is no bare metal (including your desk!) near the board when you plug it in, as it could short it out.
- Espruino Pico — the Pico is designed to plug right into you computer’s USB type A connector, or a USB extension lead. The components (not the text) should usually be facing upwards (so the 4 gold strips are facing the plastic in the USB socket).
- Original Espruino, Espruino WiFi and Wio LTE — just plug the board in with a Micro USB cable and you’re done.
- Puck.js — there is no plug! see the Bluetooth LE Quick Start Guide instead as the setup is slightly different.
- Pixl.js — the USB plug is only for power see the Bluetooth LE Quick Start Guide instead as the setup is slightly different.
- Other Boards — please see this page for more information.
Windows Users: Older versions of Windows won’t automatically load the built-in driver for USB COM ports. You’ll have to download ST’s USB driver:
-
Windows 10 users should need no drivers. The board will plug in and be recognised immediately.
-
Non-Windows XP users download version 1.4.0 drivers. Unzip the file, run the executable, and then go to in Windows Explorer and double-click either for 64 bit systems, or for 32 bit.
-
Windows XP users download version 1.3.1 drivers. Unzip the file, run , and then go to in Windows Explorer and double-click the executable.
Linux users to ensure that you have the correct permissions to connect as a normal user you’ll need to copy the file 45-espruino.rules to , reload rules with , and ensure your user is in the group (you can check by typing ). You add it by typing and then logging out and back in. Arch Linux users need to add their user to and groups instead.
Mac OS X and Chromebook Users: The board will just plug in and work, without drivers!
Software Updates
Espruino is gaining features and improvements on an almost daily basis. If you’ve just got your Espruino Board, we highly recommend that you update the firmware before you start using it.
When you first use the Espruino Web IDE and connect (see above) you’ll probably see a yellow warning marker in the top right saying that new firmware is available. Click on it (or click the icon, then ), click ‘Flash Firmware’ and follow the instructions. If you’re given a drop-down list of different firmwares to choose from and you don’t need network support, you can choose any firmware. There is no risk of damaging your Espruino board, however the firmware update process may take a few minutes to complete. If you have problems, check out the Troubleshooting guide.
Note: If you’re not using the Web IDE, follow the instructions on the Download page to flash the latest version (however this is significantly more difficult).
Installing from GitHub (Latest Version)
You need to obtain both the EspruinoWebIDE repository and the EspruinoTools repository, a submodule used in the Web IDE.
A simple way to obtain both repositories is via the git command:
This will clone both the EspruinoWebIDE repository and the submodule dependencies. Alternatively, you can download or clone both repositories individually following the steps below:
- Click the menu icon in the top right
- Click ‘Settings’
- Click ‘Extensions’ on the left
- Click ‘Load Unpackaged Extension’
- Navigate to the Directory and click Ok
- Job Done. It’ll now appear as an app with the ‘Unpacked’ banner so you can tell it apart from the normal Web IDE. You can start it easily by clicking the ‘Launch’ link on the extensions page, or whenever you open a new tab.
- Go to the directory
- Run
- Run
- Run
Wiring Up
The bare display and controller module needs to be connected with a 24pin FPC connector with 0.5mm pitch and an additional driving circuit. There are rather huge and expensive ready to use development boards available from the display manufacturer. You can even try to build the minimum circuit yourself, e.g. like Jaroslav Sýkora did.
The following infos apply only to the connection between SSD1606 and a microcontroller, ignoring the driving circuit.
Pin overview
| SSD1606 | Notes |
|---|---|
| GND | Ground |
| SDA | SPI mosi pin. The SSD1606 provides no miso pin. |
| SCL | SPI Clock pin |
| CS1 | Chip select pin, is used to prepare the SSD1606 to receive data over SPI. Pull High before you send data over SPI. |
| D/C | Data/Command control pin, is used to prepare the SSD1606 to receive either commands (pulled LOW) or data (pulled HIGH) over SPI. |
| Res | Hardware Reset pin, pull LOW to reset the SSD1606. |
| BU | This pin is Busy state output pin When Busy is High, the operation of the chip should not be interrupted, command should not be sent. |
| BS1 | Pin for selecting SPI wire mode, pull LOW for 4-wire mode and HIGH for 3-wire mode. |
| 3.3v | Power pin. |
The SSD1606 provides two types of SPI interface modes, but the module supports 4-wire mode only.
SPI-Mode 4-wire
In 4-wire mode you need to set the D/C pin before each SPI send to signal either a command or data will be send. The module takes care of that for you.
Wiring example for SPI 4-wire mode
| SSD1606 | Espruino Pico | Notes |
|---|---|---|
| GND | GND | |
| SDA | B5 | B5 is SPI-1 mosi on Espruino Pico, you can also use SPI-2 or SPI-3. |
| SCL | B3 | B3 is SPI-1 clock on Espruino Pico, you can also use SPI-2 or SPI-3. |
| CS1 | B6 | You can use any of the GPIO pins on the Espruino Pico. |
| D/C | B7 | You can use any of the GPIO pins on the Espruino Pico. |
| Res | A5 | You can use any of the GPIO pins on the Espruino Pico. |
| BU | A8 | You can use any of the GPIO pins on the Espruino Pico. |
| BS1 | A6 | You can use any of the GPIO pins on the Espruino Pico or connect it to either GND or 3.3v. |
| 3.3v | A7 | You can use any of the GPIO pins on the Espruino Pico to have full control or connect it to 3.3v. |
I’ve pasted code into the left-hand side of the Web IDE and it doesn’t work
There could be several reasons for this, but the likely one is that you have formatted your code in a way that doesn’t work well with a command-line interface.
Each time you press enter, Espruino’s command-line interface counts brackets to see if the statement you’ve entered is complete. If it is, it’ll try and execute it. For instance:
is a complete statement, so when you hit enter at the end it’ll be executed immediately. However if you type:
Then now we have a problem. Halfway through, Espruino sees that the first statement is complete and executes, and it’s now given a line that starts that isn’t a valid statement.
The easiest way to fix this is to write code in something similar to the . See the Coding Style page for more information.
If you’re writing code in the right-hand side of the Web IDE, the Web IDE should try and detect the different formatting and insert a special newline character (Alt-Enter) which will fix it for you. If you’re using other tools to send data to Espruino then this may not automatically happen for you though.
Note: If you use on the left-hand side and the module is not already part of Espruino, you may find that you get a ‘Module not found’ error. In this case, you should add the command to the right-hand pane of the Web IDE and click . This will automatically load the module into Espruino, allowing you to use it from the left hand side.
How is Espruino different to Arduino / Raspberry Pi / Embedded Linux?
Espruino vs Raspberry Pi / Embedded Linux boards
- Raspberry Pis are very powerful and flexible, but have a relatively high power consumption in idle, making it difficult to run them off a battery. Raspberry Pi is ~50mA minimum when idling, Puck.js is 0.003mA.
- You can’t reliably schedule actions in real-time on a Raspberry Pi which makes accurate timing difficult
- Raspberry Pis are good at Video, which Espruino isn’t powerful enough to support.
- Espruino runs JavaScript: this makes it very approachable and easy for beginners. Raspberry Pi on the other hand gives you a choice of programming languages, which is powerful — but can be daunting.
- Raspberry Pi lacks Analog IO, which is supported by Espruino.
- Raspberry Pi requires an SD card containing the operating system (which Espruino doesn’t).
Espruino v Arduino
- Espruinos are smaller than most Arduino boards and are much easier to get started with.
- You don’t have to pre-install software on your Mac or PC.
- While Arduino has low power consumption, the Espruino board is designed with efficiency in mind and draws over 10x less power when sleeping.
- The use of a JavaScript interpreter means Espruino doesn’t have to be reset when you make changes to the code, however it also means that the execution speed will be slightly slower.
Tutorials
Links to tutorials that you can do using just the Espruino board:
Quick Start (Writing Code)
Quick Start (USB)
Single Button Combination Lock
.NET Gadgeteer Modules
Infrared Remote Control
Dial Tones
Understanding PWM and Implementing it Yourself
Flashing Lights
Using BTN1 to turn on an LED
Tutorials using the Espruino Board:
Tap Tap Rainbow — a 2 Player Quick Reaction Game
Pocket ‘walking’ GPS
Espruino Web IDE
KeyPad Timer
Advanced Debug
Heater Controller
Wireless Temperature Sensor
WiFi Enabled Thermometer
Favourite Icon on Web Server
Water Physics with Servo Motors
Remote Control Sockets
Soldering an LCD directly to Espruino
Motion Sensing Lights
Morse Code Texting
MeArm Robotic Arm
KeyPad Combination Lock
Infrared Remote Control
Individually Addressable LEDs
Graphical Web Interface
Dial Tones
Wifi Remote Console
WiFi Xively Humidity/Temperature Sensor with Display
Digital Dice
Simple Data Logger
Small Solar Powered Espruino
Mounting the Espruino Board
Temperature Graph on a PCD8544 display, with DS18B20 temperature sensor
Temperature on a PCD8544 display, with DS18B20 temperature sensor
Making Sounds and Music
LED Clock (using WS8111)
Remote Control Helicopter with Wii Nunchuck
LED Volume (VU) Meter
Shim Collection

The shim collection is a single 10cm x 10cm board, containing several different shims for your Pico that can be snapped out.
It consists of:
Eagle CAD board
and schematic
See the ESP8266 page for more information (and videos) on soldering this shim.
NRF24L01P 0.05″ Shim
Eagle CAD board
and schematic
Solder this on to the end of your Pico like the ESP8266 shim. The NRF24 should be positioned such that it overlaps the Pico.
See the NRF24L01P page for more information on software.
| Pico | NRF24L01P |
|---|---|
| A10 | CE |
| A0 | CSN |
| A1 | SCK |
| A2 | MOSI |
| A3 | MISO |
| A4 | IRQ |
ESP8266 ESP12 0.1″ Adaptor
Eagle CAD board
and schematic
This board may need an Espruino Pico rev 1v4 board (or an Espruino rev 1v3 with external power) to work reliably.
Note: on rev 1.0 adaptors, you need to short pins 9 and 10 of the ESP8266 together (the two pins on the edge, nearest the Pico’s pin A8).
See the ESP8266 page for more information on software.
| Pico | ESP8266 |
|---|---|
| B6 | ESP8266 RX |
| B7 | ESP8266_TX |
| Component | Function |
|---|---|
| R1 | 1206 4.7k Optional pullup for GPIO16 and RESET |
| R2 | 1206 4.7k Optional pullup for GPIO0 |
| R3 | 1206 4.7k Optional pullup for GPIO2 |
Bluetooth 0.1″ Adaptor
Eagle CAD board
and schematic
This connects to HC-05, HC-06 or HM-10 bluetooth modules. See the Bluetooth and BLE pages for more information on software.
| Pico | Bluetooth |
|---|---|
| B6 | Bluetooth RX |
| B7 | Bluetooth TX |
| A8 | Bluetooth Key PIO0 (if solder jumper on reverse is shorted) |
Note: PIO1 on Bluetooth (the connection status LED) is connected to pads down the side of the Bluetooth module for an optional 0603 100 Ohm resistor and LED.
RFM69/RFM12B 0.1″ Adaptor
Eagle CAD board
and schematic
This adaptor lets you solder on a RFM69 or a RFM12B module
See the RFM69 page for information on software. There is currently no software for the RFM12B.
| Pico | RFM12B | RFM69 |
|---|---|---|
| A7 | IRQ | DIO0 (IRQ) |
| B1 | — | RST |
| B10 | CS | CS |
| B13 | SCK | SCK |
| B14 | MISO | MISO |
| B15 | MOSI | MOSI |
Note:
- When positioning the device, check the silkscreen on the rear for an marking, and position that away from the Pico, near on the PCB.
- The outlines for the RFM12/RFM69 overlap, so to make sure there is no chance of a short when adding a module, please cover the row of unused pins that sits under the module you’re soldering with a small bit of tape.
- There is an outline for a surface mount JST battery connector that sits under the Pico. If soldering your Pico flat onto the board (without pin sockets) please cover this with tape first to avoid shorts.
Eagle CAD board
and schematic
This adaptor has its own page
MicroSD 0.1″ Adaptor
Eagle CAD board
and schematic
| Pico | MicroSD |
|---|---|
| B1 | CS |
| B13 | SCK |
| B14 | MISO |
| B15 | MOSI |
Note 2: On rev 1.0 of this board, GND is not connected. You will have manually to add a wire from GND of the Espruino Pico to pin 6 of the micro SD card connector. Adding a 0.1uF decoupling capacitor across the voltage rail is also a good idea.
Note: The resistor is for a 1206-size 100k pullup resistor for the line. This should
be added as it avoids unintentional SD card accesses that could occur before the Espruino Pico has set
up the CS line properly.
0.05″ Breakout Adaptor
Eagle CAD board
and schematic
This adaptor simply converts the Pico’s 0.05″ pins to 0.1″ pins that can be easily accessed. To use this properly you’ll need to solder an unpinned Pico flat onto the board.
Note: The board is not handed and can be used any way up.
0.05″ Breakout and Prototype Adaptor
Eagle CAD board
and schematic
This adaptor converts the Pico’s 0.05″ pins to 0.1″ pins that can be easily accessed, and also provides a prototype area on the end of the board. To use this properly you’ll need to solder an unpinned Pico flat onto the board.
Note: There is the outline for a surface mount JST battery connector on the board.
- On early revisions this is on the Top of the board and would get in the way of the Pico (so needs covering up with tape first to avoid shorts).
- On later revisions this is on the Bottom of the board, and the Top has on the silkscreen.
0.1″ Prototype Adaptor
Eagle CAD board
and schematic
This adaptor provides a small prototype area either side of the Espruino Pico. It does not allow connections to any of the 0.05″ pins, but can be used in conjunction with 0.05″ shims like the ESP8266 or WiFi shims above.
Note: There is an outline for a surface mount JST battery connector that sits under the Pico. If soldering your Pico flat onto the board (without pin sockets) please cover this with tape first to avoid shorts.
Connection Types
USB
Normal Espruino boards have a USB connector, and when you plug this into
your PC the board appears as a USB Serial device, which you can then connect
to.
This is what we’d suggest programming Espruino devices with.
Bluetooth LE
Puck.js devices present themselves as as Bluetooth LE ‘Nordic UART’
device, and can be connected to and programmed through that. It’s the suggested
method of connection for Puck.js.
Adafruit make a Bluetooth LE UART board
that can be used to add Bluetooth LE UART capability to other Espruino devices.
Serial / UART
When not connected to a computer by USB, Espruino boards usually open up a serial
port on two of their pins at 9600 baud so that they can be programmed via Serial.
The pins used for this are detailed in the Pinout section of your board’s specific
reference page (eg , where they’re marked with ).
To save power, Puck.js only powers up the serial port if it detects
a voltage on the RX pin at boot time. See
Bluetooth UART
The Original Espruino Board has a footprint on the back for
an HC-05/HC-06 Bluetooth Module. Once soldered, it uses the
standard Serial port (detailed above) for communication. For more information
see here.
Standard Bluetooth is not the same as Bluetooth LE, and can’t be used to
communicate from a Website.
WiFi/Ethernet
Currently Espruino boards don’t come with Telnet support out of the box.
If you’re running Espruino on an ESP8266 then Telnet is
enabled.
On other boards, once you have a network connection established you can run:
However, using will break your connection.
I’ve connected an I2C device, but I get ‘timeout’ errors
This is usually one of four reasons:
- There are no pull-up resistors. I2C needs resistors between each of its data lines and 3.3v (or 5v) — these are usually in the 4-10 kOhm range. Many modules already have them in, but if you have a module without one then you need to add them before I2C will work.
- The device’s address is incorrect — sometimes people quote the address as being twice as large as it actually is. If in doubt, try dividing the address by two or multiplying it by two.
- The device isn’t powered or ground isn’t shared (see the point above)
- The SDA and SCL wires are mixed up. SDA should be connected to SDA, and SCL to SCL.
Advanced Reflashing
In very rare cases (if you are experimenting with writing to Flash Memory), you may be able to damage the bootloader, which will effecitively ‘brick’ the Espruino WiFi.
To fix this, you’ll have to use the hard-wired USB DFU (Device Firmware Upgrade) bootloader. You can also use this method for flashing non-Espruino firmwares to Espruino.
Just:
- Short out the solder jumper on the back of the board — you can do this by drawing over it with a pencil.
- Install ST’s DFU utility on Windows, or dfu-util for Mac or Linux
- Download the latest Espruino WiFi binary from espruino.com/binaries
- Hold down the Espruino WiFi’s button while plugging it into USB
- Use the DFU tool to flash the firmware. Using the GUI on windows, or with the command for on Mac/Linux.
- Un-short the jumper to re-use the original Espruino Bootloader. If you used a Pencil mark then you may need to use cleaning fluid and a small brush to totally clear out the graphite.
I get Uncaught Error: Module XYZ not found
This could be because the module doesn’t exist in Espruino’s list of modules — Espruino doesn’t directly support inclusion of modules from NPM, because the vast majority have too many dependencies to be used on an embedded target.
However, if you’re trying to use example code for Espruino, chances are it’s because you typed the command on the left-hand side of the IDE (see the last FAQ item). The majority of modules are loaded on-demand by the IDE (some are built-in) when code is uploaded, but the left-hand side of the IDE is a REPL — a direct connection to the Espruino device. In that case the IDE doesn’t have a chance to intercept the command and automatically upload the module for you.
Using WiFi
Connecting to an AP
To use wifi, simply require the module and call . The following code
will connect and then request the page :
For more information on HTTP requests/etc once connected, check
out this Page on HTTP.
Note: If you want Espruino to connect at power on after you have
saved, make sure that you call the WiFi initialisation code inside an
function — eg:
Access Point Mode
Espruino WiFi can be made into a WiFi access point with:
See the reference below for more information. and can be used together to make Espruino become an access point while also connecting to another WiFi network. In that case, it’ll have the DHCP-assigned IP address on the WiFi network it is connected to, and the IP address on the access point it has created.
Note: In 2v06 and earlier, you must specify a dummy password in order to have a ‘open’ access point, eg. . In 2v07 and later this is fixed, and even just will create an open access point.
Using
- Run the Web app
- Click the (?) icon, then the button to get a guided tour.
Running with Node.js/Electron and don’t see any ports when you try and connect? You’re probably using a version of Node.js that doesn’t match Electron. This causes NPM to load binary modules (for and ) that are for the old version of Node and that won’t work in Electron. To fix it, update Node.js, delete and run again.
Debugging with NW In order to debug the WebIDE using DevTools you need to install the SDK flavor of nw. This can be done with instead of just . Once the SDK flavor is installed you can specify a remote-debug port like this .
Tutorials
Tutorials using the Pico Board:
GNSS Espruino Position Tracker
Espruino ISS Notifier
Quick Start (Writing Code)
Espruino Web IDE
Handling POSTed data from Forms
Quick Start (USB)
Flappy Bird Game
Low-level STM32 Peripheral access
Advanced Debug
Pico Clock
Arduino Pico adaptor board
Espruino Home Computer
Snake Game
5 Minute Wire Loop Game
Pico Weather Station
Pico LCD Display Hello World
Pico Electronic Dice
Controlling Pico from a Computer
AA/AAA Battery Charger
Image Slideshow with ILI9341 display
Interactive Web-based UI
Logging to Google Sheets
Slot Machine
Pico Vibration
Pico Piano
Pico Light Sensor
Pico Infrared Transmit and Receive
Pico FET Output
Pico Buttons
Storing HTTPS Certificates
When is code executed?
When you write code in the right-hand pane of the Espruino IDE and click , by default the code is sent to Espruino almost as if you copied and pasted it into the left-hand pane (this doesn’t have to be the case — see the Saving page).
This means that if you write , the value of will be set to the voltage on at the time you uploaded your code. It won’t be updated again, even after a reboot.
When you type , a copy of the current state of the interpreter is saved into Flash memory, not a copy of the code that you originally uploaded.
If you want to do something when Espruino reboots, add one or more event handlers for the event on :
This will then be loaded every time Espruino starts up. If you create a function called , that will be executed too:
But of course there can only be one function, so if you copy and paste two bits of code with two functions then the second function will overwrite the first. See the Saving page for more information.
I typed save() and it succeeded, but my code isn’t loaded at power on
You could try typing to see if your code has actually been saved. If it hasn’t, it’s possible that BTN1 or the pin it is connected to was held down while Espruino boots (as this stops Espruino from loading saved code).
You could try typing to force Espruino to load its saved program.
If you want to execute certain commands at power-on, add one or more event handlers for the event on :
This will then be loaded every time Espruino starts up. If you create a function called , that will be executed too:
But of course there can only be one function, so if you copy and paste two bits of code with two functions then the second function will overwrite the first.