Sunday, October 27, 2013

Updating eMMC image

The procedure and latest production file is listed here. The process took around 40 minutes on my system.

Point to note: Power the Beaglebone Black from a 5V supply capable of at least 1A. Disconnect both USB and Ethernet cables before flashing the eMMC.

Once the updating process is complete, log into BBB through Terminal or Putty. I got this message:
aswin@aswin-Inspiron-1440:~$ ssh 192.168.7.2 -l root
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
36:75:f5:00:89:3c:7c:98:dc:bd:9e:4a:e8:3d:48:13.
Please contact your system administrator.
Add correct host key in /home/aswin/.ssh/known_hosts to get rid of this message.
Offending RSA key in /home/aswin/.ssh/known_hosts:1
  remove with: ssh-keygen -f "/home/aswin/.ssh/known_hosts" -R 192.168.7.2
RSA host key for 192.168.7.2 has changed and you have requested strict checking.
Host key verification failed.
Solution:

Go to home directory in host computer and create a config file in the below path:
cd ~/.ssh/
nano config
Type the following:
Host 192.168.7.*
    UserKnownHostsFile /dev/null
    StrictHostKeyChecking no 
Save and exit (Ctrl+X, Y, <Enter>)

SSH into the device and login as root.
ssh 192.168.7.2 -l root
Verify the new installation
root@beaglebone:/sys/class/gpio# cat /etc/dogtag
Cloud9 GNOME Image 2013.09.04

Saturday, October 26, 2013

Running a script on Beaglebone Black boot/ startup

1. Compile the required code.

2. Create a bash script that will launch the code at boot/ startup
cd /usr/bin/
Type nano <scriptname.sh>
#!/bin/bash
/home/root/<name_of_compiled_code>

Save and grant execute permission
chmod u+x /usr/bin/<scriptname>.sh
3. Create the service
 nano /lib/systemd/<scriptname>.service
4. Edit the above file as necessary to invoke the different functionalities like network. Enable these only if the code needs that particular service. Disable unwanted ones to decrease boot time.
[Unit]
Description=<description of code>
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/usr/bin/<scriptname>.sh
[Install]
WantedBy=multi-user.target
 5.  Create a symbolic link to let the device know the location of the service.
cd /etc/systemd/system/
ln /lib/systemd/<scriptname>.service <scriptname>.service

6. Make systemd reload the configuration file, start the service immediately (helps to see if the service is functioning properly) and enable the unit files specified in the command line.

systemctl daemon-reload
systemctl start <scriptname>.service
systemctl enable <scriptname>.service

7. Restart BBB immediately to see if it runs as intended.
shutdown -r now

Blink external LED on Beaglebone Black using C programming

LED connected to GPIO0_23 (P8.13) through 470 ohm resistor.
Do not use lesser value resistors in series with the LED.
GPIO0_23 means 0*32 + 23 = 23. Hence pass this value to the 'export' file.

Connect BBB to computer as explained here.
In terminal/ Putty, type nano Blink_external_LED.cpp
Paste the below code, press Ctrl+X, Y and Enter.
Type g++ Blink_external_LED.cpp -o Blink_external_LED and compile
Type ./Blink_external_LED and run

Code:
#include <unistd.h>
#include <stdio.h>
using namespace std;

int main()
{
        FILE *export_file = NULL;        //declare pointers
        FILE *IO_direction = NULL;
        char str1[] = "low";
        char str2[] = "high";
        char str[] = "23";                       //value to pass to export file
        export_file = fopen ("/sys/class/gpio/export", "w");
        fwrite (str, 1, sizeof(str), export_file);
        fclose (export_file);

for (int i=0; i<10; i++){        //blink LED 10 times
        IO_direction = fopen ("/sys/class/gpio/gpio23/direction", "w");
        fwrite (str2, 1, sizeof(str1), IO_direction);   //set the pin to HIGH
        fclose (IO_direction);
        usleep (1000000);

        IO_direction = fopen ("/sys/class/gpio/gpio23/direction", "w");
        fwrite (str1, 1, sizeof(str1), IO_direction);   //set the pin to LOW
        fclose (IO_direction);
        usleep (1000000);}

        export_file = fopen ("/sys/class/gpio/unexport", "w");   //remove the mapping
        fwrite (str, 1, sizeof(str), export_file);
        fclose (export_file);
}