1 / 105

Hands on Beaglebone

Hands on Beaglebone. Introduction on beaglebone Using it’s IO and interface Work as web server. Hardware introduction CPU spec What’s on beaglebone: Interfaces Software came with the board and others SW has been developped on beaglebone Make a original SD card PC environment set up

wilda
Download Presentation

Hands on Beaglebone

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hands on Beaglebone Introduction on beaglebone Using it’s IO and interface Work as web server

  2. Hardware introduction • CPU spec • What’s on beaglebone: Interfaces • Software came with the board and others • SW has been developped on beaglebone • Make a original SD card • PC environment set up • Fist program on beagle • How beaglebone IO is organized • Pins muxing • Mmap and Files • Using Script languages • Using Python on beaglebone. • Python libraries on beaglebone • Enviroment set up • Install PyBBIO • Edit through WinSCP • digital pins • Read ADC • Using UART port • PWM • Web server • Reference

  3. A. Hardware introduction • Main feature on the CPU itself: • The CPU on beaglebone is a truly powerful 720Mhz processor based on the ARM cortex-A8 • Strong graphic support with SGX530 Graphics Engine support OPENGL ES 2.0 • Integrated LCD controller • Real-Time Clock (RTC) • Up to Two USB 2.0 High-Speed OTG Ports with Integrated PHY • 10/100/1000 Ethernet Switch Supporting Up to Two Ports • Two Controller Area Network Ports (CAN) • Six UARTs, Two McASPs, Two McSPI, and Three I2C Ports • Up to Three Enhanced High-Resolution PWM Modules (eHRPWM) • Up to Four Banks of General-Purpose IO (GPIO), 32 GPIOs per Bank (Multiplexed with Other Functional Pins) • Crypto Hardware Accelerators (AES, SHA, PKA, RNG)

  4. On beaglebone: • Peripherial chips are added to make the board more handy to use. • 256MB DDR2 @ 400MHz • TPS65217 power management IC • USB hub • Ethernet phy • Micro SD slot • Four Green LEDs that can be controlled via the SW by setting GPIO ports • 2 46 pins expansions header (2.54): • LCD • GPMC bus(memory controller) • MMC1 • SPI x2 • IIC x2 • UART x4 • ADC(1.8V max) • GPIO x 66 • CAN Bus x2 • Timer output x4 • PWM x 8 • All IO are 3.3V except ADC is 1.8V

  5. Summary • Beaglebone is powerful for even android 4.0 system. • Beaglebone have necessary interface for embedded applications, covering most interfaces of common MCU. • 3.3V interface make it easy to connect with most sensors. • Full Ethernet capability make your system on line. • USB host provides wider interfaces( mouse/keyboard/USB web cam) • By the power of CPU, visual analysis is easy on beaglebone. • USB debug interface: no need for special tool. • If powered by USB only, cpu runs at 500Mhz

  6. B. Software came with the board and some others Beaglebone is an open sourced hardware, widly supported by several open source organization, serverail OS is ported on beaglebone. On the micro SD card comes with beaglebone, there is a Angstrom distribition linux. http://www.angstrom-distribution.org/ Angstrom linux distribution is specilized for embedded device, beaglebone releated release: http://downloads.angstrom-distribution.org/demo/beaglebone/ TI also support an linux on beaglebone: Sitara Linux Software (http://processors.wiki.ti.com/index.php/Sitara_Linux_Software_Developer%E2%80%99s_Guide) TI also support Android on it’s A8 process, including beaglebone. Currently upto 4.0.3 http://software-dl.ti.com/dsps/dsps_public_sw/sdo_tii/TI_Android_DevKit/TI_Android_ICS_4_0_3_DevKit_3_0_1/index_FDS.html Rowboat is an organization supports android on TI AM335x, AM35x, AM37x process, which included beaglebone, currently upto 4.11 http://code.google.com/p/rowboat/ Win CE has also been ported to beaglebone.

  7. Make a original micro SD card before starting: • This is normally done in ubuntu PC, like angstrom stated in the page: : http://downloads.angstrom-distribution.org/demo/beaglebone/ • But it’s also possible to work this out in windows: • Prepare a micro SD or SD card reader, and install the driver correctly under windows.(Please choose a reliable card reader, some cheap card reader can cause error while writing to micro SD card) • Prepare a micro SD card at least 4GB, we recommand Sandisk class 4 or class 6. (same reason as selecting SD card, and class 10 won’t be better than class 4 or 6) • Since files are mostly zipped, 7-zip is recommanded. • Download Win32 DiskImager (also known as the win32-image-writer) • If you are using an old SD card, you will need tool to erase the SD card, “HP Formatting tool” is recommanded and can be down loaded from these loations: • HP Format Tool Ver 2.18 http://www.pcworld.com/downloads/file/fid,64963-page,1/description.html • HP Format Tool Ver 2.18 http://files.extremeoverclocking.com/file.php?f=197 • HP Format Tool Ver 2.18 http://hp-usb-disk-storage-format-tool.software.informer.com/ • HP Format Tool Ver 2.0.6 http://www.4shared.com/rar/9mNWV4Vl/HP_USB_Disk_Storage_Format_Too.html • Down load the image of original one:From 12/18/2012 onward BeagleBone boards revision A6A are shipped with 11-22-12 release, can be found here: http://circuitco.com/support/files/BeagleBone-A6A/BeagleBone_Rev_A6A_Production_11_22_2012.7z

  8. Unzip the compressed image file with 7-zip. Run the HP formatter tool and format the SD card for FAT or FAT32 in order to remove partition from the card.(in windows 7 run this in adminstrator mode) After formated the SD card, close the formatter tools and start the Win32DiskImager. Select the decompressed image file and correct SD card location. MAKE SURE YOU SELECT THE CORRECT LOCATION OF THE SD CARD. Click on 'Write'.  After the image writing is done, eject the SD card, now we can put the card into beaglebone to see if every thing works.

  9. Summary • Beaglebone cames with Angustrom linux, which was made for embedded system. • You may also run Ubuntu,Android or WIN CE. • Amgustrom release including lot of tools such as GCC compliers, Vim editor and some other tools we used in a common linux system. • Opkg is used to manage the update and upgrade tools. • It also comes with support to script languages, such as Python and bone script, Java script. • Cloud9 IDE is also installed as a online programming tool.

  10. C. PC enviroment set up The enviroment on PC for developing beaglebone is not necessary to be Linux(Ubuntu..etc), Mac and windows are also good for developping applications on beaglebone. Here after we will use Windows as example. 2 programs is recommand to be installed: • A terminal, since windows has no longer hyper terminal with it, we recommand using PuTTY, it’s free and open sourced, easy to use. Can be down load here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html it’s a exe file, no need to run installation, just click on it to run. • File transfer tool: WinSCP, This is a graphic interface file transfer client(yes, there is a server on beaglebone) for windows support various protocols through ethernet. Can be down load here: http://winscp.net/eng/download.php Unless you wish to make a custom linux on beaglebone, other wise, above tools is enough for developping applications on beaglebone. USB connection and ethernet connection will be used in following pages. So you will need a router to connect beaglebone and PC.

  11. Summary • There are several ways of programming on beaglebone, you can use the on board IDE cloud 9. Using Vi or Vim editors and use gcc complier to comple and run program directly on beaglebone. In this case, you only need a terminal to login beaglebone’s angstrom linux to do above things. • How ever, windows interface will be easier for us to work, WinSCP will take care of transfering file between PC and beaglebone, you can also install a prefered editor as you prefered.

  12. Fist program on beagle • Connecting beaglebone on USB make sure the micro SD card is correctly inserted. Use the provided USB cable to plug BeagleBone into your computer. This will both power the board and provide a development interface. BeagleBone will boot Linux from the provided microSD card and operates as a flash drive. This provides you with a local copy of the documentation and drivers. 2. You'll see the PWR LED lit steadily. Within 10 seconds, you should see the USR0 LED blinking in a heartbeat pattern. During accesses to the SD card, you should see the USR1 LED turning on. 3. From version A5 and later version, there is no need to install extra USB driver. The FTDI USB driver should be already included in windows. In case your does not have it, you can down load it here: http://www.ftdichip.com/FTDrivers.htm

  13. 4. Windows will install the drivers, it will show up 2 USB devices, one is a flash drive, one as VCP(virtual com port) which can be seen under device manager. Note the comport Nr, we will need it later. If you don’t see the drive, check the LED status, SD card,USB cable, and press reset button.(small black one next to ethernet connector.)

  14. 5. Open the drive appears as “BeagleBone Getting Started. in the Doc/hardware folder, there are reference manual, schemtic, pcb files, BOM..etc. reference manual is quite helpful, you can make a copy on your PC. In the Drivers are the beaglebone drivers for different system.

  15. 6. Open the README.htm with browser(beaglebone web recommand something else than IE), you will see a page contains most useful info, links.

  16. 7. Open your PuTTY, select “Serial” in the connection type. Then typing the COM number your beaglebone appear in device management. Set speed to 115200. You can save the session, same beaglebone on same PC normally has the same COM number. Then hit the Open.

  17. 8. When PuTTY started, you may have black terminal, simply hit “Enter”, the login screen will appear. Type “root”, press “enter”(no password), wait a second, you are now login as root. Knowing some simple linux commands is usful: “ls” will show folders “cd” change dir “cd ..” upper dir “clear” you know it

  18. From here you can operate your beaglebone as a linux PC, for example, type in “Vim” and press “Enter”, you can get into the editor. You will find it’s not that friendy to use, unless you have been trainned for this kind of command type editor. We are going to take another way. Connecting beaglebone through ethernet.

  19. Connecting Beaglebone to router Connect beaglebone to router which has internet access.(without internet access will not hurt at this moment.) Make sure the router has DHCP service and giving IP to beaglebone.

  20. There are 2 ways to know the IP of beaglebone. Logging into your router and check the DHCP table, and find the IP of beaglebone. Use PuTTY to login beaglebone through USB, type “ifconfig” and press enter. You will see the eth0 got an IP from your router.

  21. Open your broswer, typing the address of your beaglebone, 192.168.1.56 in the example, it will lead to a 20 slide Beagelboard 101 presentation. Which can be viewed by pressing page up and page down.

  22. The beagle101 along may not be clear for beginning beaglebone, but there are some very useful pages such as expansion header state. So it’s recommanded to go through the 101 for a quick look

  23. Cloud9 IDE In the broswer, open port 3000 with your beaglebone address, in our example 192.168.1.56:3000 Could 9 is running on beaglebone, and doing better by adding more examples and helps. It supports bonescrpt and node.js. This script IDE largely simplified programming on a linux beaglebone. We will experience with blinking a LED.

  24. Click on the blinkled.js and the code will display on the right. If you have been playing with Arduino, you will find the codes are so similar. This code will blink the user LED3 and pin P8_3 In page 10 of beagle 101, there is a note on how to connect a LED on P8_1 Press the “debug” on the top, wait a while, you will see the led besdie the reset button start to blink. Press “STOP” can stop the program.

  25. Summary: After seeing this demo, you image how easy to program a 720Mhz ARM? Even simpler than a MCU? Well. That’s the target, bone script is not yet there to fill up all your imagnations. But you can see there is digital input, digital output, analog input and even a server examples. The idea of TI is to make beaglebone programming as simple as Arduino. In real world of embedded linux, blink a led is some how more complicate than defind pin, set pin mode and write pin high or low. We will explan on this later. But the potential of runnung script on embedded system will largely decrease the difficulty of writing a application program on embedded linux. We will see more with python. You will find out programming a 720Mhz beaglebone is not that difficult.

  26. How beaglebone IO is organized We have seen the simplicity of bonscript to blink the LED. But accessing a GPIO in a embedded linux system can be relatively complicate. Pin muxing refereing to Beaglebone System Reference manual 6.13(page 54), here it explains on those pins on header P8, you can see some pins are marked as timer, some are UART and some are GPIOs. These are the dafult setting on the Angustrom linux. Saying default means there are some other options. Yes, like some MCUs, a pin can have various functions depends on how you set up the usage in specific registers. Here with the angustrom linux on beaglebone, there are 8 possbilities(not every pin has 8 modes), called pin muxing. Unlike the MCU, the pin muxing here is SW related, not decided by the hardware. So, different linux could have different pin muxing. The developers of the Angstrom Linux image on the SD card selected their defaults to be the most commonly used ones by hobbyists, providing a good out-of-the-box experience. It’s possible to change the mux setting, since it’s control by linux, you may find them in the U-Boot configuration and some kernel modules, which is a very complicated job. fortunately it can be done another way with today’s linux.

  27. Pin muxing table are table 9 and 10 for P8 and table 12 and 13 for P9 in the beaglebone reference manual

  28. Mmap and files The Mmap stands for memory mapping, which is a technic used by linux, http://linux.die.net/man/4/mem it makes a mapping of entire physcial memory as files under /dev/mem The BeagleBone is built around the TI AM3359 ARM Cortex-A8 microprocessor, and breaks out many of its I/O pins to two 2×23 pin female headers, including 4 UART ports, 7 ADC inputs, 4 PWM outputs, a whole bunch of GPIO pins and more. The use of these peripherals is very well documented in the AM335x Technical Reference Manual. The use of each module is done through reading and writing to different 16- and 32-bit memory registers, whose addresses are given in the manual. A Unix mmap can be used to create a memory map of the /dev/mem file, which allows read and write access to it through byte addressing. This way the module registers may be accessed by their addresses in section 2.1 of the AM335x reference manual. The most basic module to use is the GPIO module. Other modules get more complicated, but they are all very well documented in the Technical Reference Manual. The biggest difference is that many of the other modules have clocks which must be enabled before they can be used. This is done using the clock module registers, and is described in detail in chapter 8. Config of pins can be done through writing a file, changing a pin status or getting data from pins can also be done through reading specific file.

  29. Knowing the principal, let’s take a look on how bonescript handle these blinking LEDs. Maybe you are not familiar with linux file commands, it doesn’t matter, here we wish you know the basic. Go back to the cloud9 and open the file in bonescript/node_modules/index.js

  30. This table contains 3 important pieces of information: the label that bonescript uses to identify the pins (P8_1, P8_2, etc) the GPIO pin number (P8_3 is gpio1+6, or 38) the mux label (P8_3 is gpmc_ad6) The GPIO pin number tells you the directory name you will use to read from or write to the pin.  The mux label tells you the filename you will use to read or write the mux setting. Also open the file index.js, where the libraries of bonescript are: At the line 145(this could be different in different version, with the angustrom of beaglebone A6A version it’s lin 145, you may reach by seraching pinMode), here pinMode function take care of pinmuxing, line 150 and 151 shows you the files this function is writing to or reading from: var muxFile = '/sys/kernel/debug/omap_mux/' + pin.mux; var gpioFile = '/sys/class/gpio/gpio' + pin.gpio + '/value'; Line 179 you see it wirte a 0x07 to the file of pin mux: pinData |= (mux & 0x07); try { var fd = fs.openSync(muxFile, 'w'); fs.writeSync(fd, pinData.toString(16), null); }

  31. Some where lower in the line 236 you can find the digitalWrite, which bonescript used to write GPIO: digitalWrite = exports.digitalWrite = function(pin, value, callback) { var gpioFile = '/sys/class/gpio/gpio' + pin.gpio + '/value'; if(pin.led) { gpioFile = '/sys/class/leds/beaglebone::' + pin.led + '/brightness'; } if(callback) { fs.writeFile(gpioFile, '' + value, null, callback); } else { fs.writeFileSync(gpioFile, '' + value, null); } return(true); } Notice that the user led is a seperated file, as we explained, pins are SW related and can be arranged.

  32. You can see it’s actually writing a value in to the gpioFile, but which one? The code to set that “path” property also in index.js, just below where the pin mux setting was done lin 207. The first thing it does is try to write to a file named “export”, specifically , “/sys/class/gpio/export”.  The value written is the GPIO pin number, which you’ll recall was specified in the table earlier in index.js.  For Port 8 Pin 3, it was defined as gpio1+6, or 38. The export file is a funky weird file: when you write a pin number to it, it (well, the kernel process which monitors that file) creates a directory and a bunch of files that provide interfaces for accessing the pin.  The directory is created at/sys/class/gpio/export/gpioNN. In the case of Port 8 Pin 3, that’s/sys/class/gpio/export/gpio38. For the purpose of using a GPIO pin, the two most important files in the gpioNN directory are named direction and value.

  33. The direction file determines whether the pin is going to be used for reading or writing.  As mentioned earlier, you can’t use a pin for reading without setting flipping a bit in the mux mode setting, so our only choice at this point is output.   The bonescript code writes the value “out” to the direction file (i.e. to /sys/class/gpio/export/gpio38/direction). The code then saves the path to the value file (i.e. /sys/class/gpio/export/gpio38/) in the pin’s path property. This is what this line does: fs.writeFile(gpioFile, '' + value, null, callback); It writes a 1 to the value file (i.e. /sys/class/gpio/export/gpio38/value) to set the pin high (and the turn the LED on) and a 0 to set it low (and the LED off). Beside these, bonescript also handle errors. That is what we saw below the catch(ex)

  34. Summary • We have saw the basic structure of beaglebone’s IO, and how it’s operated under linux using the technic of memory mapping. • To make a interface function as we used to use in MCU, it required more understanding on how linux is operating, which still make the process relatively complicate. • Fortunately these days script languages developped at speed of rocket. Using script language can largely reduce the effort, and leave developper to focus on their creation.

  35. Using Script language Of course you can use C or C++ for programming an embedded linux, it has been done before, but required lots of works. We have demostrate how to make a pin works as GPIO without using script. And you also saw at beginning how easy it was to do the samething in bonescript. the words “script language” is something very difficult to translate into chinese, here is a descript on it: “ A high-level programming language that is interpreted by another program at runtime rather than compiled by the computer's processor as other programming languages (such as C and C++) are.” Yes, script language is running on a runtime. Program can run faster if written in C or C++, but the development and progress will take much more time than script language. Another advantage of using script language is that most of script languages have lots of libraries or functions shared between users. Which preventing from doing repeated work. And in most of case, with certain conditions, script language provide cross platform ability. For example Python program can work on windows, Mac OS, linux system even android. But hardware dependance still exists, for example, using uart on windows will have different configuration than using it on beaglebone. The angustrom linux on beaglebone has already Python 2.7 on it, and there are good libraries for using beaglebone’s IO. Here after we will start some real hands on with python on beaglebone.

  36. Summary • Script language has several advantages: • Faster programming • Functions and library sharing • Possibility of crossing plat form • Easy to use for web application

  37. Using Python on beaglebone Before going depper on Python,let’s start with some partice on terminal, get your beaglebone linked with PC through USB and log in to beaglebone with PuTTY: Type in after # python –V and hit enter, it will reply Python 2.7.2 , which is the version of python.There is Python 3.x already, but 2.7 and 3.x are some how different on some functions.

  38. Key in python and hit enter, you will see a prompt as “>>>”, this is the python prompt. Under this prompt we can execute python command. Following picture shows a simple math. It seems like the old basic, but script language can do much more then is. Type in quit() will stop python. You can also use editor to make a file with extension “.py” and execute it with python xxx.py

  39. It’s recommand to get a book for much better python. It’s not easy to find books talk about python in chinese, here in Taiwan. Here we list 2 translation publish, for your reference: Head First Python(深入淺出 Python)O’REILLY 基峯資訊 Programming in Python (精通 Python)基峯資訊 Althoughit’sgoodtohaveabookonhand,butgoogleisalsoaveryhandytoolwhenlearningscriptlanguage.Thereareplentytutorialonnet,ifyoucan’tanansweronnet,itwouldbealsohardtofindagoodanswerinbooks. Remember,thesedays,programmingmostopensourcestuffisnotaboutonlygettingreferencefromothers,participationondiscussionandshareyourworkswithothersarealsoimportant.Afterall,thisiswhywecanprogresstogetherandfaster. Python has also a systematic way to share codes between users, PyPI. We may not be skilled enough to create a useful library now, but please bear in mind, sharing is an important factor in progressing.

  40. Pythonlibrariesonbeaglebone • Mostofscriptlanguagesonbeagleboneusethememorymapping(mmap)inlinuxsystem.Thereareserveralprojects: • Bonescrpt using javascript(node.js) • PerlBone using Perl • Rbone using Ruby • Hwio usig Golang • beagleboneIO and beaglebone-CLIB using C • pyBBIO, mrBBIO and beaglelib using python • Some others… • All these are open sourced projects, I choose pyBBIO for my python experience on beaglebone, since the documentations are pretty clear, examples are not complicate and easy to use. Owner is intend to make the programming of beaglebone as similar as a MCU programming(arduino precisly). And most important, Owenr (Alexander Hiam ) keep on updating the library. This will make the library getting strong and complete. The library cover today from GPIO to web server, although SPI and IIC is still on the way, but you can already make amazing things with your imagination.

  41. Enviroment set up we are going to do this programming in windows, the hardware connection is as following. Windows PC

  42. you should have now PuTTY installed on your PC, we now need a file transfer tool which we have introduced previously WinSCP, download and install it. This tool is open source and have multi language version. For traditional chinese: http://www.azofreeware.com/2008/03/winscp-41-beta.html remember how to get beaglebone IP address using PuTTY to log in as root? After log in, use ifconfig. Note down the eth0 IP adress(192.168.1.56 in this example)

  43. Open your WinSCP type in the IP address of your beaglebone, user is root, leave the password blank. For the first connection, windows will pop up an warning, reply yes to approve the connection.

  44. winSCP will locate the server on beaglebone, and log in as root. When password window pop up, leave the pass word blank and press yes. The default pass word is blank, if you wish you can add some other users and log in as other users with password. Which is as same as linux, using command as # useradd user1 # passwd user1 Then system will ask you to input 2 times of password. You can also add password to current root. #passwd And to input 2 times of password

  45. Then you will see the WinSCP window as below: on the right is the file system on beaglebone, left is the one of your PC. We will constantly use PuTTY and WinSCP these 2 windows.

  46. Once setup, the last thing is to make sure that your beaglebone has access to internet. To make sure it, you can ping a website. Google.com is what I used to use. Using PuTTY and type in ping google.com Then beaglebone is keeping pinging google.com, you can use Ctrl-C to stop it.

  47. WinSCP has a built in editor, it also allow you to use you selection of editor. I’m using a GNU editor Emacs (http://www.gnu.org/software/emacs/) To add editor in to WinSCP, first install the editor of your choise on your PC. And find out where is it’s exe program. In WinSCP, under option/preference windows, select editors on the left side. Select add. Then select external editor and give the path of the exe file of the editor. You may also set the editor with releation to extension file name.

  48. Install pyBBIO Make sure your beaglebone is up and connected to internet as previous descript. Log in as root through PuTTY. pyBBIO is a library of python on beaglebone, it use the technic of memory mapping, it also use other libraries of python, such as python-distutils(distribution utilty for update), python-mmap and python-pyserial, so the 1st step is to install these parts: Type in following command after #: # opkg update && opkg install python-distutils python-mmap python-pyserial It will start to down load from internet and install it, at the end you should see it’s configuring and back to prompt #

  49. Then we will get the code from net: # cd ~ # git clone git://github.com/alexanderhiam/PyBBIO.git The whole file system will be down loaded(cloned) to your beaglebone. You can use windows copy and past on PuTTY, copy the command from other windows, move to PuTTY, right click, the command is already on, then press enter.

  50. After it’s done, type in # ls which is a list command, you will see there is a PyBBIO floder. Now we are going to install it: Change to PyBBIO dir: # cd PyBBIO The ls (ls), you will see a setup.py, .py is the extension file name of python file. Type in the following, this is normally how python program installed. # python setup.py install It should be correctly install as following pic

More Related