JavaScript with Hardware [Part Zero]: JavaScript & Nodebots

JavaScript with Hardware [Part Zero]: JavaScript & Nodebots © MIT

Part zero of a series showing how to use JavaScript with Hardware. In this part, Iain goes over JavaScript and what Nodebots are.

  • 1,861 views
  • 1 comment
  • 15 respects

Components and supplies

About this project

This is part one of a series of posts showing how to use JavaScript software and application with hardware and robotics. This will show what JavaScript is, how to use it with hardware, and using modern JavaScript to build an application to interact with hardware. Enjoy!

Before I started doing stuff with Arduino and Hardware, I was a Web Developer for around 4 years. I worked in applications and frameworks writing HTML, CSS, PHP, and over time, JavaScript. I started tinkering around the idea of doing stuff with electronics, but didn't know where to start.

Then, I noticed it's possible to program hardware with JavaScript! This was perfect as I knew quite a bit of JavaScript from making scripts on websites and using it on applications, so I saw it as a great starting point for writing hardware.

Now, I'm passing the knowledge on to you. In this series, I'll be covering what JavaScript and Nodebots are, what boards and components you need, how to make a simple Nodebot, using modern JavaScript, making an interface, a working web app, and more!

In this part, We'll be going over why using JavaScript with Hardware is useful, what Nodebots are, and what components and tools you need, especially if you're a beginner. Let's get started!

Why JavaScript for Hardware?

If you've ever worked in anything using C or C-like coding, or have done web development before using things like jQuery or plain JavaScript, this is a perfect gateway for getting into Hardware, IoT, and Robotics. JavaScript is very universal now, it's not limited to just the web. It can be used to build anything!

A great perk with JavaScript is being able to build Applications, Servers, Databases, and APIs, even more! This is made possible with Node.JS, JavaScript Runtime Software using Chrome's V8 engine. This allows JavaScript to be used on the computer's level, and can even be used in, yes! Hardware!

Now, I am aware some people will look at this and think "JavaScript? Really?" and may be a bit skeptical about coding in JavaScript. I don't blame you — JavaScript has a notorious history due to how complex plain JavaScript used to be for scripting. If you're new to JavaScript, it can be a lot to take in, but I find it's easier to dive into than ever before. There's also tools and helpers that should make it easier to get into!

One thing that gives JavaScript the edge in coding is it's a very dynamic scripting language, while C++ is a static language. C++ can have blocks when it has to take in events and data, while JavaScript is asynchronous and doesn't have such a block! Another bonus is JavaScript has a lot of built-in functions that can make complex coding very easy, right out of the box, and it's continuously improving!

One drawback when it comes to hardware, is that JavaScript needs to be interpreted in order to run it on microcontrollers like the Arduino, much like Python does. Below is an example of how JavaScript works when it comes to Arduino, using the Firmata protocol.

However, other boards, such as Raspberry Pi, Tessel, Beaglebone and others can run Node.js on their boards, so this is just a small stopgap. Not too shabby!

We'll mostly be looking at the Arduino for the series, but also show some stuff on the Raspberry Pi as well.

What are Nodebots?

'Nodebots' are robotics and hardware that uses Node.JS — these applications are built on JavaScript, and can be made with various JavaScript libraries and plugins to make robots controlled by Game Controllers, Weather Stations, Autonomous Robots, Thermostats, and much more!

To easily write Nodebots, in this series I'll be focusing on Johnny-Five — a JavaScript IoT, Hardware and Robotics framework built by Rick Waldron. It's a great framework to use for prototyping hardware, and can work on many different platforms, not just Arduino!

Johnny-Five has a strong and diverse API, and it doesn't stop there. The Nodebots community have built numerous plugins and libraries to extend the use of Johnny-Five beyond just the framework itself!

A huge benefit of Johnny-Five is how easy it is to write — it has some resemblance to jQuery. With jQuery, it makes it easier to target elements within HTML, check events, and utilise built in functions. Johnny-Five is similar, but for robots!

One last tidbit: if you need inspiration, ideas, and further reading on JavaScript with hardware and robotics, check out my awesome-nodebots Github repo — it's got useful links to examples, tutorials, libraries, plugins and much more!

Anyway, I think we've covered enough about what each of these things are, let's get started!

So, if you're new to this, you may be asking, "Well what components and boards do I need for this?" A very good question! I'm going to keep things simple for the beginners who may be reading this. I will be covering more advanced stuff later in the series, and use a Raspberry Pi, but even just using a basic Arduino and components kit is enough to follow this series. If you have more than just beginner components, that's cool!

The first thing I recommend is buying an Arduino Uno, especially if you're new to Electronics and Prototyping. The Uno is a great board for beginners and is perfect for prototyping.

Another thing I recommend is getting a small starter kit of components. The best thing to buy as a beginner is a kit with components such as male jumper wires, resistors, buttons, LEDs, potentiometers, and a breadboard. Oh, and be sure to have a USB cable that's compatible with the Arduino!

You can buy a budget kit from Adafruit Industries, which includes an Uno and some basic components! Alternatively, you can buy an Uno separately and buy starter kits from Elegoo or Kuman. Or you can buy bigger kits — the more components, the better! You can get a lot of mileage out of even the smallest kit!

Also, if you haven't already, download and install the Arduino IDE — we'll need this to install StandardFirmata.

As a side note, a basic knowledge of circuits, and Ohm's Law, will help you when putting these projects together.

Okay, that covers it for this part! Hopefully this has got you interested into getting into JavaScript coding for hardware, and has got you ready for what is to come! Trust me, it's going to be fun.

Next Time...

We'll be making a basic Nodebot using JavaScript! We'll also be covering Node and Yarn, setting up your first Nodebot project, and the different functions you can utilise with Johnny-Five!

Want to see the next part before anyone else?

If you become a Patron, you can access this content a few days before everybody else does! All you need to do is pledge a dollar, and you'll get to see new content before everyone else!

Alternatively, if you're willing to wait a few days later yet still want to donate, here's my PayPal! You can also follow me on Twitter, like my Facebook Page, or subscribe to my mailing list to get updates!

Comments

Similar projects you might like

Basic Arduino + JavaScript (Workshop)

by Alex Glow

  • 11,873 views
  • 1 comment
  • 27 respects

Add push notifications to your hardware

by Gustavo Gonnet

  • 29,550 views
  • 24 comments
  • 83 respects

Pushing Data to Google Docs

by Gustavo Gonnet

  • 25,116 views
  • 60 comments
  • 74 respects
Add projectSign up / Login