Introduction to Bonescript and the Cloud9 IDE

beaglebone black adc

When you browse a website, you are requesting the contents of the web page from or using the calculating capabilities of a server somewhere. That server is almost always a Linux machine and server-side scripts like PHP, Python, and Node.Js are used to “talk” to these servers.

The Beaglebone Black also acts as a “local” server with an IP address of 192.168.7.2. We can also use PHP, Python, etc to communicate with it and use its features. In this tutorial, we will be using Node.Js as a server-side script, particularly a library called “Bonescript”.

The Cloud9 IDE

The Beaglebone Black comes with an IDE called Cloud9 where we can create applications using Bonescript. Cloud9 is not exclusive to the BBB, in fact, it was created as an online IDE that web developers can use.  Alternatively, we can create HTML pages, and add javascript invoking the Bonescript library but that would take some time. To access the Cloud9 IDE, open your web browser (Firefox or Chrome only) and go to 192.168.7.2:3000. Here’s what it looks like:

Cloud9 IDE

The Angstrom distribution includes several examples which can be viewed in the "demo" folder.  On the "Project Files" window, open the demo folder and choose blinkled.js. This is a script that blinks the USR3 LED and any LED connected to P8_13. Click the "run" button to execute this code. You can also click on the arrow button to choose the active file (if you have multiple files open). You can hit the "stop" button anytime, btw.

There is also a folder named "autorun". Scripts in this folder will continuously execute without the use of the "run" button.

If you are familiar with bash, you can also issue bash commands on the terminal on the bottom part.

Bonescript

The Bonescript is a node.js library for embedded Linux created by Jason Kridner. Here's a neat slideshow from beagleboard.org:


It is still incomplete according to the author but it has enough functions to be useful in creating a lot of applications. As of this writing, serial, i2c and math functions are already available:

  • serialOpen(port, options, [callback])
  • serialWrite(port, data, [callback])
  • i2cOpen(port, address, options, [callback])
  • i2cWriteByte(port, byte, [callback])
  • i2cReadByte(port, [callback])
  • sqrt(x)
  • randomSeed(x)
  • ... and many more

I will cover these functions on my coming tutorials. You can also check out the bonescript repository for updates.

Next up, we'll look at that LED blinking code.