Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
BeagleBone Black Cookbook
BeagleBone Black Cookbook

BeagleBone Black Cookbook: Over 60 recipes and solutions for inventors, makers, and budding engineers to create projects using the BeagleBone Black

eBook
$35.98 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

BeagleBone Black Cookbook

Chapter 2. Basic Programming Recipes

As the next step in learning how to control and manipulate your BeagleBone Black, we will take a look at the following languages, tools, and simple programming recipes in this chapter:

  • Introduction to BoneScript
  • Toggle LED
  • Using the Cloud9 IDE
  • Node.js basic recipes
  • Adding a new module to Node.js
  • Using Node.js with Johnny-Five
  • Python basic recipes
  • Adding libraries
  • Running a Python script to control the LEDs

Introduction

In the first chapter, our objective was to ensure that all you new chefs were ready with sharpened knives and the right combination of seasonings, or at least equipped with a basic working environment with happy, flashing blue LEDs on your BeagleBone Black and some command-line controls.

In later chapters, you will learn how to use other physical pieces of the system, including controlling the physical pins on the board. Before we get there, however, you will need to take a quick dip into a handful of recipes using programming languages that are typical and essential for building robust, compelling projects on BeagleBone Black. So, give a big round of applause to your soon-to-be faithful friends: BoneScript, Node.js, and Python.

Introduction to BoneScript

BoneScript is BBB's handy Node.js library. What is Node.js, you ask? Also, why bother with another library? We will talk more about Node.js in the next section. However, as far as another library goes, we're bothering with it because it's designed to work seamlessly with the hardware of your board, making physical computing development under embedded Linux faster and simpler. Using Arduino-like functions, BoneScript exploits the vast developer base of JavaScript.

Typically, your intention in using Node.js and BoneScript on BBB—just as it is with Python in the next section—is to gain access to the header pins, the General Purpose In/Out (GPIO) pins. Although we will discuss more about GPIOs in a later chapter, for now our plan is to briefly explore some fundamental methods to control the hardware.

Toggle LED

In this section, let's do a quick and easy recipe with BoneScript, one that turns on and off the on board LEDs, also known as USR LEDs. We will tackle more complex recipes with BoneScript in the next chapter.

How to do it...

In order to do this, perform the following steps:

  1. Remove all cables and power from your BBB.
  2. Power up your board via the mini USB using your desktop USB port.
  3. On the BEAGLEBONE_BLACK device that appears on your desktop, browse to and open the START.htm file (some versions of the OS may have a slightly different file name, such as BASIC_START.htm).

    Note

    Note that on Debian 8 (Jessie), your board will be labelled BEAGLEBONE on the desktop and not BEAGLEBONE_BLACK.

  4. Scroll down the page to BoneScript interactive guide, where you'll see an embedded script that you can run to interact with BBB.
  5. Click on Run.
  6. All the LEDs should stay on for two seconds. Let them return to blinking.
  7. Now change USR0 from b.HIGH to b.LOW.
  8. Change the timing from 2000 to 12000.
  9. You should...

Using the Cloud9 IDE

