NodeBots: JavaScript
Powered Robots with
Johnny-Five
Mark Alan West
SOURCE: WWW.NODEBOTS.IO
Why use Johnny-Five?
1. Maturity
2. Community
3. DSL
4. Portability
5. Open Source
6. JavaScript
7. Node.js ecosystem
8. REPL
var five = require("johnny-five");
var myBoard = new five.Board();
myBoard.on("ready", function() {
var myLed = new five.Led(13);
myLed.blink(500);
this.repl.inject({
replLed: myLed
});
});
Imports J5 Dependancy
Adds LED instance to REPL
Declares LED as connected to UNO Pin 13
Blinks LED every 500 milliseconds
Code block triggered by UNO ”Ready” Event
Initialises UNO
Johnny-Five Code Example
https://vimeo.com/134953425
Why use the Arduino UNO?
1. Price
2. Robustness
3. Flexibility
Drawback with the UNO:
Doesn’t run JavaScript
Laptop running Johnny-
Five
Arduino UNO
running Firmata
Serial Cable
Allowing Johnny-Five
to talk to Firmata
(WIFI & Bluetooth
also supported)
Actuators
(i.e. Servos,
Motors, LEDs)
BrainSensors
(i.e Button, Heat,
Motion)
Nervous System
Sensors Nervous System Brain Actuators
Demo Setup
“Dance”
Getting Started with NodeBots
1. Buy an Arduino Experimenters Kit.
2. Follow the tutorials at http://node-ardx.org.
3. Visit http://johnny-five.io for more
information and inspiration.
Thanks for listening!
mark.west@bouvet.no
@markawest

JavaZone 2015 : NodeBots - JavaScript Powered Robots with Johnny-Five

Editor's Notes

  • #2 Welcome to my Lightning Talk! In this talk I will give you a quick introduction to Johnny-Five and the world of NodeBots
  • #3 So what are NodeBots? Simply put, they are Robots powered the JavaScript and the Node,js platform!
  • #4 The NodeBots movement is a worldwide phenomenon, with meetup groups spread across the whole world. The community has many events, including an international NodeBots day in July.
  • #5 The most popular software solution for programming NodeBots is currently Johnny-Five. The name comes from the 80’s classic sci-fi comedy Short Circuit. In this film a military Robot called Johnny-Five gets struck by lightning and becomes self aware, with hilarious consequences.
  • #6 The reasons for Johnny-Five’s popularity in the NodeBots world are as follows: Maturity - Johnny-Five is stable and robust. Community - An active and helpful community led by Rick Waldron. DSL - Easy to learn, consistent DSL which reflects real world objects such as LED and Motor (along with their actions). It is also much easier to learn and requires less boilerplate than say the Arduino Language. Portability - Johnny-Five is supporting more and more platforms - such as the Arduino, Raspberry PI, Tessel 2 and Spark Core. You can reuse your code even if you upgrade your robots hardware. Open Source - is Johnny-Five missing a feature? Go ahead and add it! Feel free to delve into the code! JavaScript - Its’s a great chance to reuse your JavaScript knowledge (or even get started with learning JavaScript). Node.js ecosystem - Want to control your robot with a Keyboard? Over MQTT? With Voice Commands? Node has over 160000 modules that cater for everything and these can be easily installed though the Node Package Manager, or NPM. REPL – The REPL allows you to change the state of running code from the command line. This makes it very easy to play with and learn the DSL.
  • #7 So lets have a quick look at the Johnny-Five code for making an LED blink on and off. The code here does the following: Imports the Johnny-Five dependency. Initialises the Board. On a successful initialisation event sets up the LED as connected to pin 13 and blinks it. I’ve also added the LED to the Node.js REPL so I can write commands directly.
  • #8 In this video I am running the code you’ve just seen. As you can see the LED is blinking every 500 milliseconds. I then go to the command line and use LED reference to stop the LED blinking and then switch it on and off – all from the command line. This REPL is a great way of becoming familiar with the Johnny-Five DSL, as well as allowing you to mess about with actuators connected to the UNO.
  • #9 When working with Johnny-Five I prefer to use the Arduino UNO for conecting to the various physical components, due to it’s following strengths: (a) Price - The UNO is very cheap at around 200kr. Copies available from Ebay are closer to 100kr. (b) Robustness - The UNO is resistant to damage from mishandling, faulty wiring, short circuits and so on. (c) Flexibility - The UNO supports a range of Digital and Analog inputs and outputs out of the box. You could also use the Raspberry PI, but it is no where near as robust and doesn’t support analog inputs and output out of the box.
  • #10 How do Johnny-Five and the UNO work together? Well the Arduino UNO doesn’t understand JavaScript. Therefore Johnny-Five runs on a PC, which then sends commands to a tethered Arduino UNO. The connection between the UNO and the Host can be a Serial Cable, or even a WIFI or BlueTooth connection. The UNO is running a program called Standard Firmata which provides an API for Johnny-Five to communicate with. In this example the PC can be swopped out with anything able to run Node.js (including a Raspberry PI).
  • #11 Confused? Well a Robot should have the following four types of components: Sensors for receiving stimuli. For example detecting visual or auditory events. Actuators for interacting with the physical world. For example legs that move the robot away from danger. A Brain for interpreting stimuli from the sensors and triggering relevant responses in the actuators. A Nervous System for relaying messages between the brain, sensors and actuators. In this diagram I have specifed the UNO as the Nervous System and a PC running Johnny-Five, but you could use a Raspberry PI for the Brain, or even for both the brain and the Nervous System. But try to remember that the PI is less robust and flexible than the UNO. There does exist other platforms that combine the best of both the UNO and PI, such as the Tessel 2, but I haven’t yet tried this out.
  • #12 Ok it’s time for a live demo of a real NodeBot in action. Keep your fingers crossed!
  • #15 Ok so if you are interested in playing around with NodeBots, or any type of robotics, then I would encourage you to start buying an Arduino Experiementers Kit. These cost from 300-400kr up to over 1000kr. I would shop around and buy a kit with the most possible sensors and actuators. Once you’ve got your hands on a kit then I’d visit the node-ardx website and run through the tutorials there. These will get you started with J5 and will also get your started with building electronic circuits. A lot of fun! And finally you should take a peek at the J5 webite for more information and inspiration.
  • #16 Thanks for listening! Come and have a chat if you’d like to talk more about NodeBots or any kind of Robotics – you can also contact me on Twitter!