Ananth's Blog - page 9

Posts

Getting started with GPIO (Testing GPIO with a multimeter)

There are 65 possible GPIO pins that you can control. Some of the GPIO pins are normally configured to different functions. Let's play with one of them.

Go to the beaglebone website and figure out the header pin corresponding to gpio23.


The gpio23 is mapped to the 13th header pin. In this tutorial we are testing the gpio23 output using a multimeter (Do not connect an LED directly to BBB IO pin).

First go to following directory

cd /sys/class/gpio/

Then make gpio23 available

echo 23 > export

A new directory will be created. Open gpio directory.

cd gpio23

The direction of IO will be normally set as in (input).  To make it as output,

echo out > direction

Then set the pin to high using

echo 1 > value

Measure the voltage at pin 13 of P8 header. If its 3.3 V then you are on the right track. Pin 1 and 2 will be ground. You can connect the negative terminal of multimeter to pin 1 or 2.

To set output as zero,

echo 0 > value

After finished with the tutorial unexport the gpio23 pin.

cd ..
echo 23 > unexport

To get a better idea refer this site.

BeagleBoneBlack apt-get upgrade error due to led-aging.sh

When I try to upgrade my new BBB bought from element14 (4gb emmc) it throws a list of errors.

stem facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv:  loop involving service mountkernfs at depth 1
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting led_aging.sh depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: exiting now without changing boot order!
update-rc.d: error: insserv rejected the script header
dpkg: error processing ppp (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 rsyslog
 apache2.2-common
 apache2-mpm-worker
 apache2
 dbus
 dbus-x11
 hostapd
 openssh-server
 ppp
E: Sub-process /usr/bin/dpkg returned an error code (1)


The error was due to a file led-aging.sh. I found the solution from here. (By Dirk Koopman)

Edit the file

nano /etc/init.d/led_aging.sh

and replace the contents with

#!/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 run

apt-get upgrade

again. It will solve the issue.

Getting internet on BBB via usb (Share internet from your linux machine)



Login to your BBB and type

route add default gw 192.168.7.1

Then type the follwing in your linux machine to route the network.

sudo su
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface eth1 -j ACCEPT 
echo 1 > /proc/sys/net/ipv4/ip_forward


Note: eth0 is LAN interface which has internet connectivity. eth1 is the usb network connection with BBB. 192.168.7.1 is the ip address that assigned to your PC.

Following part is not needed if internet is working properly.

If you are using network that doesn't allow third party dns server (like google dns 8.8.8.8 or 8.8.4.4), you had to configure /etc/resolv.conf.

First find out what dns server address your internet provider (your college) gives you. If you have a working network type

nm-tool

to find out the dnsaddress. Then delete all the entries in /etc/resolve.conf and replace it with

nameserver <dnsaddr>

eg: nameserver 192.168.0.5

Remote access your BeagleBone Black using vnc

Before going into how to share desktop with your BBB I assume you have a proper ssh access to your BBB. (through USB) (if not read this) Also this tutorial is for BBB with Debian installed (type cat /etc/*-release to know which distro you are currently using. Or refer here)

First install the vnc server in BBB.(After logging into BBB)

ssh root@192.168.7.2
apt-get install x11vnc

Then go to your local computer and open a terminal window. Install a vnc viewer like vinagre.

sudo apt-get install vinagre

Now its time to start vnc server in BBB.

x11vnc -auth /var/run/lightdm/root/:0 -forever

This will start a vnc server at port 5900. Note this server setup is temporary. If you want to remotely connect to your BBB after a reboot type the above command again.

Go to your local computer and type 

vinagre 192.168.7.2::5900



A remote desktop will be shown if all goes well. Try exploring other options in x11vnc using (in BBB)

man x11vnc

The server that's currently running will not have any password set. So if you want to set a password or want to know more about x11vnc refer here.

Note: These descriptions are for getting started with BBB. Do not run a vnc server without any password if you are planning to deploy it directly to internet.

Program BBB using C (Blink onboard LED)

If you are familiar with linux, you may know that everything in linux is a file. You can talk to a hardware as if you are writing to a file.
There are 4 on board LEDs in BBB. You can play with that LED.

Go to /sys/class/leds/beaglebone:green:usr3/

cd /sys/class/leds/beaglebone:green:usr3/

If you write a '1' to the file corresponding to LED3, then it will light that LED. Writing '0' will switch off the LED.

echo 1 > brightness

It will switch on the LED forever. :-) If you want to switch off it again type

echo 0 > brightness

Let's do it in c.

First ssh into your BBB (refer here). Then create a directory to work with.

mkdir helloworld
cd helloworld


Open your favourite texteditor.

nano LEDBlink.c

Then type this program.


#include<stdio.h>

int main()
{
        FILE *LEDHandler=NULL;
        char *LEDPath="/sys/class/leds/beaglebone:green:usr3/brightness";
        if(LEDHandler=fopen(LEDPath,"r+")){
                fwrite("1", 1, 1,LEDHandler);
                fclose(LEDHandler);
        }
        sleep(3);
        if(LEDHandler=fopen(LEDPath,"r+")){
                fwrite("0", 1, 1,LEDHandler);
                fclose(LEDHandler);
        }

        return 0;
}

Save the program using Cntrl+O and close it using Cntrl+X.
Then compile the program using

gcc LEDBlink.c

Then run your first program.

./a.out

The program will switch on the LED for 3s and then switch off.