Skip to content

Johnny Five, how to use a REPL

This post is part of the Johnny Five series. See the first post here.

When you run a program using Johnny Five, you can see that in the terminal, we have access to a REPL, a term that means Read-Evaluate-Print-Loop.

In other words, we can write commands in here.

Let's try by creating a repl.js file with this code:

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

I am going to play with the LCD circuit made in the previous lesson.

Run the program with node repl.js:

Next, we're going to write some commands in the REPL.

Start by requiring the LCD class:

const { LCD } = require("johnny-five")

Then initialize an lcd object from it:

const lcd = new LCD({ pins: [7, 8, 9, 10, 11, 12] })

Now write to the LCD display:


You'll see a big message coming back:

Because the command returns a reference to the LCD object. This is to let us chain commands together, like this:


If you don't run clear(), any new thing you write is going to be appended to the one already there.

To write to the second row, you call cursor(1) (the default row is 0:

lcd.clear().print("Hello from")
lcd.cursor(1, 0).print("Johnny-Five!")

→ Download my free JavaScript Handbook!



You might be interested in those things I do:

  • Learn to code in THE VALLEY OF CODE, your your web development manual
  • Find a ton of Web Development projects to learn modern tech stacks in practice in THE VALLEY OF CODE PRO
  • I wrote 16 books for beginner software developers, DOWNLOAD THEM NOW
  • Every year I organize a hands-on cohort course coding BOOTCAMP to teach you how to build a complex, modern Web Application in practice (next edition February-March-April-May 2024)
  • Learn how to start a solopreneur business on the Internet with SOLO LAB (next edition in 2024)
  • Find me on X

Related posts that talk about js: