Skip to main content

Using the Johnny-Five platform to control Arduino using JavaScript

When trying to figure out how to actually set the thinker blinker up, the creators specified that they "uploaded the Firmata sketch to an Arduino, then wrote JavaScript code to drive the bulb, using Johnny-five to communicate with it."



I then began to search on how to set this Johnny-five up. To understand more about what it is and how to use it, I stumble across this article. But the point I want to share is this.

Julian Gautier then implemented the Firmata protocol, a protocol used to access microcontrollers like Arduinos via software on a computer, using JavaScript in his Node.js Firmata library. 
Rick Waldron took it a massive step further. Using the Firmata library as a building block, he created a whole JavaScript Robotics and IoT programming framework called Johnny-Five. The Johnny-Five framework makes controlling everything from LEDs to various types of sensors relatively simple and painfree. This is what many NodeBots now use to achieve some very impressive feats!
I also searched for a simple tutorial on how to use these 'Johnny-five' with an Arduino and found this video by the channel MakeUseOf that explains the step by step on how to install the Johnny-five to your computer. Basically, the part that I followed for my own project is setting up your computer with the Johnny-five library.
  1. The first thing you need to do is set up node.js. If you don't have node.js, go to this link to download it. Then pick the 'Recommended For Most Users' option, and install it. (Note: make sure when installing node.js, on the custom setup, that the 'Add to Path' options are there)
  2. Once it's done installing, open your command prompt. To make sure your node.js is 'readable', type in "npm init", then continue pressing enter 'Is this OK? (Yes)' line comes out. Then press enter.
  3. Next, type in the line "npm install johnny-five". This is the line to actually install the johnny-five.
  4. The video also recommends us to install keypress beforehand to avoid any problems when doing your experiment, just in case. What keypress does is allowing to control your projects with the help of pressing keyboard buttons. To install it, just type in the line "npm install keypress".
After following the steps, you are basically done with installing it. However, when you want to try an experiment, make sure that your js is saved under the same folder as where your node.js is.

  1. After picking on which experiment you want to try out (the video uses this code as an example). Copy the codes to Notepad++ or Sublime to be able to read your codes more clearly.
  2. In the tutorial video, the const is replaced with the word var, which stands for variables. Inserting the first two lines, it means that we are telling the code to include the johnny-five and keypress library when activating this project.
  3. Now see the fourth line of the code, which says "const board = new Board();". MakeUseOf says that this line is to indicate with Port your Arduino is connected to (you can check it from your PC's device manager). Basically, this step is to help you if the javascript you're going to try out on your command prompt couldn't figure out which port your Arduino is on. By inserting the COM number to it. (Note: The var you see on the picture, is what this list's no. 2 is explaining, so don't be confused).
  4. Then, save your javascript under the same folder as to where your Command Prompt reads (by default, the location is C:\Users\(your Window's profile).
  5. Open your Command Prompt, then just type in "node (name of your javascript without it's extension). For example, if you save your js file as Servo21.js, then type in "node servo21" on the command prompt. Then just press enter. This will transfer the command to your Arduino board and the experiment should be happening.
Watch the video tutorial for more information on how they connect the Arduino Uno and Servo with Johnny-Five.

Comments

Popular posts from this blog

TouchDesigner Experiment: Inserting OSC data with OSCIn

From one of my last experiment , I tried to change the data input. Instead of using audio, I replaced it with OSC data from my Muse headset. To connect your OSC device to TouchDesigner, make sure that the IP address and port number is the same so the data transfer can be accurate. In this case, I use a third-party app called Mind Monitor (available on iOS devices) to connect my Muse headset to the TouchDesigner software. Below are screenshots and videos from my experiment. You can see that the brainwave data is already recorded in real-time in the software. Then I used the alpha, beta, and theta brainwave to change the movement of the visuals (the chosen brainwave data I used are just placeholders for now to see the movement). Then the data is connected with 'noise', which is like the fluid/abstract visuals you see on the background. I also set the colors to be moving/changing over time.

Final Project Research - Final Proposal

This blog post will summarize the proposal for my final project. Translating Memories. A brainwave art installation. This project is based on a lot of things, but mainly from making art that is personal, unique, one-of-a-kind to the person involved in making it, because the art is created by their own personal memory. It will also allow people to express their feelings with the correspondent memory without having to say it out loud. The projected image will consist of abstract visual created by the combination of lines, shapes, and colors that follows the Geneva Emotion wheel . The Geneva Emotion wheel has been commonly known by psychologists to determine what human emotions are represented by what color and plotted on a 2D valence-activation graph. This project doesn't really have any particular target audience. Anyone and everyone are welcomed. Art enthusiast or just the curious mind. The value that I believe when creating this project is it is still uncommon to us...

Arduino Experiments (pt. 1)

Earlier this week, I bought my first Arduino Kit . Since this is week 6 of term, our lecturer has asked us to display an experiment by week 7. It could be any type of experiment, and it doesn't even have to be related to our project. The reason why I picked to try on Arduino is that I think it's the closest medium I'll be using for my actual work. But I was kind of worried about this, mainly it is because I've never used or tried it before. I've only heard about it but never actually played around with it. So this is the kit I bought. It costs SGD 70 at one of the shops in Sim Lim Tower. It contains a lot of items to try out experiments. It also includes several tutorial cards that can be successfully running with the items provided in the kit. For more detailed tutorials and the codes of each project, we are asked to go to their website and search for the complete step by step tutorials. Thus far, I have tried several projects, and for ...