As the name implies, Cloud9 is a cloud-hosted toolkit. For BBB, it provides an integrated, open source development environment to build BoneScript-powered (JavaScript) code. Its strengths are JavaScript and Node.js (which it actually uses on the backend; we'll discuss this in the next section), though it is also very flexible with other programming languages such as PHP, Ruby, and Python.

The IDE comes preloaded and ready to use immediately on the BBB firmware with no setup necessary. With your board still connected via USB, let's do a snappy recipe.

How to do it…

  1. To load the IDE, open a browser window to the following URL: http://192.168.7.2:3000/ide.html. The IDE will open to a window like this:
    How to do it…
  2. Next, change the color settings to improve readability in the UI. The default black scheme is funereal; let's change it to Cloud9 Bright Theme instead.

    Note

    Not all UI screens change to the new color scheme; there's a temporary bug in this beta release...

Node.js basic recipes

JavaScript on the server; let that sink in for a moment….

What is Node.js? The quick and dirty answer is that it's a unique and very fast server environment to handle requests from client applications and apps that are authored in Javascript. It's Javascript on the server. More specifically, it's an I/O framework that:

  • Is event-driven
  • Is nonblocking
  • Runs on the V8 JavaScript engine
  • Executes JavaScript code on the server side
  • Is rich in robust developer libraries and modules

Node's speed makes it particularly useful in physical computing scenarios as it can handle requests in real time. After all, when a gust of sudden wind blows and your BBB-powered drone starts teetering midair, you don't want to rely on a poky LAMP stack and keep those gyros compensating.

The good news about Node.js—and we'll often just call it node—is that you don't have to install it because it comes preloaded on the BBB firmware. The bad news about...

Adding a new module to Node.js

Here is a recipe to add a new module into Node.js. In this case, we'll use Nodemailer, a powerful and highly customizable API e-mail engine. We chose this module because we wanted to actually have the script do something interesting and not just spit out another onscreen print command. At the end of this recipe, you will be able to run a script that sends an e-mail to your inbox.

Getting ready

Open up LXTerminal. Alternatively, open up the Cloud9 IDE in the manner described in the previous section.

How to do it...

Create a directory for your projects using the following command:

$ mkdir projects

Perform the following steps after creating a directory for your project:

  1. Browse to this new directory and make another emailer directory using the following command:
    $ cd projects
    $ mkdir emailer
    
  2. Now, go to the new directory with the following command:
    $ cd emailer
    
  3. Although it's not mandatory, the following command is the proper first step to setting up your node...

Introduction


In the first chapter, our objective was to ensure that all you new chefs were ready with sharpened knives and the right combination of seasonings, or at least equipped with a basic working environment with happy, flashing blue LEDs on your BeagleBone Black and some command-line controls.

In later chapters, you will learn how to use other physical pieces of the system, including controlling the physical pins on the board. Before we get there, however, you will need to take a quick dip into a handful of recipes using programming languages that are typical and essential for building robust, compelling projects on BeagleBone Black. So, give a big round of applause to your soon-to-be faithful friends: BoneScript, Node.js, and Python.

Introduction to BoneScript


BoneScript is BBB's handy Node.js library. What is Node.js, you ask? Also, why bother with another library? We will talk more about Node.js in the next section. However, as far as another library goes, we're bothering with it because it's designed to work seamlessly with the hardware of your board, making physical computing development under embedded Linux faster and simpler. Using Arduino-like functions, BoneScript exploits the vast developer base of JavaScript.

Typically, your intention in using Node.js and BoneScript on BBB—just as it is with Python in the next section—is to gain access to the header pins, the General Purpose In/Out (GPIO) pins. Although we will discuss more about GPIOs in a later chapter, for now our plan is to briefly explore some fundamental methods to control the hardware.

Toggle LED


In this section, let's do a quick and easy recipe with BoneScript, one that turns on and off the on board LEDs, also known as USR LEDs. We will tackle more complex recipes with BoneScript in the next chapter.

How to do it...

In order to do this, perform the following steps:

  1. Remove all cables and power from your BBB.

  2. Power up your board via the mini USB using your desktop USB port.

  3. On the BEAGLEBONE_BLACK device that appears on your desktop, browse to and open the START.htm file (some versions of the OS may have a slightly different file name, such as BASIC_START.htm).

    Note

    Note that on Debian 8 (Jessie), your board will be labelled BEAGLEBONE on the desktop and not BEAGLEBONE_BLACK.

  4. Scroll down the page to BoneScript interactive guide, where you'll see an embedded script that you can run to interact with BBB.

  5. Click on Run.

  6. All the LEDs should stay on for two seconds. Let them return to blinking.

  7. Now change USR0 from b.HIGH to b.LOW.

  8. Change the timing from 2000 to 12000.

  9. You should now see...

Using the Cloud9 IDE


As the name implies, Cloud9 is a cloud-hosted toolkit. For BBB, it provides an integrated, open source development environment to build BoneScript-powered (JavaScript) code. Its strengths are JavaScript and Node.js (which it actually uses on the backend; we'll discuss this in the next section), though it is also very flexible with other programming languages such as PHP, Ruby, and Python.

The IDE comes preloaded and ready to use immediately on the BBB firmware with no setup necessary. With your board still connected via USB, let's do a snappy recipe.

How to do it…

  1. To load the IDE, open a browser window to the following URL: http://192.168.7.2:3000/ide.html. The IDE will open to a window like this:

  2. Next, change the color settings to improve readability in the UI. The default black scheme is funereal; let's change it to Cloud9 Bright Theme instead.

    Note

    Not all UI screens change to the new color scheme; there's a temporary bug in this beta release of Cloud9's IDE.

  3. One handy feature...

Left arrow icon Right arrow icon

Key benefits

  • Learn how to develop applications with the BeagleBone Black and open source Linux software
  • Sharpen your expertise in making sophisticated electronic devices
  • Explore the BeagleBone Black with this easy-to-succeed recipe format

Description

There are many single-board controllers and computers such as Arduino, Udoo, or Raspberry Pi, which can be used to create electronic prototypes on circuit boards. However, when it comes to creating more advanced projects, BeagleBone Black provides a sophisticated alternative. Mastering the BeagleBone Black enables you to combine it with sensors and LEDs, add buttons, and marry it to a variety of add-on boards. You can transform this tiny device into the brain for an embedded application or an endless variety of electronic inventions and prototypes. With dozens of how-tos, this book kicks off with the basic steps for setting up and running the BeagleBone Black for the first time, from connecting the necessary hardware and using the command line with Linux commands to installing new software and controlling your system remotely. Following these recipes, more advanced examples take you through scripting, debugging, and working with software source files, eventually working with the Linux kernel. Subsequently, you will learn how to exploit the board's real-time functions. We will then discover exciting methods for using sound and video with the system before marching forward into an exploration of recipes for building Internet of Things projects. Finally, the book finishes with a dramatic arc upward into outer space, when you explore ways to build projects for tracking and monitoring satellites.

Who is this book for?

If you are a hardware, Linux, and/or microcomputing novice, or someone who wants more power and possibilities with product prototypes, electronic art projects, or embedded computing experiments, then this book is for you. It is for Internet of Things enthusiasts who want to use more sophisticated hardware than the Raspberry Pi or the Arduino can provide. Whether you are an engineering student, a DIYer, an inventor, or a budding electronics enthusiast, this book delivers accessible, easy-to-succeed instructions for using an advanced microcomputing platform.

What you will learn

  • Set up and run the BeagleBone Black for the first time
  • Learn the basics of microcomputing and Linux using the command line and easy kernel mods
  • Make introductory projects with Python, JavaScript, BoneScript, and Node.js
  • Explore physical computing and simple circuits using buttons, LEDs, sensors, and motors
  • Discover the unique features of the BeagleBone Black and its real-time computing functions
  • Build intermediate level audio and video applications
  • Assemble and add ingredients for creating Internet of Things prototypes

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 18, 2015
Length: 346 pages
Edition : 1st
Language : English
ISBN-13 : 9781783982936
Category :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 18, 2015
Length: 346 pages
Edition : 1st
Language : English
ISBN-13 : 9781783982936
Category :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 130.97
Mastering Beaglebone Robotics
$48.99
Learning BeagleBone
$32.99
BeagleBone Black Cookbook
$48.99
Total $ 130.97 Stars icon

Table of Contents

10 Chapters
1. Setting Up for the First Time Chevron down icon Chevron up icon
2. Basic Programming Recipes Chevron down icon Chevron up icon
3. Physical Computing Recipes Using JavaScript, the BoneScript Library, and Python Chevron down icon Chevron up icon
4. Exploring GNU/Linux Recipes Using Bash, Autotools, Debugger, and systemd Chevron down icon Chevron up icon
5. Basic Programming Recipes with the Linux Kernel Chevron down icon Chevron up icon
6. Run Faster, Run Real Time Chevron down icon Chevron up icon
7. Applied Recipes – Sound, Picture, and Video Chevron down icon Chevron up icon
8. The Internet of Things Chevron down icon Chevron up icon
9. The Black in Outer Space Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(2 Ratings)
5 star 50%
4 star 0%
3 star 0%
2 star 0%
1 star 50%
Matthew Lucero Apr 24, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book to have on your shelf or Kindle... It is an easy read and contains great information regarding the Beaglebone Black
Amazon Verified review Amazon
Engineer Dec 01, 2020
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
The description of this item did not state that the information is pre-2015. The Debian LINUX OS for the BeagleBone Black is completely different and that makes this book a complete waste of money. I do not recommend this book at all! The recipes and solutions are very simplistic and most no longer work on the platform because the referenced items no longer exist.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.