Programming BeagleBone Black: Getting Started with JavaScript and BoneScript

[Code Download] [Errata] [DEBIAN]

The book Programming BeagleBone Black will get you started programming this excellent board using its ‘standard’ programming environment of BoneScript.

This book’s main focus is on learning to program the BeagleBone Black from the viewpoint of someone who is new to programming. It therefore starts with basic concepts, gradually building on the earlier material towards more advance topics. It does therefore need to be read more or less in order.
This book is organized into the following Chapters:
Chapter 1. Introduction and Setup. In this chapter we introduce the BeagleBone Black, look at what you can do with it, as well as setting it up so that we can connect to it from your main computer over a USB or network connection.

Chapter 2. A Linux Computer. The BeagleBone Black is capable of functioning as a tiny general purpose computer, using a keyboard, mouse and monitor. In this chapter, you will explore this aspect of the BeagleBone Black.

Chapter 3. JavaScript Basics. While you can program BeagleBone Black in many different languages, the standard and BeagleBoard recommended language is called BoneScript. This is an extension of JavaScript, and in this chapter we get started with JavaScript programming from the point of view of the novice programmer. You will also make a start on some simple code examples, including turning the LEDs built onto the BeagleBone Black on and off.

Chapter 4. JavaScript Functions and Timers. JavaScript is different from many of the languages that are used to program embedded electronics. It does not have a “delay” or “sleep” function. Instead it has a concept of “Timers”. In this chapter, you will also start to develop an example to flash Morse Code signals using the built-in LEDs.

Chapter 5. Arrays, Objects and Modules. We are now getting into more advanced topics and continue the Morse sending example, building it up to a general purpose translator that will flash as Morse code, any message we supply as text.

Chapter 6. BoneScript. This chapter concentrates on the BoneScript library itself. You will learn how to use it to control digital and analog outputs as well as reading values from analog and digital inputs.

Chapter 7. Harware Interfacing. Although this is a book primarily about programming, the basics of attaching electronics such as LEDs, switches, servos etc. are described, with just enough electronics theory to get your project going.

Chapter 8. Using Capes and Modules. This chapter is concerned with programming and using expansion capes and modules, including I2C and Serial modules, as well as motor controllers.

Chapter 9. Web Interfaces. The web serving capabilities of the BeagleBone Black provide a great way of making a web interface for your projects.

Chapters 10 and 11. These chapters bring together topics from throughout the book to provide end-to-end project examples. The first project is a web-controlled roving robot, and the second an email notifier that uses a 12V incandescent lamp to notify you of incoming emails.


Page 54. Step 4 of the example code installation. The second command is missing the option “-r”. It should be:

# cp -r “prog_bbb/Prog BBB”/ “ProgBBB”

Page 125. Figure 8-7. The module is missing from the image. The figure should look like this:

replacement F08_07



When this book was written, The BeagleBone Black was at revision B, which ships with Angstrom Linux. Very soon after publication, the BeagleBone Black revision C was announced that has Debian Linux pre-installed. While the basic principals of Linux are the same and much of the book is unaffected, especially in the basics of using Javascript, some things are a little different.

If you have a first printing of the book, you will find that some of the example code differs slightly from the text of the book. In particular, you might see lines of code like this:

var htmlPage = ‘Prog BBB/10_02_rover.html’; // Angstrom
// var htmlPage = ’10_02_rover.html’; // Debian
These two lines do the same thing, but one of the lines should always be commented out, by placing a // before it. In the example above the code is set for Angstrom. To change the code to work on Debian, then comment-out (disable) the first line and un-comment the second line like this.
// var htmlPage = ‘Prog BBB/10_02_rover.html’; // Angstrom
var htmlPage = ’10_02_rover.html’; // Debian
Don’t forget to save the file before you run it.