BeagleBoneBlackCookbook
TableofContents
BeagleBoneBlackCookbook
Credits
AbouttheAuthor
AbouttheReviewers
www.PacktPub.com
Supportfiles,eBooks,discountoffers,andmore
WhySubscribe?
FreeAccessforPacktaccountholders
Preface
Whatthisbookcovers
Whatyouneedforthisbook
Whothisbookisfor
Sections
Gettingready
Howtodoit…
Howitworks…
There’smore…
Seealso
Conventions
Readerfeedback
Customersupport
Downloadingtheexamplecode
Downloadingthecolorimagesofthisbook
Errata
Piracy
Questions
1.SettingUpfortheFirstTime
Introduction
Firstbootup
Gettingready
Howtodoit…
Gettingready
Howtodoit…
Powerrequirements–basicguidelines
Display
ConnectinganHDMILCD
Howtodoit…
Connectinganon-HDMILCDorcape
Howtodoit…
There’smore…
EssentialGNU/Linuxcommands–thecommandshell
Gettingready
Howtodoit…
Howitworks…
EssentialGNU/Linuxcommands–typicalcommands
Gettingready
Systemnavigationalcommand–changeyourdirectory–cd
Howtodoit…
There’smore…
Systemnavigationalcommand–showyourcurrentdirectory–pwd
Howtodoit…
Systemnavigationalcommand–findafile–find
Howtodoit…
Deviceandsysteminsight–showswhat’sinsideadirectory–ls
Howtodoit…
Deviceandsysteminsight–findoutwhatUSBdevicesareconnected–lsusb
Howtodoit…
Deviceandsysteminsight–getinformationaboutconnecteddevices–
cat/proc/bus/input/devices
Howtodoit…
There’smore…
Deviceandsysteminsight–getyourversionofLinux
Howtodoit…
Deviceandsysteminsight–findoutrunningprocesses–ps
Howtodoit…
Deviceandsysteminsight–findouttheresourcesusedbyrunningprocesses–top
andhtop
Howtodoit…
Deviceandsysteminsight–quittingprocesses–kill
Howtodoit…
Deviceandsysteminsight–messagereports–dmesg
Howtodoit…
Deviceandsysteminsight–showsdiskspace–df-h
Howtodoit…
Deviceandsysteminsight–explorenetwork–Ifconfig
Howtodoit…
Modifycontent/datacommands–makeanewdirectory–mkdir
Howtodoit…
Modifycontent/datacommands–removeafileordirectory–rm
Howtodoit…
Modifycontent/datacommands–downloadfiles–wget
Howtodoit…
There’smore…
Modifycontent/datacommands–openatarfile–tar[options]
Howtodoit…
There’smore…
Modifycontent/datacommands–cleanupfiles–autoclean
Howtodoit…
Modifycontent/datacommands–purgeapackage–apt-getpurge,apt-getremove
—purge
Howtodoit…
Modifycontent/datacommands–shutdownthesystem–[options]
Howtodoit…
Seealso
Editatextfilefromthecommandshell
Howitworks…
Howtodoit…
Seealso
Connectivity
Connectivity–Ethernet
Gettingready
Howtodoit…
Connectivity–Wi-Fi
Gettingready
Howtodoit…
There’smore…
Seealso
Packagemanagement–Installingpackagesusingapt-get
Gettingready
Howtodoit…
Seealso
SSH/Remoteaccess
UsingSSHtocontrolyourBBB
Howtodoit…
UsingVNCtocontrolyourBBB
Gettingready…
Howtodoit…
There’smore…
Systemimages
OSimageflashing–internaldriveboot
Gettingready
Howtodoit…
There’smore…
Expandyourpartition
Backingupacodeimagetoafile
OSimageflashing–theSDcardboot
Gettingready
Howtodoit…
UpdatingyourcurrentOSkernel
Seealso
2.BasicProgrammingRecipes
Introduction
IntroductiontoBoneScript
ToggleLED
Howtodoit…
Seealso
UsingtheCloud9IDE
Howtodoit…
Seealso
Node.jsbasicrecipes
AddinganewmoduletoNode.js
Gettingready
Howtodoit…
There’smore…
Seealso
UsingNode.jswithJohnny-Five
Howtodoit…
There’smore…
Pythonbasicrecipes
Gettingready
Addinglibraries
Howtodoit…
RunningaPythonscripttocontroltheLEDs
Howtodoit…
There’smore…
3.PhysicalComputingRecipesUsingJavaScript,theBoneScriptLibrary,andPython
Introduction
Theessentialsofelectronics
Headerpinsandpinmuxing
Theprocessofpinmuxing
There’smore…
ControllingexternalLEDs
Gettingready
Howtodoit…
WritinganalternativescriptwithPython
There’smore…
Usingbuttons–buttonpressfunction
Pull-up,pull-down,andfloating
Gettingready
Howtodoit…
There’smore…
Usinganalogsensors
Temperaturesensors
Gettingready
Howtodoit…
There’smore…
Seealso
Variableresistancesensor–photocell
Gettingready
Howtodoit…
Usingmotors
DCmotors
Gettingready
Howtodoit…
Howitworks…
Servomotors
Acrashcourseinpulsewidthmodulation
Gettingready
Howtodoit…
There’smore…
4.ExploringGNU/LinuxRecipesUsingBash,Autotools,Debugger,andsystemd
Introduction
Thebasicshellscript
Howtodoit…
EpochTimeshellscript
Howtodoit…
There’smore…
Compileandinstall
Seealso
CompileandinstallGitfromsource
Howtodoit…
Debugging
Seealso
DebugasimpleC-codeapplicationfromthecommandlineusingGDB
Howtodoit…
Seealso
DebuganapplicationremotelyfromEclipseandGDBserver
Howtodoit…
There’smore…
systemdservices
There’smore…
Seealso
Basiccommandsforsystemdservices
Howtodoit…
There’smore…
Optimizeboottime
Howtodoit…
Createasystemdservicetorunatboottime
Howtodoit…
5.BasicProgrammingRecipeswiththeLinuxKernel
Introduction
Kernelbuildingbasics
Seealso
Kernelapplicationbinaryinterface
Gettingready
Howtodoit…
Howitworks…
Installingthelatestkernelimage
Gettingready
Howtodoit…
Installingandbuildingacustomkernel
Gettingready
Howtodoit…
Interactionswiththekernel–sysfsentriesandcontrollingtheGPIOs
Gettingready
Howtodoit…
There’smore…
DeviceTreeanditsroots
There’smore…
DeviceTree/basicbuild
Gettingready
Howtodoit…
DeviceTree/advanced–addingDToverlaytorunacustomcape
Gettingready
Howtodoit…
There’smore…
Seealso
Universalcapeoverlay
Gettingready
Howtodoit…
There’smore…
RunningascripttocheckDTusageonGPIOpins
Gettingready
Howtodoit…
6.RunFaster,RunRealTime
Introduction
Installingatesttool
Gettingready
Howtodoit…
Seealso
ModifyingthekernelusingRT-PREEMPT
Gettingready
Howtodoit…
There’smore…
ModifyingthekernelusingXenomai
Gettingready
Howtodoit…
There’smore…
Seealso
Programmablereal-timeunits–anintroduction
Gettingready
Howtodoit…
AsimplePRUtestwithanassembler
Gettingready
Howtodoit…
Seealso
RunninganultrasonicrangesensorwiththePRUs
Gettingready
Howtodoit…
UsingPythonwiththePRUs
Gettingready
Howtodoit…
Seealso
7.AppliedRecipes–Sound,Picture,andVideo
Introduction
Wiringupaminiampandspeakers
Gettingready
Howtodoit…
Creatingahigh-qualityaudioplatformwithVolumio
Gettingready
Howtodoit…
There’smore…
Seealso
Usingvideosanddisplaysinprojects
Gettingready
Howtodoit…
There’smore…
TestingaminiLCDcape
Gettingready
Howtodoit…
MakingavideochatclientprototypeusingLinphone
Gettingready
Howtodoit…
PartI–compilingandinstallingaLinphonebinaryfromtherepository
PartII–compilingandinstallingLinphonefromsource
Gettingready
Howtodoit…
8.TheInternetofThings
Introduction
Location-basedrecipes–hookingupGPS
Gettingready
Howtodoit…
There’smore…
Location-basedrecipes–BluetoothLEandBeacons
Gettingready
Howtodoit…
There’smore…
UsingsensorsanddatawithThingSpeak
Gettingready
Howtodoit…
Seealso
Makingthingssmarter–buildingawirelessdigitalpictureframe
Gettingready
Howtodoit…
Seealso
9.TheBlackinOuterSpace
Introduction
GrabbingtheInternationalSpaceStationflyoverdataandvisualizingit
Gettingready
Howtodoit…
There’smore…
TrackingusingRTL-SDR
Seealso
AirplanetrackingwithRTL-SDR
Gettingready
Howtodoit…
There’smore…
SatellitetrackingusingGPredictandRTL-SDR
Gettingready
Howtodoit…
There’smore…
SatellitetrackingusingtheSatNogsNetworkclient/groundstationandRTL-SDR
Gettingready
Howtodoit…
Addingotherinterfaces–ISStrackingandtexttospeech
Gettingready
Howtodoit…
There’smore…
Index
BeagleBoneBlackCookbook
BeagleBoneBlackCookbook
Copyright©2015PacktPublishing
Allrightsreserved.Nopartofthisbookmaybereproduced,storedinaretrievalsystem,
ortransmittedinanyformorbyanymeans,withoutthepriorwrittenpermissionofthe
publisher,exceptinthecaseofbriefquotationsembeddedincriticalarticlesorreviews.
Everyefforthasbeenmadeinthepreparationofthisbooktoensuretheaccuracyofthe
informationpresented.However,theinformationcontainedinthisbookissoldwithout
warranty,eitherexpressorimplied.Neithertheauthor,norPacktPublishing,andits
dealersanddistributorswillbeheldliableforanydamagescausedorallegedtobecaused
directlyorindirectlybythisbook.
PacktPublishinghasendeavoredtoprovidetrademarkinformationaboutallofthe
companiesandproductsmentionedinthisbookbytheappropriateuseofcapitals.
However,PacktPublishingcannotguaranteetheaccuracyofthisinformation.
Firstpublished:November2015
Productionreference:1121115
PublishedbyPacktPublishingLtd.
LiveryPlace
35LiveryStreet
BirminghamB32PB,UK.
ISBN978-1-78398-292-9
www.packtpub.com
Credits
Author
CharlesA.Hamilton
Reviewers
NathanBurles
AnujDeshpande
DeepakKarki
AgrimaSeth
CommissioningEditor
EdwardGordon
AcquisitionEditor
RichardBrookes-Bland
ContentDevelopmentEditor
RohitKumarSingh
TechnicalEditor
VijinBoricha
CopyEditor
ShrutiIyer
ProjectCoordinator
MaryAlex
Proofreader
SafisEditing
Indexer
MonicaAjmeraMehta
ProductionCoordinator
ConidonMiranda
CoverWork
ConidonMiranda
AbouttheAuthor
CharlesA.HamiltonistheownerofHudsonWerks,aNewYorkCity-basedDIY
hardwareanddevelopmentshopfornewproducts.Passionateaboutemerging
technologies,opensourcehardware,andthemakermovement,hisbackgroundasa
“technologycreative”,entrepreneur,andmakerprovidesreaderswithaunique
perspective.
BesidesBeagleBoneBlack,Charlesworksfrequentlywithotherhardwareplatforms,
includingtheRaspberryPi,Arduino,andUDOOdevelopmentboards,opensourceboard
architectureandPCBdesign,micromechatronics,andsensors.Heisalsoanadvocateand
keenuserofemerginglow-costmanufacturinganddesigntoolssuchas3-Dprintersand
lasercutters.Amongothersubjects,Charleskeenlyfollowsadvancesanddesign
challengesinthearenasofIoT,spacetechnologies,andnext-generationhealthand
wellnessdevices.Hewritesandblogsat.
HeisaformercreativedirectoratAT&TandproductdeveloperataNewYorkCity-based
newproductdevelopmentagency.Charles’developmentexpertisespansdevicesinthe
consumerelectronics,digitalmedia,display,voicerecognition,andtelecommunication
markets.Heisalsoaproudpapatohis4-year-oldson,Hudson.
IwouldfirstliketoacknowledgethesupportofJasonKridner,theTexasInstruments
embeddedapplicationsEvangelistandfounderofBeagleboard.org,withoutwhomthis
bookwouldneverhaveachievedliftoff.Additionally,immeasurablethanksneedtogoto
JohnReavesofLearningWorldsandMasuoKitanoofSeikoEpsonCorporation,who
ignitedtheprototyping-and-build-something-crazysparkinme.JonathanHirschmanof
PCB:NGgaveitafurtherpushbyshowingusthewaytocookupPCBsfromscratch,
literally.Finally,morethanthanksarenecessarytothetwopeoplethatshowedthegreatest
forbearanceinseeingthisprojecttoitsconclusion:mywife,Mary,andlittleboy,Hudson.
Withouttheirencouragement,patience,andlove,thisbookwouldneverhavehappened.
Forthis,Iamhumbledandgrateful.
AbouttheReviewers
NathanBurlesisapostdoctoralresearcherwithaPhDincomputerscience.Heis
currentlyworkingforUniversityofYorkonsubjectsasdiverseasartificialneural
networks,automatedprogramming/softwareimprovement,andoptimizationforpower
consumption.
Inhisfreetime,Nathanenjoystinkeringwithembeddedsystemsandelectronicsranging
fromfullsystems,suchasRaspberryPiandBeagleBoneBlack,tosimple
microcontrollers,suchasArduino,addingcircuitrytocommunicateusing433MHzRF
andinfrared.
Heblogsabouthisprojectsandtopicssuchaswebsitedevelopment,Android,anddancing
at.
AnujDeshpandeisafanofBeagleBoneBlackandallthingsembedded.Hedabblesin
embeddedLinuxandlovestoprototypeideasandbuildinteractiveinstallations.
SomeoftheprojectsthatAnujhasbeenapartofareUserspaceArduinoandTah.He
completedhisbachelor’sdegreeincomputersciencefromPICT,Pune.
AnujcurrentlyrunshisowndevelopmentandconsultingfirmcalledMakervilleSolutions
().
DeepakKarkiisasoftwaredeveloperandopensourceEvangelistbasedinBangalore,
India.Heenjoysworkingwithlike-mindedhackersandisoftenaparticipantin
hackathonsinandaroundthecity.Duringtheday,Deepakworksonchallenging
hyperconvergenceproblemswithNutanix,andinthenight,hekeepsbusypushingcode
ontoGitHub.
HewasaGoogleSummerofCode(GSoC)studentforbeagleboard.orgin2014and,
consequently,amentorforthesameorganizationduringGSoC2015.Deepak’smainareas
ofinterestincludeSaaSapplicationdevelopment,embeddedsystems,parallelcomputing,
networks,andsecurity.
Lately,hehasbeenheavilyinvolvedinIoTprojectsandisworkingwithWorldWideWeb
Consortium(W3C)tohelpstandardizeInternetofThingsbycontributingtotheirWoT
platform.
Apartfromwritingcode,Deepaklovesteachingandworkingout.Youcancatchhimat
github.com/deepakkarkioron#beaglefreenodeIRCasnick:karki_.
AgrimaSethiscurrentlyasenioryearstudentpursuingabachelor’sdegreeof
engineeringininformationtechnologyatUniversityofPune,India.Herresearchinterests
includemachinelearningandinformationretrievalsystems.Sheiscurrentlyaninternwith
theSIG(GeneralizedInformationSystems)researchteamunderProfessorJosianeMothe
atIRIT,France.Here,Agrimaisworkingonperformingeffectivedataindexingandquery
reformulationonTRECdatasetstostudyandcreatebetterinformationretrievalsystems.
ShehasbeentherecipientofSirRatanTataMemorialScholarshipandothermerit
scholarships.