1 2 3 Previous Next

BeagleBone Black

69 posts

I have been working on an idea for my project. I am using my BBB to get the weather forecast and to let me know if I need to take an umbrella when I go out. (To be honest I don't use an umbrella but this is is for a "proof of concept" idea).

 

I am using python here to collect the forecast from Weather Underground, the api page is very helpful, and when I have the forecast as a json document I can extract the data I am looking for and do stuff with it. Currently I am displaying the weather forecast form my local area for the day that the program is being run and the next day. I have coded the place that I want the weather for into the string that makes up the URL, as my project is going to be setup per user I think that this is OK. See code below:

 

# program to grab the weather forecast from weather underground
# author Mark Venn
# based on code from "Getting Started with Raspberry Pi"
# currently collects the forecast for current day and next day. Lights an LED if the chances of rain are over 60%

# imports
import requests
import Adafruit_BBIO.GPIO as GPIO
import time

# configure GPIO pins
GPIO.setup("P8_8",GPIO.OUT)

GPIO.output("P8_8",GPIO.LOW)

# wunderground api key

key = 'xxxxxxxxxxxxxxxx'

# build string using hard coded web address & api key variable
ApiUrl = 'http://api.wunderground.com/api/' + key + '/geolookup/forecast/q/UK/Bembridge.json'

while True:

    # get the weather forecast from wunderground and store in variable
    r = requests.get(ApiUrl)

    # take response and parse it into python dictionary object
    forecast = r.json

    # extract relevant data.
    # use variable to collect day of the week
    day = forecast['forecast']['txt_forecast']['forecastday'][0]['title']
    # display next day
    nextDay = forecast['forecast']['txt_forecast']['forecastday'][2]['title']

    # chance of rain
    rain = forecast['forecast']['txt_forecast']['forecastday'][0]['pop']
    rain = int(rain)

    # display current day
    print day

    #directly display the required info
    print forecast['forecast']['txt_forecast']['forecastday'][0]['fcttext']


    print nextDay
    # TEST CODE
    # print rain

    #directly display the required info
    print forecast['forecast']['txt_forecast']['forecastday'][2]['fcttext']

    if rain >= 60:
        GPIO.output("P8_8",GPIO.HIGH)
    else:
        GPIO.output("P8_8",GPIO.LOW)

    time.sleep(180)


# TEST CODE #
# prints entire json document
#print forecast

The data I need for the forecast is held in fcttext in 2 key / value pairs and this is displayed.

root@beaglebone:~# python text_forecast_v3.py

Monday

Mostly cloudy. Lows overnight in the low 40s.

Tuesday

Cloudy and becoming windy. Periods of light rain early. Turning colder. High 46F. Winds N at 20 to 30 mph. Chance of rain 40%.

Monday

Mostly cloudy. Lows overnight in the low 40s.

Tuesday

Cloudy and becoming windy. Periods of light rain early. Turning colder. High 46F. Winds N at 20 to 30 mph. Chance of rain 40%.

Monday

Cloudy. Lows overnight in the low 40s.

Tuesday

Light rain early. Then becoming windy in the afternoon. Turning colder. High 47F. Winds N at 20 to 30 mph. Chance of rain 40%.

 

I am displaying this in the console at the moment, I might use some kind of GUI at a later date; my son odion is often telling me that I should put stuff into GUIs but A console is good enough for me for now

The code to get the forecast could be run on any machine that can run python 2.7 but now we come to the reason for running this on the BBB. There is a single LED connected to P8-8 and when the value of the precipitation chance in percentage is over  60% this LED lights up. The whole check is done every 3 minutes at the moment but I will be playing with the timings later. It is likely that I can get away with every 6 hours or so but I will see.

text_forecast_v3.py_bb.jpg

I have taken the idea for this from the "Getting Started with Raspberry Pi" book and made a few changes as well as converting it to the BBB; I will probably set this up on the Pi next and see if there are any differences in the way it works.

The Weather Underground api looks very wide ranging and I will see what else I can get out of it, I think that as we in the UK head into winter something that pulls the expected maximum and minimum temperatures will be useful. I have found where this info is held in the json document:

"period":1,

"high": {

"fahrenheit":"48",

"celsius":"8"

},

"low": {

"fahrenheit":"41",

"celsius":"5"

}

Will have to play around with this info and see how I can make use of it.

 

I will be using my BB_VIEW display to see how I can display the info, not sure what or how yet, this will be in another blog. I am going to be writing about my experiences with my new Pi B+ so check out my blogs on there.

Bye for now, off to check if my LED is alight yet!

 

Beaglebone Black

BB View 4_3 LCD Display

bbb-web-gpio-banner.jpg

 

In my last tutorial I covered the installation of Drupal onto the BeagleBone Black and how to setup an Apache-based web server. In this tutorial, I am going to continue building on that foundation and cover the basics of using that Drupal-based website to control the GPIO pins on the BeagleBone Black using PHP to run bash scripts. This will, in turn, allow you to use the internet to control anything that is connected to the BeagleBone Black's GPIO pins, and will further the foundation for some basic home automation tutorials I will write in the coming months.

 

Prerequisites: What you need to know to be able to complete this project.

  • Understand how Drupal-based websites work.
  • Understand how PHP can be used to parse commands to the web server's terminal.
  • Understand how LEDs work, and what the terms Anode and Cathode mean.
  • Understand the basics of how Transistors work, and why they should be used for applications like this.
  • Understand how the BeagleBone Black accesses its GPIO Pins.
  • Basic knowledge of soldering.

 

Hardware Required: What hardware is needed to complete this project.

  • BeagleBone Black (Rev C recommended) BeagleBone Black (Rev C recommended) running the latest Debian image.
  • 5mm Green LED
  • 1x 460Ω 1/4w Resistor
  • 1x 3.3kΩ 1/4w Resistors
  • 1x 100Ω 1/4w Resistors
  • 1x 2n3904 General Purpose NPN Transistors
  • Female to Male Jumper Wires
  • Male to Male Jumper Wires
  • 5V Power Source for BeagleBone Black
  • 5V Power Source for BeagleBone Black (Optional without BB View cape, Required if BB View Cape is used.)
  • Solder
  • Flux
  • Soldering Iron

 

Getting started: Soldering the resistor to the LED



For the purpose of this tutorial we are going to use an LED to indicate when a specific GPIO pin has been toggled on and off. As I am sure many of you reading this already know, Light Emitting Diodes (or LEDs) are one of the most revolutionary electronic components to have ever been created. In fact, this year's Nobel Prize in Physics was awarded to the team of scientists who created the efficient blue LED, which has revolutionized the way humans light the world. Since LEDs are so efficient, and sip very little power, the 3.3v coming out of the BeagleBone Black's GPIO pins would fry the LED if we tried to connect it without a current limiting resistor. While this is old-hat stuff for most of you, there will be some readers who will find this section interesting and helpful, and that is why I am including it. Below is a diagram that shows exactly what makes up your typical 5mm LED.

 

led-anatomy.jpg

Since the LED is a diode, electricity will only flow one direction. This is why a LED is polarized, unlike a resistor that works in any orientation. In the diagram above, you will notice that the Anode (+ side) is the smaller element inside the LED, and that the Cathode is actually the leg that houses the crystal that emits the light. Another way to tell the Anode from the Cathode is that the Anode will usually be longer than the Cathode. Finally, the Cathode is usually closest to the flat spot on the LED's base ring.

 

Placing the resistor on the Anode or Cathode will work, but I prefer to place it on the Cathode. This is just personal preference, but I find it to be considered best practice in several textbooks and guides. There is also no set standard for attaching a resistor directly to the leg of the LED, but I generally tend to go for the "wrap it around neatly" method. I also like to trim the Cathode down so that the resistor's lead matches up with the Anode leg length. For breadboard work I like to build easily reusable LED modules that include the resistor and are soldered to a 2-pin male header.

 

LED-Breadboard.jpg

 

With that finished, we can now move on to setting up the transistor circuit on a breadboard. The transistor circuit is needed because the BeagleBone Black is only able to supply about 8mAh to each of its GPIO pins and connecting something that draws more than 8mAh can damage the board's ARM chip. We can turn on a general-use PNP transistor with just a few mAh which will let us power the LED externally, and prevent any damage to the board. This is also handy for controlling relays and other components that can be triggered via the GPIO pins.

 

bbb_breadboard_led.jpg

 

Here is a quick diagram of how I wired up the transistor circuit and attached the LED.

 

Breadboard_actual.jpg

 

You will notice that I have a 9Volt battery powering the LED via the transistor. You do not have to use a 9V battery, and anything above 5V will work, but I would not use a power supply over 12v for this application.


bbb_circuit_breadboard.jpg

 

With the Transistor Circuit wired up, lets connect the BeagleBone Black. Basically we simply need to connect one of the GPIO Pins to the Transistor, and carry over the BeagleBone Black's ground circuit to our bread board. With all of this connected, we can now test the LED using the BeagleBone Black's terminal.

 

Testing The Circuit: Using the terminal to trigger the GPIO Pin.

 

To test the circuit we need to access our BeagleBone Black via SSH. I covered how to do this in the BeagleBone Black RSS News Reader tutorial, but will post it here as well.

 

To access the BeagleBone Black via SSH I will be using a terminal for Windows called Putty, as well as an add-on called MTPutty, which allows me to run multiple putty instances from within a single tabbed interface. Both Putty and MTPutty are available for free, and take just a few moments to download and install. Chances are, if you are reading this, you already know how to use Putty. If you are using a Mac you can simply use the built-in Terminal to access your Black Via SSH. To connect to your Black, you need to enter the following credentials.


Putty-Config.jpg

With these settings configured, click ok and then double click the BeagleBone Black name in the server list. This will open up a new terminal tab and you will be prompted to enter a username. Unless you have modified the root user, you should enter root as the user name.

 

Putty-connect-2.jpg

 

BeagleBone has made it easy here as there is no password and after entering the username, the connection will finish, and you will be placed in your "home" directory.

Putty-connect-3.jpg

 

Now that you are SSHed into the BeagleBone Black we will need to prepare GPIO 67 (P8:08). The pinout diagram can be seen below.

 

bbb-pinout.jpg

 

Before we get started with testing, lets take a moment and talk about how the BeagleBone Black's GPIO pins are addressed by the Linux-based Debian operating system. The BeagleBone Black addresses its GPIO Pins by reading the contents of files which are located in the sys/class/gpio directory in the board's operating system. The most basic functionality is to write the pin high or low, and is what we will be doing in this tutorial.

 

To use a GPIO Pin you first need to tell Debian that you are going to use a particular pin in a specific GPIO header. The following code uses GPIO 8.8 as an example, but any GPIO Pin can be accessed by creating these files. Enter the following commands into the BeagleBone Black's terminal.

 

The first thing we need to do is create a new directory called gpio67 in the /sys/class/gpio/sys/class/gpio directory.

echo 67 > /sys/class/gpio/export







































































































 

At this point you will need to let the BeagleBone Black know whether or not the specified GPIO pin is input or output.

echo out > /sys/class/gpio/gpio67/direction







































































































 

With this command, the BeagleBone Black no longer supplies 2.3V to the header and it is considered to be turned off. In order for us to turn on GPIO Pin 67 we need to set its value to 1. To turn it back off again, the value needs to be 0. We can do that with the following commands.

 

Set the GPIO Pin High

echo 1 > /sys/class/gpio/gpio67/value







































































































 

Set the GPIO Pin Low

echo 0 > /sys/class/gpio/gpio67/value







































































































 

Remove control of the GPIO Pin when finished.

echo 67 > /sys/class/gpio/unexport







































































































 

With those basics out of our way, let's move on to testing. Since we already have GPIO Pin 67 setup, and the rest of the circuit above is in order, we just need to give our breadboard power via a 9-volt battery. Connect the 9-volt to the breadboard as shown in the image below.

 

9-volt-power.jpg

 

With everything connected, we should be able to use the command line to set GPIO Pin 67 high, which should in turn activate the transistor and allow the LED to light up.

Set the GPIO Pin High

echo 1 > /sys/class/gpio/gpio67/value

































































































 

If everything was followed correctly, you will see the LED light up

 

LED-Illuminated.jpg

 

Now set the GPIO Pin to low to turn off the circuit.

Set the GPIO Pin Low

echo 0 > /sys/class/gpio/gpio67/value
































































































 

Configuring The Website: Using the internet to control the GPIO Pin.


If you have been following along in my BeagleBone Black series you will recall that my last tutorial demonstrated how to install an apache-based web server on the BeagleBone Black, and how to install and configure a Drupal-based website on top of that web server. For this next part, you will need to follow the steps in that tutorial and get a Drupal 7 website up and running on your BeagleBone Black before continuing with this tutorial.

 

Pull up the previously created website, and login as the administrator by visiting the (my_website_url)/user.

 

There are a few different ways that we can build functionality into our website to control the GPIO pins on the BeagleBone Black. Note that the following methods only work when the website is hosted on the BeagleBone Black. We are going to begin with the two simplest methods. Method one will create two separate pages that run a php script when visited, while method two creates toggle buttons within a single page or block. While these methods work, they are highly vulnerable to security breaches, and should only be used on sites that are not directly open to the public.

 

 

Method One: Controlling the GPIO via separate web pages.

 

Since the BeagleBone Black GPIO Pins are accessible using the command line, we can write a simple PHP script that turns any of the pins on and off using the commands listed above. First, we need to turn on the PHP filter in Drupal. (Note that turning this filter on in Drupal exposes your website to security vulnerabilities, and as such it should only be done on sites not publicly available) Navigate to (my_website_url)/admin/modules/ and scroll down until you see the PHP Filter module under the Core heading. Enable this module by ticking the box to the left, then scroll to the bottom of the page and click save.

 

phpfilter.jpg

Creating the LED On Page

 

With the PHP filter enabled create a new basic page by navigating to (my_website_url)/node/add/page. Fill out the page with the following information, or watch the video embedded below and follow along.

  • Title: LED ON
  • Body:
    • <?php
      exec("/bin/echo \"1\" > /sys/class/gpio/gpio67/value");
      ?>
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
  • Text Format: PHP Code
  • Menu Settings:  Tick the box for Provide Menu Link
    • Menu Link Title: LED On
    • Parent Item: <Main Menu>
    • Weight: 1
  • Publishing Options:  Tick the box for "Published" and make sure the other two options are not checked.

 

Now click the "Save" button at the bottom of the page. If everything was entered correctly, you can return to the home page and there will be a new main menu link called "LED On."

LED ON Menu.jpg

 

Creating the LED Off Page

Now we need to create a web page that turns the LED off. Create a new basic page by navigating to (my_website_url)/node/add/page. Fill out the page with the following information, or watch the video embedded below and follow along.

  • Title: LED Off
  • Body:
    • <?php
      exec("/bin/echo \"0\" > /sys/class/gpio/gpio67/value");
      ?>
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
  • Text Format: PHP Code
  • Menu Settings:  Tick the box for Provide Menu Link
    • Menu Link Title: LED Off
    • Parent Item: <Main Menu>
    • Weight: 2
  • Publishing Options:  Tick the box for "Published" and make sure the other two options are not checked.

 

Now click the "Save" button at the bottom of the page. If everything was entered correctly, you can return to the home page and there will be a new main menu link called "LED Off."

LED Off Menu.jpg

Setting Permissions

With both control pages created, we need to modify the permissions on the gpio67/value directory so that the www-data user (Apache) can write to it. Run the following command from within the terminal.

chmod 666 /sys/class/gpio/gpio67/value






















































 

With this done, we are able to test that everything works. With the transistor's base pin connected to GPIO67 and the 9-volt battery powering the breadboard, you should be able to click on the LED On menu link and the LED will turn on. Clicking the LED Off Menu Link will turn the LED Off. If your LED is not turning on and off, revisit the steps above. Alternatively, you can watch the video below and follow along.

 

 

Method Two: Controlling the GPIO via toggle buttons on a single page or block.


While turning the LED on and off with separate web pages works, it is not the most efficient or best way to do things. This method could come in handy if you wanted to trigger a GPIO event whenever someone visits a webpage, but for general user triggered On and Off use, buttons would be a far better method. To trigger the GPIO pins via web buttons, we will utilize some existing code that I found during a quick search. This PHP code creates two basic buttons that fire off php scripts when pressed. You can view the original code at http://www.berriman.co.uk/beaglebone-black-bbb-simple-web-io/.

 

To make the code work we will need to modify two lines to point to the specific GPIO pin we are using to turn our LED circuit on and off. I have pasted the code you will need to use in the Page Building section below.

 

Creating the LED On / Off Toggle Button Page

Now we need to create a web page that turns the LED off. Create a new basic page by navigating to (my_website_url)/node/add/page. Fill out the page with the following information.

  • Title: LED On and Off Buttons
  • Body:
  • Text Format: PHP Code
  • Menu Settings:  Tick the box for Provide Menu Link
    • Menu Link Title: LED On and Off Toggle Buttons
    • Parent Item: <Main Menu>
    • Weight: 3
  • Publishing Options:  Tick the box for "Published" and make sure the other two options are not checked.

 

Now click the "Save" button at the bottom of the page. If everything was entered correctly, you can return to the home page and there will be a new main menu link called "LED On and Off Toggle Buttons." Click on that page and click the LED On button and then the LED Off Button. The LED should illuminate and then turn off. If this is correct, we can move on, otherwise revisit the steps above.

 

LED bittons.jpg

 

Creating the LED On / Off Toggle Button Block

Create a new block by navigating to (my_website_url)/admin/structure/block/add. Fill out the block with the following information, or watch the video embedded below and follow along.

  • Title: Access LED
  • Block Description: GPIO67 LED Buttons
  • Body:
  • Text Format: PHP Code
  • Region Settings:
    • Bartic (Default Theme)
      • Sidebar First

Now click save block. You can change the weight of this block by visiting the Block Administration page, and navigating to  (my_website_url)/admin/structure/block. Now you will see the LED Toggle buttons when visiting any page on the website. The beauty of this block / button method is that you can now place your GPIO buttons anywhere on the website, and not have to display them as a page.

 

button block.jpg

 

There are many ways to do this that are specific to Drupal, but the PHP code used in this last example will work on any web framework, and can be used independently as well. One of the safer ways to execute this code would be to set up a rule and use a flag to control when each script is run. That is more advanced Drupal development work than I want to get into in this tutorial, but I would be glad to write a separate tutorial on it if there is enough interest. For the advanced Drupal developers out there, you can head over to my Github and download a feature module with this functionality built in. You will still have to create the node, and install some modules though.  In the mean time, I urge everyone to play around with modifying this code, and making some awesome stuff.

 

 

My next tutorial will involve modifying this code to trigger a set of relays, and notification LEDs that can be used to control anything from a basic lamp to a more full featured home automation system.

Banner.jpg

 

When the BeagleBone BlackBeagleBone Black was first released, I was one of the first journalist in the country to receive one, and impressed did not begin to describe how I felt about the little black board. At the time, I was still riding a high from my experiences with the Raspberry Pi, and while the Black lacked the camera and LCD connectors, it made up for it in on-board flash and processing power. Unfortunately I was very disappointed in the Angstrom Linux distro that shipped with the Black, but did manage to flash the board to Ubuntu with the help of a friend at my local MakerSpace. Over the next several months, I played with the Black here and there, and made a few small projects here and there. When revision C of the BeagleBone Black came out running Debian from the factory, I knew I had to have one. It was also around this time that I made a major career change, and left tech journalism for a more lucrative position as a Drupal developer at a friends web development firm. While playing around with my new BeagleBone Black one night, I began wondering how hard it would be to get a web server up and running and if the Black would be able to handle MySQL and Apache2 along with a Drupal Install.

 

Prerequisites: What you need to know to be able to complete this project.

  • Understand how to install packages from the terminal.
  • Understand how a LAMP-based web server works.
  • Understand how Drupal is installed and configured.
  • Understand how RSS feeds work.
  • Understand basic HTML and XHTML.

 

SSHing into the BeagleBone Black via Putty

 

To access the BeagleBone Black via SSH I will be using a terminal for Windows called putty, as well as an addon called MTPutty which allows me to run multiple putty instances from within a single tabbed interface. Both Putty and MTPutty are available for free, and take just a few moments to download and install. Chances are, if you are reading this, you already know how to use Putty. If you are using a Mac you can simply use the built-in terminal to access your Black Via SSH. To connect to your Black, you need to enter the following credentials.


Putty-Config.jpg

With these settings configured, click ok and then double click the BeagleBone Black name in the server list. This will open up a new terminal tab and you will be prompted to enter a username. Unless you have modified the root user, you should enter root as the user name.

 

Putty-connect-2.jpg

 

BeagleBone has made it easy here as there is no password and after entering the username, the connection will finish, and you will be placed in your "home" directory.

Putty-connect-3.jpg


To get things started, I first needed to get MySQL installed and running on the BeagleBone Black, and I will be perfectly honest in saying that it was no easy task starting off. Since revision C of the Black runs Debian Wheezy from the factory, I knew that apt-get install would be used to install new packages now where as opkg was used with the Angstrom distro on earlier models. Unfortunately that is where I began running into problems. When I would run anything via apt-get install the whole install process would run, but then quickly error out due to a script called led_aging.sh causing an error. After almost an hour of pulling my hair out, and searching the web, I found a thread in a mail archive where someone was having the same problem. As it turns out the script was missing some of its functions, and that was causing the dkpg error, but why a seemingly random script was causing apt-get install to fail is beyond my pay-grade. If you are interested in seeing the original mail archive with the information, it can be found here. I am going to cover this fix below for convenience though.


If you get an error surrounding the led_aging.sh script when running apt-get install on your BeagleBone Black, or during any terminal process, you will need to modify that script to include some missing functions. The process to do this is found below, but you will need a basic understanding of the Linux file structure and how to modify files via the terminal to complete this. You can also check out this code on github.

 

  • From your home directory navigate to /etc/init.d and then nano the led_aging.sh file that is inside the init.d directory.
  • Replace all of the code inside the led_aging.sh file with the following code.
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: led_aging.sh
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start LED aging
# Description: Starts LED aging (whatever that is)
### END INIT INFO

x=$(/bin/ps -ef | /bin/grep "[l]ed_acc")
if [ ! -n "$x" -a -x /usr/bin/led_acc ]; then
  /usr/bin/led_acc &
fi


























































































 

  • Then exit out of nano, keeping the filename the same as it was.

 

This should have fixed the issue that pops up when trying to run an apt-get install command. Now that we have that error taken care of, lets move on to the rest of the project.

 

Installing and Configuring the Web Server

 

There are a few packages we need to install in order to get our web server up and running to be able to serve a Drupal installation. The packages we need to install are listed below.

  • MySQL Server
  • MySQL Client
  • Apache2

 

Before we get started, we need to make sure that Debian is up to date with the latest libraries, and doing that is as simple as running the following command.

 

apt-get update


























































































 

This will automatically download and install the latest update for the version of Debian that is running on the BeagleBone Black.

 

With the distro updated, we can now install MySQL Server and MySQL Client with a single command. For those of you following along at home, MySQL is the database of choice for Drupal installations, but you could run MariaDB, postgresql, or another variant of MySQL. To keep things simple and standardized, we will be running MySQL. To install both packages, use the command below.

apt-get install mysql-server mysql-client


























































































 

This will run through the install process. You will be prompted with some password creation prompts and you can set the passwords to whatever you wish, but make sure to write them down as they will be needed later.

 

With MySQL installed, its time to install Apache2 run the following command

apt-get install apache2

























































































 

Let the install process finish, and grab something to drink in the meantime. When the install finishes, install the following packages.

apt-get install php5
apt-get install php5-mysql
apt-get install php5-gd
apt-get install libapache2-mod-php5 
apt-get install php5-curl

 

With those packages installed, we can move on to building a Drupal-based website on the BeagleBone Black.

 

Installing and Configuring a Drupal-based Website

 

In the terminal, navigate to the srv/www directory, and create the directory in which we will install the Drupal instance too. We will need to create several sub-directories as well, including backup and error log directories as well as the website doc root.

cd /srv/www
mkdir bbb.news
cd /srv/www/bbb.news























































































 

Now create the sub directories using the commands located below

mkdir backup
mkdir download
mkdir logs























































































 

While only two of these directories are really needed, I prefer to follow what I consider to be best practice when installing drupal on any server. The backup directory is used to backup the website's database, making life much easier when things go bad. We will use the download directory to download the Drupal install tarball to. The logs directory will house two required error log files, and the htdocs directory will be where our website resides.

 

While we are at this level of the file structure, lets go ahead and create two files that apache will need later. Navigate to the logs directory and enter the two touch commands below.

cd logs
touch access.log
touch error.log























































































 

This creates the needed log files that will help troubleshoot issues if they occur.

 

With these files created we can navigate back to the main bbb.news directory and then into the download directory.

cd ../download























































































 

Once inside the download directory, we can use the wget feature to grab a fresh copy of the latest version of Drupal 7. While Drupal 8 is right around the corner, I chose to go with Drupal 7 because it is the most widely adopted version at the moment and has the most module support currently. Follow the commands below to download Drupal and untar it into the htdocs directory.

wget http://ftp.drupal.org/files/projects/drupal-7.32.tar.gz
tar -zxvf drupal-7.32.tar.gz
mv drupal-7.32 ../
mv drupal-7.32 htdocs

 

Now verify that the files were successfully extracted to the htdocs directory by entering the following commands and matching up your directory with the screenshot below.

cd ../htdocs
ls























































































 

drupal-root1.jpg
If the extraction was successful, you should see something similar to this.

 

Now we need to navigate to the sites/default directory and copy the default.settings.php file and rename it to settings.php, then set the permissions on the settings.php file to 777.

cd sites/default
cp default.settings.php settings.php
chmod 777 settings.php















































































 

To finish getting our Drupal site ready we need to build a database for it to store things in. You will need the MySQL username and password that you set up earlier in the tutorial for this. Use the following commands (with your unique credentials) to build the database we will use for the Drupal installation.

mysql -u (username) -p (password)














































































 

That should drop you into the MySQL terminal and from here you can create the database with the following commands.

create database (database_name);
grant all on (database_name).* to '(database_username)' identified by '(database_password)';














































































 

If everything was entered correctly, then you should see a line returned with the following command Query OK, 0 rows affected (0.00 sec) .  Be sure to write down the database name, database user name, and database password as you will need them shortly. If things are correct, you can now exit the MySQL terminal using the following command.

exit









































































 

Now lets set up the vhost file for our newly installed website. Navigate to the apache2/sites-available directory using the following command.

cd /etc/apache2/sites-available









































































 

Now we need to create a new virtual host file (vhost) for our newly installed drupal website. To do this, we are simply going to use the touch command to create the file. If you want to be able to access the website you are building from an external network, you will need to configure a new A-record on a domain name that you own, and point it to your home's IP address, then forward the ports in your router to the BBB for that domain name. I wont cover those aspects in this tutorial, but the internet is full of valuable resources that will help you along the way. For the purpose of this tutorial, I have already completed these steps, and that is why you see the charlesjgantt.com domain attached to the vhost. When doing this on your own, simply replace my domain name with yours. I will post some screen shots of what my setup looks like, to help you along though.

touch bbb.news.charlesjgantt.com




































































 

Now run an ls command to verify that the file was created.

ls



































































 

vhost1.jpg

If the file was created correctly, you should see it here.

 

Now we need to edit the file and paste in a few lines of text. Nano into the bbb.news.(your_domain.com) and paste the following text. Remember to remove the (your_domain) and replace it with your domain url.

nano bbb.news.(your_domain.com)


























































 

<VirtualHost *:80>

    ServerAdmin webmaster@(your_domain).com

    ServerName bbb.news.(your_domain).com

    DocumentRoot /srv/www/bbb.news/htdocs

    ErrorLog /srv/www/bbb.news/logs/error.log

    CustomLog /srv/www/bbb.news/logs/access.log combined

</VirtualHost>

 

Now save and exit out of nano by pressing ctrl+x and y when prompted then saving with the same name.

 

You have successfully created a proper Virtual Host file for the new Drupal site. Now we need to enable that site using the following command. Once enabled, apache will need to be restarted.

a2ensite bbb.news.(your_domain).com
service apache2 reload























































 

Below are the screenshots I promised of my A-Record entry in my DNS settings for charlesjgantt.com as well as the port forwarding settings in my router.

a-record settings.jpg

Your A-Record can be found in the DNS settings of your domain. Simply give it the sub-domain name you wish to use, and then point it towards your home IP address. (Mine has been blurred out for security purposes.)

portforwarding3.jpg

 

Now enter your router's settings and find the port forwarding settings. You want to point the port you set in the V-Host file (80) to port 80 on your router. After saving this, you may need to reboot your router depending on its model.

 

In preparation for the BB View_70 LCD we will cover later in this tutorial, we need to disable a few services on the BBB to ensure that port 80 is free to serve our new website.

systemctl disable bonescript.service  
systemctl disable bonescript.socket
systemctl disable bonescript-autorun.service
systemctl disable avahi-daemon.service 
systemctl disable cloud9.service  
systemctl disable gateone.service 




















 

With these items finished, we are ready to test the website and see if it works. From within your local network, open up a browser such as Chrome and visit http://bbb.news.(your_domain).com:80 and if everything is correct, you should be prompted with the drupal install page as seen below. You will have to select your preferred language, and then if the steps above were followed, you will be taken to the Database configuration tab. Select MySQL, and then enter the correct Database Name, Database Username, and Database Password that you set up a few minutes ago.

dbconfig.png

Now click save and continue, and proceed to fill out the requested information on the final few pages. When finished you should be prompted to visit your new website which should look something like this!

bbb.button.jpg

 

Now that we have the news website up and running on the BeagleBone Black, we need to begin importing "News" content to it. Before we can do that, we need to install a few modules and to make life easier, we are going to install a utility called Drush (Drupal Shell) that will make life much easier moving forward. While seasoned Drupal Developers will certainly cringe at the method I am about to use to install Drush, it will work fine for this tutorial. To install Drush using the preferred method, visit the install instructions found at https://github.com/drush-ops/drush

apt-get install drush




































 

Before we can install any modules we need to modify the permissions on the modules directory, and then create two new directories.

chmod -R 777 sites/all/modules
cd sites/all/modules
mkdir contrib
mkdir features




































 

When the Drush install finishes, navigate to the websites root, and then use the drush pm-install and pm-enable commands to install the needed modules. The final command we will run in this set will clear all of Drupal's various caches.

cd /srv/www/bbb.news/htdocs
drush dl admin_menu adminimal_admin_menu module_filter features feeds feeds_tamper feeds_imagegrabber job_scheduler strongarm context
drush en admin_menu adminimal_admin_menu module_filter features feeds feeds_tamper feeds_imagegrabber job_scheduler strongarm context -ydrush cc all




































 

With those modules installed and enabled, hard-refresh the webpage and then visit the modules page to verify that everything we needed was properly enabled. Go through the list and make sure that Context, Context UI Features, Feeds Admin UI, Feeds Import, Feeds News Feeds Tamper Admin UI, Feeds Tamper, Feeds, Feeds Image Grabber, Job Scheduler, Job Scheduler Trigger, and Strongarm are enabled.

modules_page.jpg

 

With all the necessary modules enabled, we can move forward and build a feed importer that will allow us to pull in news from any website with an RSS feed. For the purpose of this tutorial, I am going to pull new content from Element14's All Content RSS Feed which can be found at http://www.element14.com/community/groups/feeds/allcontent. I am also going to pull in a feed of the newest 3D models uploaded to httphttp://www.thingiverse.com. To keep all of this organized, I need to create a new content type for the Thingiverse feed. Before I decided what I would be importing, I named this new content type "Tech News" but its sole purpose is to import from Thingiverse, so ignore the name and make yours whatever you want.

 

To get started creating the new content type and feed, follow along with the videos below.

 

 

 

 

 

I apologize for not being able to show the Thingiverse Feed creation. At the time of recording, the Thingiverse RSS feed had a bug that prevented me from mapping the elements correctly, but basically it is the same as creating the previous feed, but involves using Feeds Tamper, and Feeds Image Importer to get the images displaying correctly. A quick good search will show you the best way to utilize these extension modules.

 

Now that we have the feeds importing, and the site is up and running as it should, lets take a moment and look at how we can add the BB View_70 7-inch Touchscreen LCD CapeBB View_70 7-inch Touchscreen LCD Cape to create a desktop rss news reader.  For those of you who are new to the BeagleBone Black, the BB View_70 is a 7-inch 18-bit, 800x480 resolution LCD screen with a 4-wire resistive touchscreen digitizer on top. The Cape features two user-defined LEDs, and five tactile switches of which 4 can be user defined.

c8bd85ad871e36df5647ba9f3588e75c.png

 

Originally, the BB View_70 ran on the Angstrom distro, but with Debian being added as the default OS in revision C of the BeagleBone Black, the BB View_70 cape is easier than ever to get up and running. I could cover that entire process here, but it is actually very thoroughly covered in the BB View User Manual beginning at page 23. Note that if you run the BB View_70, you will need to supply an external 5V 1amp power source to the BeagleBone Black before the screen will turn on.

 

bbb-stand-2.jpg

 

For those of you with access to a 3D Printer, you can head over to Thingiverse and download the BBVIEW 7 LCD + Beaglebone Black Stand by Chumsize. This stand provides a clean way to securely and safely mate the BeagleBone Black and the BB View_70 together. The stand holds the screen at the perfect angle for both viewing and touch screen navigation. The stand takes about 35 minutes to print on a decent printer running at about 80mm/sec and uses hardly any ABS filament. I did find that the holes designed to capture the standoffs need a bit of cleaning, and you will need to heat the standoffs with a cigarette lighter or soldering iron and then press them into the holes for a more secure fit. Overall I think this stand is one of the coolest things I have ever printed, and it has made my development time with the BB View_70 much easier.

 

bbb-stand-1.jpg

 

I'm a screen junky and at my home office, I have tripple 24" monitors, with about 30 tabs open in each at any given time. I know this is excessive, but having this little news reader on my desk really does make life easier. As an additional bonus, since it only imports the latest 10-items every hour, I spend less time down a news rabbit hole, and more time working. I hope this tutorial was as informative as I hoped it would be, and I would love to hear from anyone who makes their own news reader, or takes these instructions and builds something completely different. I have a few more tutorials coming out in the next couple of weeks that will build upon this basic starter, such as learning how to control the BeagleBone Black's GPIO pins via the internet using Drupal. Until then #HackTheWorld & #MakeAwesome!

 

final.jpg

Hello,

 

I've got a Sensor Connection Cape (GVS) for the Beaglebone Black up on Kickstarter. Here is a picture of the card:


BBB-GVS-X3-cca-01B.jpg


Here is a video demonstration of the card.



Thanks,


Doug Gilliland.

logo.pngstachedog.png

 

Intro

This Demo will take a fresh from the box element14 BeagleBone Black with the preinstalled Debian system and configure it to work with BB-View. Subsequently we will use this new setup to attach virtual moustaches to passers-by

 

Equipment Required

e14 BeagleBone Blacke14 BeagleBone Black

BB-View 4.3"4.3" or 7"7"

5v PSU5v PSU

UART8000-UUART8000-U (Optional QOL improvement)

USB memory stick

Playstation 3 camera

 

Downloads

Debian patch files

Linux tools

BeagleStache

 

Setup

 

Extract the files from the Debian Image archive to a USB stick

 

Connect the BeagleBone black to your PC via either the UART8000-U or the included USB cable

USB.pngUART.PNG

 

Connect the 5V PSU

PSU.png

 

While the board is booting, ensure PuTTY is installed on your computer and start the software. The settings for each connection type vary:

Ethernet over USB: uses an SSH connection via the default IP address of 192.168.7.2

UART8000-U: The COM port will vary, the correct port can be found in the Windows Device Manager (for more information on this please see the UART8000-U guide). The other settings are shown in the image to the right.

serial settings.PNG

 

Once the board has had time to boot you can go ahead and click "Open" on the main screen of PuTTY to open a connection to the board. From here on all the commands are uneffected by your chosen connection method. There is a slight inconveniance when connecting via SSH using the Ethernet over USB as the connection will need to be re-established each time you reset the board

SSH error.PNG

BB-View Patches

 

In the terminal window enter the following commands (as per the BB-View user manual):

mkdir /media/udisk
mount /dev/sda1 /media/udisk
cp -f /media/udisk/zImage /boot/uboot
cp -f /media/udisk/*.dtb /boot/uboot/dtbs
tar -xvf /media/udisk/kernel_modules.tar.gz -C /
cp -f /media/udisk/xorg.conf /etc/X11/
sync












If you are using the 4.3" screen with your BB-View than you are good to go! However the 7" screen requires a little more configuration, enter the following commands into PuTTY:

cd /boot/uboot/dtbs
cp am335x-boneblack-lcd7.dtb am335x-boneblack.dtb
rm /etc/pointercal*
sync












Now shut down the BeagleBone and connect the BB-View along with the screen, then supply power.

You should now have a working BB-View & BeagleBone Black system running Debian

Ethernet

 

After applying the BB-View patch the ethernet is disabled by default to improve boot times. If required, the Ethernet can be re-enabled with a simple edit, use nano to edit the following file:

nano /etc/network/interfaces












Then find the lines:

#auto eth0
#iface eth0 inet dhcp












and uncomment them by removing the # to read:

auto eth0
iface eth0 inet dhcp












After this save and exit then:

sync
reboot












Moustache Time!

(From my list of titles I never thought I would write)

 

A full set of instructions for adorning people with virtual moustaches can be found at BeagleBoard.org - BeagleStache however they are repeated below, with slight modifications to make the project BB-View compatible.

    1. Clone the GitHub repository and build the code with the following commands
      git clone git://github.com/jadonk/stache
      cd stache
      make && make install
    2. Because the BB-View by default operates as the user "Debian" instead of root, the following commands are required to operate BeagleStache:
      mkdir /home/debian/stache
      cp -r /root/stache/* /home/debian/stache
    3. To make the running of BeagleStache a little easier you can create a shellscript on your desktop containing the following:
      #!/bin/bash
      sudo /root/stache/runstache
    4. Now plug in the camera ,doubletap your new desktop script and enjoy your moustachey exploits!
bs.png

openrov 1.jpg

OpenROV open-source submarine (via OpenROV)

 

What happens when an entire community comes together to help one man discover underwater treasure? Quite possibly one of the best maker projects ever devised is born, that’s what. Meet OpenROV, an open-source exploration submarine created for the DIY community, powered by a BeagleBone!

 

The OpenROV project began when Eric Stackpole wanted to explore a cave near his home that was rumoured to have buried treasure. When neighbors got wind of his idea, everyone was willing to help (go figure). The real magic, however, began when scientists heard about the idea of creating a tiny, open-source submarine and got to thinking.

 

Makers, engineers and scientists from more than 50 countries banded together to make Stackpole’s dream a reality. Why? Because an open-source robot can be programmed to do just about anything. Scientists believe they can program the OpenROV to do everything from monitor pollution under the sea to discovering new aquatic species. Plus, Stackpole gets to hunt for gold too. It’s a win-win.

 

openrov 2.jpg

(via OpenROV)

 

The robot is 30cm long, 20cm wide and 15cm tall and it looks just like what you always hoped Scuba Steve would use during his underwater explorations. It weighs in at 2.5kg and was designed to withstand depths of up to 100m, although its only been tested at 20m.

 

openrov 3.jpg

OpenROV in action underwater (via OpenROV)

 

The DC-powered design features a single 10cm by 18cm waterproof tube that protects all electronics and equipment from water damage and it can move horizontally, vertically and diagonally with the help of three 800kv brushless motors, two horizontal thrusters and one vertical thruster. It’s also fully controllable via computer keyboard or USB controller.

 

At its heart is a BeagleBone single board computer and their OpenROV BeagleBone Cape. Does that mean they want you to experiment with their cape? It looks like it.

 

The robot is fully functional in both fresh and saltwater and moves at 1m/s. It is still, unfortunately, an energy guzzler, as it takes 8 on-board C batteries for every 60-90 minutes of activity, but improvements are in the works.

OpenROV successfully completed its Kickstarter campaign on Friday and is looking to make several improvements to the design in the near future, including more efficient propellers and better resistance to rusting caused by salt water.

There’s no word on what the final product will retail ─ it is still largely an experiment. Once the kinks are worked out it should launch for the general public, but for now if you’re lucky enough to find one you’ll have to tinker with it yourself. This does, however, grant you the freedom to program it to do your evil bidding. There’s no underwater lair you won’t be able to discover. Fight evil responsibly.

 

 

C

See more news at:

http://twitter.com/Cabe_Atwell

I just saw this: http://hackaday.com/2014/07/22/talking-beagleboard-with-jason-kridner/

 

It's a 14-channel 100Msps logic analyzer using the BeagleBone Black and no additional hardware - it makes use of the on-chip dual programmable real-time units (PRUs).

Apparently it has been used to capture sustained >100MByte sized data streams : ) And also for I2S audio data capture : ) It would be ideal for digital audio testing!

Highly impressive stuff.

 

The BBB has evolved into the universal test tool that we always suspected it could become.

Multifunction instrument based on BeagleBone Black

Probably the best way to understand the Internet of Things is to get some things on the Internet and in this article we're going to do just that.

 

icon_19938.pngWhat we are going to assemble is a greenhouse control system which will be able to monitor temperature and light levels and control the windows on the greenhouse. More importantly, at the end of it, you'll have a development platform built for further exploration. At the core of what we are constructing will be a BeagleBone Black, a powerful, small ARM-based general purpose computer which will play host to a number of Eclipse tools, run an MQTT stack for us and act as the main brain of the operation. It'll be responsible for taking our temperature and light readings and publishing them to the Internet while listening for control messages to set the greenhouse windows.

 

Some would, at this point, attach the sensors and controls directly to the BeagleBone Black (BBB). In real world implementations, it's more common to find micro-controllers in the front-line as it were, connected and controlling the sensors, servos and other hardware as they typically are more resilient to the environment, more compatible with the electrical elements and a lot cheaper. Therefore to be more realistic, we are going to attach an Arduino micro-controller over a Serial-over-USB connector though this could be an actual serial connection or a wireless connection of some description - the advantage of a USB connection for this example is that it also supplies the power to the Arduino.

 

So far, you'll need an Arduino and a BeagleBone Black to follow our build process. There are a whole range of Arduinos with different features but we recommend the ever popular Arduino Uno or the Arduino Leonardo. For the sensors and servos, although you can assemble your own collection of hardware, we are going to recommend the Grove Starter Kit Plus, a shield sporting numerous sockets and a collection of components with de-coupling chips and pre-wired with plugs for the shield sockets. This makes it great for experimentation without breaking out the soldering iron.

 

orion.pngWe're going to use Eclipse Orion on the BeagleBone Black rather than the default Cloud9 IDE as it is a development environment more capable of working with languages other than JavaScript, even if here we are using it entirely with JavaScript. The flexibility of being able to use the same tools with whichever language you decide to work in and the ability to use those tools over the Internet is a huge plus when putting together a prototype or development system.

 

The Eclipse IDE, which many are familiar with, is built as a platform for integrating tools from many different vendors in one coherent framework on the desktop. Eclipse Orion has been developed as a separate project which looks to bring that tool integration philosophy to a web-based browser-native development environment. There's actually two Orion IDE's - the project started with a Java based version with an eye on hosted collaborative development platforms while along side that, Orion Node, a Node.js based version of the system designed for a single user has emerged. The Orion IDE offers a syntax aware editor, with search tools, and a shell environment to support command-line style application building, deployment and running. The Orion Node version is also pretty compact and remarkably easy to install, making it a great way to get working on a small device remotely.

 

Beginning building

 

First though, lets make a start by getting the controller assembled. First, attach the Grove shield to the Arduino. Then, in the components you'll find a temperature sensor, a light and a light sensor  we'll get to the servo later. Plug the temperature sensors into the A0 (analog 0) port, a sideways connector on the lower left side of the Grove shield. This port and its other four siblings are able to read an analogue voltage from an electronic device making them ideal for non-digital sensors. Plug the light sensor into A1, just above A0.

 

And that's the hardware assembled:

 

hackpad.com_VCR1WLsIyOE_p.160075_1402832276223_DSC01899.jpg

 

Note that though the Arduino can be powered over the USB port from the BeagleBone it is better, especially when adding power-drawing devices like servos, to use a 9V power supply (or battery) for the microcontroller.

 

Next we'll need to be configuring the BBB and selecting the operating system. To date, most BBB boards have come with the Angstrom Linux distribution installed on the 2GB of eMMC flash storage; they are identifiable by being labelled revision A or B. Although Angstrom is a functional Linux distribution, it isn't mainstream and the BeagleBone project is in the process of switching its default Linux to an up to date Debian GNU/Linux. There's only one catch... Debian is a bit bigger than Angstrom and although it fits onto the 2GB eMMC flash, if you install the packages we will, you'll find yourself with less than 1% free space. If you have an 2GB BBB, we recommend you get yourself a Micro-SD card and install and boot Debian from that - you may also want to install Debian onto the eMMC for consistency.

Instructions on how to install Debian into the eMMC and the latest images for eMMC and SD are on the BeagleBoard.org site. You will also need to resize the image on the SD card once installed to make full use of the SD cards capacity - a guide to this is also available and, to save time, there's a quick version of the process at the end of the page .

 

As new BeagleBone Blacks labelled Revision C are starting to arrive with 4GB of eMMC and Debian pre-installed so this isn't an issue.

 

Organising Orion

 

The next steps can be carried out locally, if you've plugged your BBB into an HDMI monitor and attached a USB keyboard and mouse or remotely over a SSH connection on a network. If the former, you will still need to connect the BBB to your network. Also remember to use a USB hub as the BBB only has one USB port and we have yet to connect the Arduino we talked about earlier. If over the network, the Debian installation will be advertising itself as beaglebone.local, so all thats needed is to run ssh root@beaglebone.local to log in. (It is possible to connect a BBB to a PC over just a USB cable and ssh in, but this by default doesn't share the PCs internet connection which we'll need to install software).

 

The Debian GNU/Linux image already has an up-to-date node.js installed so what we initially need to do is install Eclipse Orion, the web-based IDE. We can do this like so:

 

root@beaglebone:~# mkdir greenhouse
root@beaglebone:~# cd greenhouse/
root@beaglebone:~/greenhouse# mkdir workspace
root@beaglebone:~/greenhouse# npm install orion









 

We'll be keeping all our work in the greenhouse directory which is why we also created a workspace directory in there. Once installed you can use npm to start Orion too, but before that, there's a small tweak to be made. We need to edit node_modules/orion/orion.conf and change the fourth line, a commented out line for setting npm_path to:

 

npm_path=/usr/share/npm/bin/npm-cli.js









 

And the last line, a commented out line setting the location of the workspace. In this case it should be replaced by...

 

workspace=/root/greenhouse/workspace

 

... though this could of course be any directory.

 

Save the file and we're ready to start Eclipse Orion:

 

root@beaglebone:~/greenhouse# npm start orion

 

Go to your browser and browse to "http://beaglebone.local:8081/" if accessing remotely (localhost:8081 if local) and you should be greeted by the Orion user interface.

hackpad.com_VCR1WLsIyOE_p.189956_1403513024589_orion-ui.png

The icons at the left hand side set the view in the Orion IDE, the pencil shows the workspace and other directory/file views, the magnifying glass takes you to a search centric view and the rectangular icon, representing a console session, gives access to the Orion shell.

Getting Firmata onboard

 

We now have the hardware for the sensors assembled and an IDE installed on our BBB. The next step is to bring connect them and for this we are going to use Firmata, firmware which implements a generic protocol for talking between host computers and micro-controllers. In many ways, it's the software equivalent of the Grove kit we are using as it makes it easy to work with controllers.

 

You can install the Firmata firmware using the Arduino IDE. At this point you have a choice - you can install the Arduino IDE on a PC, Mac or Linux box and use that or you can install it on the BeagleBone Black. The latter course of action will require you to have a screen or a remote X Windows session configured as the IDE is a GUI application. Install the IDE with sudo apt-get install arduino

 

The former approach, installing the Arduino IDE on a PC, Mac or Linux system, is often quicker as you'll only be doing this once in a while. You can download the software from the Arduino downloads page  we recommend the Arduino 1.5.6-r2 beta or later  and follow the installation instructions.

Whichever route you take, once the Arduino IDE is running, select File » Examples » Firmata » StandardFirmata, select the Arduino board and USB/serial port it is connected to the IDE host machine with in the Tools menu and then click the compile and upload button (the tick and the right arrow in the Firmata sketch window). When this is complete, your Arduino board will understand the Firmata protocol and you can plug the USB cable back into to the BeagleBone Black and we can take control of our Arduino board.

 

Back to Orion

 

We can now return to Orion in the browser and start creating some code. Over on the left hand side of the browser are a pencil, magnifying glass and a terminal window. The pencil lets you view, create and edit projects, the magnifying glass lets you search in various ways and the terminal gives you access to a shell. It's this shell we want to go to next because we have Firmata support on the Arduino and need software to communicate with it.

Johnny-Five is such software, developed for Node.js to enable robotics development. Its big feature is that it allows a programmer to work in terms of LEDs, Buttons , Sensors and Servos rather than high/low pins and it simplifies the process of managing them.

To install it, we use npm as we did earlier to install Orion, but now we can run it from within the shell. Go to the text field at the bottom of the Orion shell view and type:

npm install johnny-five

It'll look like this when it's done installing:

 

hackpad.com_VCR1WLsIyOE_p.100400_1404211483449_Screenshot 2014-06-28 11.37.40.png

 

Click on the pencil to get the file view back and select from the Orion menu File » New » Project » Basic and enter greenhouse as our new project's name. This will move us into the directory for the new project in the viewer. Now select File » New » File and create a file called greenhouse.js.

 

hackpad.com_VCR1WLsIyOE_p.100400_1404215568626_Screenshot 2014-06-28 11.38.52 (1).png

 

We can now start entering some code. First of all, we need to tell Orion's IDE that we're writing Node.js code and not to warn about common Node.js commands and classes. This is done through a jslint directive in a comment:

 

/* jslint node:true */









 

Now we need to bring in the Johnny-Five library. At the core of Johnny-Five is the Board abstraction in that we talk to a Board. We'll create that at the same time as bringing in the library:


var five = require("johnny-five"),
board = new five.Board();









 

When the program starts and the Board is created, the library will begin to negotiate with the Firmata enabled Arduino and will reach a point when its ready to start doing some work. We want to capture that "ready" event...


board.on("ready", function() {










The first thing we want to do is monitor the temperature sensor. We want to read the temperature once a second and, if you recall, we attached the sensor to A0. In Johnny-Five, we just have to tell it about that sensor like so:

 

    var tempsensor = new five.Sensor( { pin:"A0", freq:1000 } );


This freq(uency) means that every 1000 millisecond, or second, the sensor will be read and a data event fired. We now want to capture that data event by directing it to our own callback:

 

    tempsensor.on("data", function() {


The event comes complete with a value for the reading (this.value) and we can use that to calculate the temperature by first working out what the resistance of the temperature sensor is and then converting it to a temperature using a formula based on the sensor's data sheet. (See this wiki page on the sensor for more).

 

        var resistance=(1023-this.value)*10000/this.value;
        var temperature=1/(Math.log(resistance/10000)/3975+1/298.15)-273.15;









 

For now, we'll print the result to the console and end the tempsensor callback and the program's code.

 

        console.log("Temp:"+temperature);
    });
});





 

Once we have selected File » Save to write the code to disk, we now have a program ready to run from the Orion shell. If we switch to the shell using the sidebar and click into the command entry panel at the bottom, we can begin typing. The shell will attempt to autocomplete for many things. Type "no" and it will suggest "node". To accept that suggestion, press Tab. We want to start a Node.js program, so type "st" and autocomplete will suggest "start", again press Tab to accept. At this point you can enter a filename but the shell is already anticipating that and will be offering filenames from the current directory; select greenhouse.js from the list and hit return.

The program should start running and, after initializing, start printing readings from the temperature sensor.

 

hackpad.com_VCR1WLsIyOE_p.100400_1404215609798_Screenshot 2014-06-28 14.07.34.png

 

To stop it running, go to the command panel and enter node stop at which point the shell will offer process ids you can stop. There should only be one at this point so select that, hit Return and the process is stopped. We are now reading the sensor, the next step is to get that information out to the world.

Going MQTT

 

We're going to use the MQTT messaging protocol to send our data out. MQTT is built for this kind of task because it's lightweight and flexible. For this part of the example, suffice to say that with MQTT you can send messages with tags to what looks like (but isn't) a file-system hierarchy on a server. To make life easier, Eclipse runs a sandbox server at iot.eclipse.org so we'll use that as the MQTT server. What we need is MQTT support so go to the shell, make sure you are in the top level "Orion Content" directory (if not enter cd .. till you are) and then enter npm install mqtt to install the Node.js MQTT library.

 

hackpad.com_VCR1WLsIyOE_p.100400_1404215664783_Screenshot 2014-06-28 14.23.04.png

 

After that's installed, return to Edit view and bring up greenhouse.js. After the require for johnny-five we want to add code to bring in MQTT and connect to the Eclipse sandbox...


 

var mqtt = require("mqtt"),
client = mqtt.createClient(1883,"iot.eclipse.org");









 

 

And that's a basic connection set up. Now we need to publish our temperature data. After the console.log we'll add this line...


 

client.publish("greenhouse/mygreenhousename/sensor/temp",temperature.toString(), { retain:true });

 

 

The first parameter is the topic, a file-system-like path - greenhouse/mygreenhousename/sensor/temp but don't make assumptions about it working like a path; it's more of an informal hierarchy of names. This first thing for us though is to change mygreenhousename to something that is unique to you to avoid colliding with other users on the sandbox who are also following this article. Now we have the 'greenhouse' and your own name for that greenhouse. Beneath that we have sensor where, going forward, we'll put all our sensor data and beneath that a temp element where we'll post the temperature data.

 

The next parameter is us converting our temperature to a string before posting to make it more readable; MQTT doesn't have any rules for what is called the payload of a message so it could be binary or an image. We've gone with the good old string because we'll want to read it later when testing.

 

Finally we set an option, "retain" to true to ask the server to hold onto the value for any other client that requests the data. If we don't set retain, the value will be broadcast to any client listening for it at the time but it won't be available for clients that connect after the broadcast leaving them to wait. While we're pushing the temperature out every second, we may want to only do that when it has changed and that may be an indeterminate amount of time.

 

Save this code, return to the Orion shell and start the program again. It should start as it did before, but now, if you open a new browser window and look at http://eclipse.mqttbridge.com/greenhouse/mygreenhousename/sensor/temp you should also see that same temperature reflected on the Eclipse sandbox. The eclipse.mqttbridge.com site also monitors to iot.eclipse.org MQTT server and makes debugging easier by allowing you to browse the various MQTT topics that it sees appearing on the server.

 

Now we know that's working, you may want to go back and delete the console.log line.

Let there be light (sensor)

 

We've only done the temperature sensor, but it should simple to add support for the light sensor and it is. After the temperature sensor handler we can add


var lightsensor = new five.Sensor( { pin:"A1", freq:5000 });









To map the light sensor and get it sampled every five seconds and then send that sampled value to the MQTT server like so...


client.publish("greenhouse/mygreenhousename/sensor/temp",temperature.toString(),
{ retain:true });









 

And with just those few lines, if you re-run the program, you'll be transmitting light and temperature data. The process for adding more sensors follows this basic pattern though you can, for example, cut down on bandwidth by only updating when your code detects a change locally or using some other logic. As before, if you browse to if you browse to http://eclipse.mqttbridge.com/greenhouse/mygreenhousename/sensor/light you should see

Moving on

 

In our virtual greenhouse, we are getting the temperature and light readings, but we aren't able to take any action on then like opening the windows. For that you'll need a servo to attach to the window control. If you look in the Grove kit, you'll find one along with all the basic mounting gear. Don't worry about mounting it to anything yet, just take a Grove cable and plug it into digital port 3 (D3) which on most Arduino's is the first digital port that supports PWM (Pulse Width Modulation, useful for controlling servo motors).

 

With the servo installed we can now add some lines to greenhouse.js to control the servo. We'll add this code immediately after the light sensor code. We start by declaring we have a servo on pin 3.


 

var servo=new five.Servo(3);
servo.center();









 

 

Servo motors typically take a value from 0 to 180 and move to that angle. We are going to get the value for the servo via the same MQTT server we are publishing our temperature and light readings to. We will be listening from someone broadcasting a new setting under the greenhouse/mygreenhousename/commands/servo by using the MQTT library's subscribe command.


 

client.subscribe("greenhouse/mygreenhousename/commands/servo");

 

 

Now, when anything happens in that topic, an event will be triggered. We can capture this by waiting for the "message" event...


client.on('message', function(topic,message) {
    console.log("Got topic "+topic+" with "+message);









 

We get the topic value because you can actually subscribe to multiple different topics and wildcard topic names in subscriptions - getting the topic name lets us make decisions based on what particular topic generated the message. For now though, we're only subscribed to one topic so we'll assume that's a servo control message. We can now process the message and we'll keep it simple and just parse whatever's arrived as an integer.

 

    var val=parseInt(message);
    if(val<10) { val=10; }
    if(val>170) { val=170; }
    servo.to(val);
});









 

We also map it into a tighter range (as servos can be mechanically tetchy at the ends of their ranges) and then we tell the servo to move to that position. And that's it. If we run this version of the code, nothing will happen with the servo until we post a value to the iot.eclipse.org server. Again the eclipse.mqttbridge.com server comes to our aid. We can use curl to send a value over HTTP to it like so:


 

curl -X POST --data-binary "100" http://eclipse.mqttbridge.com/greenhouse/mygreenhousename/commands/servo

 

Beyond the servo

 

Of course you could always write another node.js client (or use other language) to monitor the temperature and light levels by subscribing to those topics and control the airflow by publishing new servo positions.

The combination of Eclipse Orion, Johnny-five, MQTT, the BeagleBone Black and Arduino make for a formidable set of tools when setting out to explore what you can create for the Internet of Things. And you can of course add more sensors and control more devices, or take the BeagleBone out of the equation by adding ethernet or Wi-Fi to the Arduino and porting the JavaScript Node.js code to run on the Arduino itself. Or add a meshed wireless controller and use the BeagleBone to coordinate that mesh of devices... and even run the MQTT server on the BeagleBone and...

 

Just add imagination and the Internet of Things is yours!

Final code

 

/*jslint node:true */

var five = require("johnny-five"),
board = new five.Board();

var mqtt = require("mqtt"),
client = mqtt.createClient(1883,"iot.eclipse.org");

board.on("ready", function() {
    var tempsensor = new five.Sensor( { pin:"A0", freq:1000 } );

    tempsensor.on("data", function() {
        var resistance=(1023-this.value)*10000/this.value;
        var temperature=1/(Math.log(resistance/10000)/3975+1/298.15)-273.15;
        console.log( "Temp:"+temperature.toFixed(2) );
        client.publish("greenhouse/mygreenhousename/sensor/temp",temperature.toString(),
                    { retain:true });
    });

    var lightsensor = new five.Sensor( { pin:"A1", freq:5000 });

    lightsensor.on("data",function() {
        var light=this.value;
        client.publish("greenhouse/mygreenhousename/sensor/light",light.toString(),
                    { retain:true });
    });

    var servo=new five.Servo(3);
    servo.center();

    client.subscribe("greenhouse/mygreenhousename/commands/servo");
    client.on('message', function(topic,message) {
        console.log("Got topic "+topic+" with "+message);
        var val=parseInt(message);
        if(val<10) { val=10; }
        if(val>170) { val=170; }
        servo.to(val);
    });
});









New BeagleBone Black Case for the Embedded industrial application of users. This case has followed on from the popular Raspberry Pi DIN rail case which saw many users across Europe and the US using these for industrial use. The modulbox is a DIN mounting enclosure which has been designed according to DIN 43880 to meet the needs of a number of applications including heating & lighting control and energy metering. The case is made from UL94V-0 moulded plastic.

 

The box measures (HxDxW) 90.5x62x68.1mm

 

Available at 25.041EN00.BGB - HITALTECH - MODULBOX, 4M KIT, BEAGLEBONE BLACK | CPC

IMG_20140623_162344.jpg

IMG_20140623_162357.jpg

IMG_20140623_162409.jpg

IMG_20140623_162420.jpg

shabaz

BBB - PRU C compiler

Posted by shabaz Apr 30, 2014

Nice bit of information at this TI URL:

(My underlining below):

 

PRU Development

The Programmable Real-time Unit (PRU) is a low-latency microcontroller sub-system comprised of two or more 32-bit RISC processors, local instruction and data RAM, local peripherals and an interrupt controller. The PRU is efficient at handing events that have tight real-time constraints. The PRU is also known as the Industrial Communications Sub-System since it is used to enable industrial protocols such as EtherCAT®, EtherNet/IP™, PROFINET, PROFIBUS, POWERLINK, SERCOS III, and others. Each 32-bit processor runs at 200MHz, enabling 5ns instruction cycle. Local peripherals within the PRU sub-system include UART, eCAP, MII_RT, MDIO and IEP. The PRU’s fast input and output pins enable detection and reaction to I/O events within two PRU cycles.

Code Composer Studio provides a C compiler enabling users to add differentiation to their products.

 

(Downloading now! )

 

bbb-pru-c.png

I've previously had great results connecting Adafruit 8x8 LED matrix displays to the BeagleBone Black via I2C:

 

I decided to try out the Adafruit bi-color 8x8 LED matrix and hooked it up with the same I2C pins as before.  You'll need to setup the Adafruit_BBIO Python library if you haven't already:

https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/overview

 

You'll also want to grab the Adafruit Python libraries for the Raspberry Pi since they work on BeagleBone Black, too:

https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code

 

Here is the BegaleBone Black running the demo program ex_8x8_color_pixels.py from the repo:

https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code

 

BeagleBone Black & Adafruit 8x8 bi-color matrix

https://www.youtube.com/watch?v=vnHC6bVj5bc

 

I thought it would be interesting to plot the readings from a sensor over time on the matrix with different colors representing the magnitude of the reading:

20140116_104027.jpg

 

I hooked up a pot to the analog input to simulate a sensor.  Here's the Python script:

https://github.com/pdp7/beaglebackpack/blob/master/plot.py

 

It is Invoked by this shell script so that PYTHONPATH will be set:

https://github.com/pdp7/beaglebackpack/blob/master/plot.sh

 

BeagleBone Black: plot analog sensor on Adafruit bi-color LED matrix

https://www.youtube.com/watch?v=QQNqxHQDj5E

 

Cheers,

Drew

http://twitter.com/pdp7

Introduction

This post briefly documents a BeagleBone Black (BBB) based music box. If you’ve ever wanted a Sonos system but (like me) felt they were a little expensive, then it is worth considering using a compact Linux platform like the BBB for creating something slightly similar. I feel the sound quality is not leagues different (better nor worse) than some more expensive commercial offerings.

finished-front.jpg

It was a quick, fun project and costs about £100 including the cases and the BBB.

The idea for this project was simple - a compact box that connects to the home network and allows the ability to send it music to play (or it can play music stored on-board or on a server). The documentation provides just an overview because the circuits are already documented, and every implementation could be slightly different depending on end user needs, speaker enclosure, etc.

Here is the rear view:

finished-rear1.jpg

 

Shown below is a video of it in action. The sound was recorded from the camera in-built mic so is not representative of actual sound quality. For actual sound quality, refer to the MP3 recording here, which was captured by connecting the headphone output (not line output) directly to an ADC and captured by the PC.

 

Components

The main bits and pieces are the speaker box, the BBB and a DAC/amplifier.

Although a BBB and home-built DAC/amplifier was used, a Raspberry-Pi and Wolfson audio card could be used too, for a similar price.

The home-built DAC and amplifier is easy to assemble; it uses medium-sized SMD components that are hand-solderable, and gives results similar to a Meridian DAC which uses the same chip (a Texas Instruments ic). Full circuits and information are at these two locations: part 2 has the schematic, and part 1 has some more technical detail.

There are plenty of other DACs available including pre-built ones. A search for “I2S DAC” will reveal ones that should be suitable (I have not tried them) – this ebay example is just over £10. (Note that you may require a logic inverter, see the comments sections in the links earlier).

 

The speaker is a Tivoli Audio speaker. It is possible to get these in new condition for about £15-20 frequently on ebay, in various color options. Any speaker enclosure would have been fine. The official Tivoli webshop sells new speakers (slightly different model) from £39 upwards.

 

Design and Implementation

The DAC board was mounted inside the speaker, and the BBB was mounted outside. This allows access to all the BBB ports while making the minimal amount of holes in the Tivoli speaker (Speakers are sealed for good audio reasons).

It won't replace main home music systems but that was not the intention, nor is it stereo (that capability is easy to achieve by adding a second speaker connector, but I didn't require it). This is more a bedroom or home study one-box sound system.

 

Step 1: Fit BBB inside a case

The first step was to get the BBB into its own case. I connected a push-switch to safely power on/off the platform. I also wired up a DB9 connector to interface to the DAC.

case-open.jpg

I used L-shaped single-in-line header pins to solder up the connections and heatshrink at the DB9 connector end. The switch and LED were wired up to the power switch pin on the BBB and to the 3.3V supply (via a 100 ohm resistor) respectively. The push-switch is wired to the P9 header, pin P9_9 and to ground (pin P9_1). The LED 3.3V supply can be taken from P9_3.

 

The photo below shows the LiPo battery fitted. I used a paper sticker on the underside of it, to insulate it further. The BBB doesn’t run hot, but the battery could have a spacer between the PCB and itself if desired.

battery-fitted.jpg

Here is the finished result, powered up. It can be safely powered down by pressing the button again (this feature is by default in the current Debian image).

single-cased.jpg

The other side of the case provides access to the USB port, and a small USB WiFi adapter was fitted. I have not got round to finding a software driver for it yet, so for now I just used Ethernet.

 

Step 2: Speaker modifications

The next step was to put the BBB aside and work on the speaker and DAC. The speaker was opened up, and the wadding was removed and stored in a plastic bag to prevent dust and drilled fragments of plastic getting on it. The speaker cable was chopped and discarded, and the grommet removed.

speaker-first-opened.jpg

The DAC board was fitted with L-brackets http://uk.farnell.com/jsp/search/productdetail.jsp?CMP=i-ddd7-00001003&sku=1466881 and the speaker rear cover was marked up for drilling the holes to secure it, and for the headphone and line jack outputs (3mm holes for the screws, and 6mm holes for the jacks).

l-brackets.jpg

The photo below shows the finished result.  The jacks are rather recessed. This is actually no problem for some headphones (e.g. a pair of low-end AKG I own) but others will have problems. I plan to drill to a recess with a larger drill bit to 7mm and it will cover both of my sets of headphones. Note that you want to make the holes as small as practical.

dac-mounted.jpg

After wiring up the DAC to the speaker, the wadding was placed back in position and the cover was closed up again as shown below. Then the DB9 matching connector was soldered (wires protected with heatshrink). I didn’t bother with a cover for it.

rear-before-securing.jpg

After testing, the hole needs to be sealed (perhaps with epoxy resin glue).

Finally, the BBB was attached to the speaker (rubber feet and adhesive foam pads can be used).

 

Step 3: Try it out!

This step was the easiest.

Plug in the power supply, power up and install the audio player software:

sudo apt-get install mplayer




Then, try to play a music file (either from local storage or from network storage):

/usr/bin/mplayer -ao alsa -volume 10 “songname.mp3"




 

Summary/Next Steps

A quick and simple sound system was created. With a pre-built DAC and amplifier, the hardware implementation can be extremely easy.

There are plenty of software options for creating a library of songs and providing an interface for the user to select something to play. I have not tried them. For now I will just use SSH to select music. Eventually the hope is to create a simple browser based app that will allow one to upload MP3 songs from a PC or mobile phone for instant playback. A wake-up alert in the morning with a random song, or the news, will be a good option too (enabled via browser on mobile phone).

shabaz

BBB - Logic Supply BB100 Case

Posted by shabaz Feb 19, 2014

The Logic Supply BB100 case has be available for a while (also in black), I purchased one recently while buying other gear, these were my thoughts on it

(pictures were from a cameraphone so apologies for the quality - better images at the Logic Supply website of course).

board_inserted.jpg

 

If you need your BeagleBone Black boxed up, there are worse ways. I thought it was very well made and quite flexible. The cover can be mounted at three heights, to accomodate capes (the gaps can then be used for wires and ribbon cables for example. I will probably fit the Olimex 1400mAH LiPo inside it too as shown here.

 

The case is steel (not aluminium) and in my opinion is extremely accurately cut and shaped. The case has sub-millimeter accuracy. The base and shell are less than a millimeter thick, yet extremely tough because of the choice of material.

 

All connectors are spot-on centered into their holes and the tiny narrow microSD card slot doesn't scrape or touch the card at all.

 

The board is held in place with four screws on permanently fitted metal stand-offs. The finished result is about the size of a pack of playing cards.

interior.jpg

 

The exterior finish is a matt type, slightly roughened surface so not gloss shiny/smooth. I think the finish is great.

Initially I wasn't a fan of the D-Sub connector punch-out (I don't like using this connector for serial connections although it is a standard) but I now think it is a great idea, since it can serve as the I/O for 8 pins or more if a serial port is not desired. On the other side there is a circular punch-out ideal for coax shaped connectors or for a switch for example (approx 6.5mm dia hole measured with a ruler). These punch-outs mean that for many use-cases one may not need to ever drill any holes in the case.

Very narrow slots allow for all LEDs on the board to be visible.

case-closed.jpg

 

Lots of spare screws are supplied in two sizes; the flush ultra-tiny ones shown in the photo earlier, or slightly larger pan-head. By only fitting two screws, the lid can become hinged.

The rear has punch-outs for providing screwed attachment to another surface, or thin vertical slots can be used for fitting to a metal chassis. Really nice engineering everywhere on this case.

Four thin rubber feet are supplied for optional fitting.

The case is not cheap but metal cases usually do cost more, and so this case is fairly good value for money especially if you want a case you can use as part of a demonstration for example.

Postal cost is quite low in Europe for this case shipped from Netherlands, so that helps too.

 

As a summary, the case is very nice and practical, and I think it is worth the cost.

(BBB - Building a DAC part 1 can be found here).

Part 3 implements a complete design in an enclosure for a Sonos-like solution.

Introduction

The BeagleBone Black (BBB) has a digital audio interface and this was explored slightly in an earlier post.

The findings from that prototype were used to construct up a DAC board and it is described here. The aim was to have a relatively simple, easy-to-assemble board designed for portable use (headphone or small speakers) but with at least iPod-level performance. The circuit is described here and the complete schematic is attached to the post. The entire circuit connects to the BBB using 6 pins and needs no separate power supply. This is a recording using just the microphone from the camera - actual audio quality is much better.

 

For a better quality, the audio from the prototype can be heard in this zipped mp3 file. This was directly recorded from the headphone output so that it is more representative of what the user will hear (the original track that was played through the DAC was downloaded from Amazon, for comparison purposes).

dac-board.jpg

 

Detailed Description

This is the functionality on the board:

dac-layout.png

The DAC integrated circuit and headphone amplifier portion were left unchanged from the part 1 prototype although the DAC was replaced with TI’s PCM5102 which is pin-compatible with the earlier PCM5101A. The PCM5102 device is used in commercial DACs such as Meridian’s Explorer.

The remainder design is kept simple too. Three regulators are used to supply power to the DAC (can be reduced to one to save costs, or replace with the lower cost pin-compatible TC1015-3.3):

supply-schematic.png

An optional speaker output was desired, and the selected device was LM4861 which can run from a single low voltage supply and offers over 1W of power. This is enough to provide loud volume for home use (in the video above, the single mono speaker was a couple of meters away and the audio was played at a volume setting of 15 on mplayer). The circuit uses two of these for stereo, although only one needs fitting for mono summed speaker output (the photo above shows only one populated). The LM4861 input is driven from the headphone output, not the line output, to keep line output and headphone outputs as distortion free as possible.

speaker-amplifier.png

The speakers are muted using the LM4861 shutdown pin driven from the headphone socket built-in switch.

shutdown.png

The board was tested with headphones, a small 4 ohm speaker and a larger home speaker. Sound was as expected, and there are no known issues although more testing needs to be done. The board runs cold unless driving a speaker, in which case the LM4861 which is intended to be run without heatsinking in normal temperatures, would perhaps benefit from a tiny heatsink such as this one. The BBB image that I used outputs 16-bit audio at 48ksample/sec (i.e. the sound is as good as a regular CD player), but the DAC will work at higher resolution and sample rates for those with recordings that would benefit from it. The board was tested on an older Angstrom image and a Debian image. There are discussions in the comments section in the earlier post describing current ongoing exercises to get drivers working for different settings.

 

Summary

The described circuit is low cost and provides hopefully nice performance. The complete schematic and parts list is attached.