Johnny-Five – letting us code hardware in Node.js

In the past, when you thought of robotics projects, it meant writing in C or C++, usually through the Arduino IDE and APIs. However, as microcontrollers have gotten more powerful, they are capable of running other programming languages, even scripting languages, such as subsets of Python and JavaScript.

And, of course, with computer/microcontroller hybrids, such as the Raspberry Pi, you're able to run stock Node.js, allowing you to create even advanced robotics projects without having to deal with any low-level languages. There are quite a few benefits to being able to code robotics projects in Node.js:

  • Event-based systems: In the Arduino and C/C++ level of robotics programming, you will need to check the state of everything through each iteration of a loop, and act accordingly. This can create monolithic functions and code paths. With Node.js and Johnny-Five, we can use event emitters and systems, which fit in surprisingly well as they can read sensors and interact with peripherals in the real world, where things take time. This will help you to organize code in a way that reflects the asynchronous way the world works.
  • Garbage collection/automatic memory management: While Arduino and C++ handle most memory management for you, programming in microcontrollers that use C requires strict memory management. While you may need to bear the resource constraints of the Raspberry Pi in mind from time to time, it is much easier than the days of 20K SRAM.
  • Using a language you already know: Instead of trying to remember the way things work in a new language, it will accelerate your learning in the field of electronics and robotics if you focus on learning fewer things at once. Using Node.js can help you focus on learning the wide and varied world of electronics, instead of adding on the extra work of remembering whether it's uint8_t or uint16_t.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.4.206