Saturday, December 21, 2013

Beaglebone Black GPIO - 8x8 LED Matrix with C Program - Part3

STEP-4 : Setting up the Start-up Script and make active at boot-up

  • In order to work with device tree overlay what we have created in previous step, we need to write a start-up script.
  • The C code we are going to use is have some issues with GPIO ports like "Bus Error" when the compiled file is executed.
  • Based on this website the issue got resolved when we export one pin on each GPIO port. So this we need to add it on start-up script.
  • This start-up script will be executed every time the Beaglebone Black is started.
  •  Make a start-up script with the following steps:
       root@beaglebone:# vi /usr/bin/init_boot.sh
   
        Copy and Pase following lines in "init_boot.sh" file - Download

 #!/bin/bash
echo 5 > /sys/class/gpio/export

echo 33 > /sys/class/gpio/export

echo 65 > /sys/class/gpio/export

echo 115 > /sys/class/gpio/export

export SLOTS=/sys/devices/bone_capemgr.8/slots

echo GPIO-Test > $SLOTS

  • To save and exit the file press "Esc" type ":wq" and Enter.
  • Now start-up script is ready to make active at booting process.
  • To make start-up script active at booting process, make a service with the following lines:
      root@beaglebone:# vi /lib/systemd/init_boot.service

[Unit]
Description=Enable GPIO Pins
After=syslog.target network.target

[Service]
Type=simple
ExecStart=/usr/bin/init_boot.sh

[Install]
WantedBy=multi-user.target


  • To save and exit the file press "Esc" type ":wq" and Enter.
  • Make a symbolic link

    root@beaglebone:# cd /etc/systemd/system/
    
root@beaglebone:# ln /lib/systemd/init_boot.service init_boot.service

  • Make systemd take notice of it, activate the service immediately and enable the service to be started on boot-up
   root@beaglebone:# systemctl daemon-reload
  
root@beaglebone:# systemctl start init_boot.service   
   root@beaglebone:# systemctl enable init_boot.service
  • Now the start-up script is active.
  • To check whether start-up script is active restart the beaglebone black.
  • Run following commands:
    To check GPIO pins 5, 33, 65 & 115 are exported:
   root@beaglebone:# ls -al /sys/class/gpio

root@beaglebone:# ls -al /sys/class/gpio/total 0
drwxr-xr-x  2 root root    0 Jan  1 05:00 .
drwxr-xr-x 48 root root    0 Jan  1 05:00 ..
--w-------  1 root root 4096 Jan  1 05:00 export

lrwxrwxrwx  1 root root    0 Jan  1 11:30 gpio115 -> ../../devices/virtual/gpio/gpio115
lrwxrwxrwx  1 root root    0 Jan  1 11:30 gpio33 -> ../../devices/virtual/gpio/gpio33
lrwxrwxrwx  1 root root    0 Jan  1 11:30 gpio5 -> ../../devices/virtual/gpio/gpio5
lrwxrwxrwx  1 root root    0 Jan  1 11:30 gpio65 -> ../../devices/virtual/gpio/gpio65
lrwxrwxrwx  1 root root    0 Jan  1 05:00 gpiochip0 -> ../../devices/virtual/gpio/gpiochip0
lrwxrwxrwx  1 root root    0 Jan  1 05:00 gpiochip32 -> ../../devices/virtual/gpio/gpiochip32
lrwxrwxrwx  1 root root    0 Jan  1 05:00 gpiochip64 -> ../../devices/virtual/gpio/gpiochip64
lrwxrwxrwx  1 root root    0 Jan  1 05:00 gpiochip96 -> ../../devices/virtual/gpio/gpiochip96
--w-------  1 root root 4096 Jan  1 05:00 unexport

   To check the device tree overlay is loaded:
   root@beaglebone:# cat /sys/devices/bone_capemgr.8/slots

 root@beaglebone:/lib/firmware# cat $SLOTS
 0: 54:PF---
 1: 55:PF---
 2: 56:PF---
 3: 57:PF---
 4: ff:P-O-- Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
 5: ff:P-O-- Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
 6: ff:P-O-- Bone-Black-HDMIN,00A0,Texas Instrument,BB-BONELT-HDMIN
 7: ff:P-O-L Override Board Name,00A0,Override Manuf,GPIO-Test

  • It is loaded on 7th slot. 
STEP-5 : Proceed for C code
  • Download C Coded from Here

Beaglebone Black GPIO - 8x8 LED Matrix with C Program - Part2


STEP-3 : Setting the Pin mux and enabling the pullup or pull-down resistors on Port_8
  • With the help of Device tree overlay we can set the pin mux and enable the pullup or pulldown resistors.
  • Make a device tree overlay file with the following code:
//---------File Name:GPIO-Test.dts---------------
/dts-v1/;
/plugin/;

