Language: EN

que-es-y-como-usar-johnny-five-con-esp32

How to use Johnny-Five on an ESP32

Johnny-Five is a JavaScript framework designed for creating applications in embedded systems and robotics.

This means we can easily interact with a development board like an ESP32, using JavaScript.

Key Features

  1. JavaScript: Allows developers who are already familiar with JavaScript to work with hardware without having to learn a new language.
  2. Active community: Johnny-Five has a large community and a wealth of examples.
  3. Multiple hardware: Can be used on different hardware platforms.
  4. Integration with Node.js: Which allows building web and IoT applications.

Johnny-Five is not for programming your device in JavaScript. Johnny-Five provides an easy-to-use API to interact with hardware.

The program runs on Node.js and communicates with the hardware (via Firmata). The advantage is that it is easy to integrate into web and IoT projects.

👆 If you want to know more, check the Node.js course

Installing Johnny-Five

To start using Johnny-Five with the ESP32, we need to set up our development environment.

Install Node.js: If you haven’t installed it yet, download and install it following the instructions for your operating system.

Set up your Project

  • Create a new folder for your project and navigate to it in the terminal.
  • Initialize a new Node.js project with the following command:
npm init -y

Install Johnny-Five: Run the following command to install Johnny-Five

npm install johnny-five

Example Load

To verify that the installation is correct, let’s load a simple example that will make an LED connected to the ESP32 blink.

Upload the Firmata to the ESP32

Johnny-Five communicates with the hardware through the Firmata protocol, so it is necessary to upload the firmware to the ESP32.

Code in Node.js

Create a file index.js in your project folder and add the following code:

const { Board, Led } = require("johnny-five");
const board = new Board();

board.on("ready", () => {
  const led = new Led(13); // Pin 13 for the LED
  led.blink(500); // Blink every 500 ms
});

Run the code

In the terminal, run the following command:

node index.js

If everything is set up correctly, the LED should start blinking.

Examples of Using Johnny-Five

Once you have Johnny-Five installed and running, you can start interacting with different hardware components.