Getting Started with Johnny-Five in Proteus

Arduino Johnny Five LED blink in Proteus

In the first part of this tutorial Programming Arduino with Johnny-Five in Proteus we discussed, what is Johnny-Five is, what node.js is,  what Proteus is and the benefits of using Johnny-Five in Proteus. We also explained the necessary application and library to run johnny-five based Arduino program in Proteus. That is we showed how to install Node.js, Johnny-Five, generate StandardFirmataPlus hex file etc. Here we dive into the steps to get started with programming Arduino in Proteus using Johnny-Five.

Step 1: Create a new project in Proteus

Once you have Proteus and Johnny-Five installed, you can create a new Proteus project in the same folder where you installed johnny-five library. Open Proteus and create a new schematic by clicking on File > New > Schematic. This will open a blank canvas where you can design your electronic circuit.

Step 2: Add Arduino Board and Components

In the Proteus schematic, you can add an Arduino board and other electronic components to your circuit. Proteus provides a wide range of components that you can drag and drop from the library onto your schematic. Place Arduino, COMPIM(Serial communication library part), a LED and a resistor as shown below. Connect the circuit as shown below.

Arduino Johnny-Five Proteus Circuit Diagram

 Double click on the Arduino to open its properties and browse and select the StandardFirmataPlus.hex file in the Program File section.

StandardFirmataPlus hex file

 Next, double click on the COMPIM part and edit the port to COM1 and baudrate to 57600 for both the physical and logical port as shown below. The 57600 baud rate is important because the firmata which we had created earlier requires baud rate of 57600.

Step 3: Download and install Virtual Serial Port Emulator(VSPE)

Next in order to communicate between Johnny-Five application with COM port part in Proteus we need virtual COM port pair. The software VSPE can create virtual com port for this. You can download and install the free version from the following link.

https://eterlogic.com/Products.VSPE.html

Once install create a virtual pair between COM1 and COM2 as shown below.

vspe

A detailed tutorial on how to configure COM port in Proteus and set up virtual com port is explained in the tutorial Serial communication from PC to Proteus.

 Step 4: Write Johnny-Five LED blink code

Next open any text editor like nodepad and write the following program.

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

board.on("ready", () => {
  // Create an Led on pin 8
  const led = new Led(8);
  // Blink every half second
  led.blink(500);
});

The code snippet you provided is an example of how to use Johnny-Five library in a Node.js application to control an LED connected to an Arduino board.

Here's a breakdown of the code:

  • const { Board, Led } = require("johnny-five");: This line imports the necessary modules from the Johnny-Five library. Board represents the Arduino board, and Led represents an LED component that can be controlled using Johnny-Five.
  • const board = new Board({port:"COM2"});: This line creates a new Board object, which represents the connection to the Arduino board. The port option specifies the serial port that the Arduino is connected to, in this case, it is set to "COM2".
  • board.on("ready", () => { ... });: This sets up an event listener for the "ready" event on the board object. The "ready" event is emitted when the Arduino board is ready to receive commands.
  • const led = new Led(8);: Inside the "ready" event handler, this line creates a new Led object representing the LED component connected to pin 8 of the Arduino board.
  • led.blink(500);: This line calls the blink() method on the led object, which makes the LED blink on and off every 500 milliseconds (half a second).

 Save the file as ledblink.js.

Step 5: Run the Simulation

The final step is to run the simulation. At this point the VSPE must be running. Then run the Proteus simulation. Then in the terminal type in the following npm command:

node ledblink

Then you should see the LED blinking in Proteus.

Arduino Johnny Five LED blink in Proteus

References and Further Readings

[1] Interfacing Proteus and MATLAB-SIMULINK for Co-Simulation

[2] Send data from Simulink to Proteus for Arduino Co-Simulation

[3] Arduino in Proteus co-simulation with Simulink: Advantages & Applications

Post a Comment

Previous Post Next Post