/{
       compatible = "ti,beaglebone", "ti,beaglebone-black";
       part-number = "GPIO-Test";
       version = "00A0";

       fragment@0 {
             target = <&am33xx_pinmux>;
           
             __overlay__ {
                  pinctrl_test: GPIO_Test {
            pinctrl-single,pins = <

                0x018 0x07 // P8_3 38 OUTPUT MODE7 pulldown
                0x01c 0x07 // P8_4 39 OUTPUT MODE7 pulldown
                0x008 0x07 // P8_5 34 OUTPUT MODE7 pulldown
                0x00c 0x07 // P8_6 35 OUTPUT MODE7 pulldown
                0x090 0x07 // P8_7 66 OUTPUT MODE7 pulldown
                0x094 0x07 // P8_8 67 OUTPUT MODE7 pulldown
                0x09c 0x07 // P8_9 69 OUTPUT MODE7 pulldown
                0x098 0x07 // P8_10 68 OUTPUT MODE7 pulldown
              
                0x034 0x17 // P8_11 45 OUTPUT MODE7 pullup
                0x030 0x17 // P8_12 44 OUTPUT MODE7 pullup
                0x024 0x17 // P8_13 23 OUTPUT MODE7 pullup
                0x028 0x17 // P8_14 26 OUTPUT MODE7 pullup
                0x03c 0x17 // P8_15 47 OUTPUT MODE7 pullup
                0x038 0x17 // P8_16 46 OUTPUT MODE7 pullup
                0x02c 0x17 // P8_17 27 OUTPUT MODE7 pullup
                0x08c 0x17 // P8_18 65 OUTPUT MODE7 pullup
              
              
                      
                    /* OUTPUT  GPIO(mode7) 0x07 pulldown, 0x17 pullup, 0x?f no pullup/down */
                   /* INPUT   GPIO(mode7) 0x27 pulldown, 0x37 pullup, 0x?f no pullup/down */

            >;
          };
             };
       };

       fragment@1 {
        target = <&ocp>;
        __overlay__ {
            test_helper: helper {
                compatible = "bone-pinmux-helper";
                pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_test>;
                status = "okay";
            };
        };
    };
};



  • Save file with is name "GPIO-Test.dts",
  • Compiling the overlay from .dts to .dtbo  
       root@beaglebone:# dtc -O dtb -o GPIO-Test-00A0.dtbo -b 0 -@ GPIO-Test.dts

  • Now you need to copy it to /lib/firmware so it can be found.
      root@beaglebone:# cp GPIO-Test-00A0.dtbo /lib/firmware
  • We need to define SLOTS to make it active
      root@beaglebone:# echo SLOTS=/sys/devices/bone_capemgr.8/slots
  •  Finally to make it active in SLOTS
      root@beaglebone:# echo GPIO-Test > $SLOTS
  • You can check with following command
 root@beaglebone:/lib/firmware# cat $SLOTS
 0: 54:PF---
 1: 55:PF---
 2: 56:PF---
 3: 57:PF---
 4: ff:P-O-- Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
 5: ff:P-O-- Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
 6: ff:P-O-- Bone-Black-HDMIN,00A0,Texas Instrument,BB-BONELT-HDMIN
 7: ff:P-O-L Override Board Name,00A0,Override Manuf,GPIO-Test

  • It is loaded on 7th slot.
  • You can download HERE the file created by me
  • You can modify and make your own device tree overlay with this file "GPIO-Test.dts" (Open file in text editor like)
                                                     Further info  See Part3 - To be Continued

Thursday, December 19, 2013

Beaglebone Black GPIO - 8x8 LED Matrix with C Program - Part1

I made an 8x8 LED matrix circuit to work with GPIO pins on Beaglebone Black.

STEP-1 : Make LED matrix board with the following circuit:

Components Required:
1. Breadboard PCB or General PCB - 01
2. 3mm RED LED's - 64
3. 330 Ohms Resistors - 08
4. Male/Female Header - 01
5. Male/Female Jumper wires - 16
Note: If you don't want to make circuit you can use a standard 8x8 dot matrix module buy from local electronic shops or buy online.

Beaglebone Black: Connect all ROWS to Port_8 on  Pins 11 to 18 and all COLUMNS to Port_8 pins 3 to 10 using Jumper wires.

This application is tested on Beaglebone Black running Angstrom OS

Note: To use these GPIO pins you need to disable onboard emmc and HDMI port. 

STEP-2 :Disabling on-board emmc and HDMI port:
  • Connect Beaglebone Black to PC with USB cable. wait for storage media to initialize.
  • Go to My Computer and open "BEAGLEBONE" storage media.
  • Navigate the file "uEnv.txt" and open in text editor.
  • Paste this following line:  
 optargs=quiet capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN,BB-BONE-EMMC-2G 


  • Save & Close the file, restart Beaglebone
                                                                                                See Part2 - To be Continued

Tuesday, December 3, 2013

How to get the BeagleBone Black Drivers to work on Windows 8 computer

To install the drivers, the windows 8 computer needs to be restarted in the mode where it allows you to install unsigned drivers.

Here's a quick step-by-step guide:

1. Press win+c on the keyboard to bring up the charms side bar (or move mouse to right top corner of the screen)

2. Click the Settings button.

3. Click the Change PC Settings at the bottom of the sidebar.

4. On screen that shows up, select the General option from the sidebar then scroll down the page that appears.

5. Click the Restart now button under the Advanced startup section.

6. You will momentarily see the restarting screen, then it will switch to a blue screen titled "Choose an option"

7. Click the Troubleshoot button.

8. Click Advanced options.

9. Click Startup Settings

10. Click Restart

11. You should then see a Startup Settings screen after your computer reboots.

12. Press 7 or F7 on your keyboard to Disable driver signature enforcement

13. Now Windows 8 will continue starting up.

14. For Windows 8 64-bin: Log-in as normal, and then run BONE_D64.exe again (Click on Link to download)

15. For Windows 8 32-bin: Log-in as normal, and then run BONE_DRV.exe again (Click on Link to download)

16. Now you should see 4 warning dialogs about "unsigned driver installation", click OK for all of them.


Courtesy: elinux.org