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

How to use Johnny-Five on an ESP32

  • 3 min

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 already familiar with JavaScript to work with hardware without having to learn a new language.
  2. Active community: Johnny-Five has a wide community and a large number of examples.
  3. Multiple hardware: It can be used on different hardware platforms.
  4. Integration with Node.js: This 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 in Node.JS and communicates with the hardware (through firmware). The advantage is that it’s easy to integrate into web and IoT projects.

Learn to develop with Node.js step by step

👆 If you want to learn more, check out 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 don’t have it installed, 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

Loading Example

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

Load Firmata onto the ESP32

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

Node.js Code

Create a file named 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
});
Copied!

Run the code

In the terminal, run the following command:

node index.js

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

Johnny-Five Usage Examples

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