January 28, 2016 Mark Yoder And Jason Kridner - BeagleBoard

Transcription

January 28, 2016Mark Yoder and Jason KridnerAuthors of BeagleBone Cookbook andBeagleBoard.org Foundation board members1

BeagleBoards and BeagleBones are inexpensive web servers, Linuxdesktops, and electronics hubs that include all the tools you need tocreate your own projects—whether it's robotics, gaming, drones, orsoftware-defined radio. This webcast will go over some of the recipesin the BeagleBone Cookbook that go beyond BeagleBone Black forconnecting and talking to the physical world with this credit-card-sizedcomputer. In this webcast you will learn:– What is BeagleBone Black? What can you do with BeagleBone Black?– What basic skills will “BeagleBone Cookbook” help me develop?– What are some other BeagleBoards coming out, including SeeedStudioBeagleBone Green, SanCloud BeagleBone Enhanced, BeagleBoard.orgBeagleBone Blue and BeagleBoard.org BeagleBoard-X15– What recipes will work with these other boards and how do I apply them?2

Truly flexible open hardware andsoftware development platformAll you need is in the boxProven ecosystem from prototypeto product 50 Ready to use USB client network Built-in tutorials Browser based IDE Flashed w/Debian Fast and flexible 1-GHz Sitara ARM 2x200-MHz PRUs 512-MB DDR3 On-board HDMI 65 digital I/O 7 analog inputs Support for numerousCape plug-in boardshttp://beaglebonecapes.comBeagleBone Black – the most flexible solution in open-source computing3

10/100 EthernetPower ButtonDC PowerUSB HostEasily connectsto almost anyeverydaydevice suchas mouseor keyboardLEDSSerialDebugReset ButtonUSB ClientDevelopment interfaceand directly powersboard from PCmicroHDMIConnectdirectly tomonitorsand TVsmicroSDExpansion slot foradditional storage512MB DDR3Faster, lower powerRAM forenhanced user-friendlyexperienceMoney saving extras:4BootButtonExpansionheadersEnable cape hardwareand include: 65 digital I/O 7 analog 4 serial 2 SPI 2 I2C 8 PWMs 4 timers And much much more! Power over USB Included USB cable1-GHz SitaraAM335xARM Cortex -A8processorProvides amoreadvanced userinterface andup to 150%betterperformancethan ARM11 4-GB on-board storage Built-in PRU microcontrollers4-GB on-boardstorage usingeMMC Pre-loaded withDebian LinuxDistribution 8-bit busacceleratesperformance Frees the microSDslot to be used foradditional storagefor a lessexpensive solutionthan SD cards

digitalWrite()5

7 Medical analysis, assistance andinformation management Home information, automation andsecurity systems Home and mobile entertainmentand educational systems New types of communicationssystems Personal robotic devices forcleaning, upkeep andmanufacturing Remote presence and monitoring Automotive informationmanagement and control systems Personal environmental explorationand monitoring

99 recipes ays and outputsMotorsInternet of thingsKernelReal-time I/OCapes8

Gain familiarity with electronic components you canintegrate– Sensors, displays/lights, motors, networking and more– Quick success with known-good recipes– Go all the way to making your own PCB Build confidence working with a Linux system–––––Get the guided tourWork with high-level languages like JavaScript and PythonUtilize Linux networking capabilitiesGet introduced to working with real-time and kernel patchingGain exposure to related industry tools9

Fanless open computerBeagleBoardNow, BeagleBoard-X15,updates the full-featuredBeagleBoard line forthose wanting everythingIn 2010, BeagleBoard-xMprovided extra MHz andmemory, without extra costIn 2008, BeagleBoard.orgintroduced the world topersonally affordable opencomputing with the originalBeagleBoard, spawningcountless want-to-bedesigns inspired by opencommunity collaboration10In 2013, BeagleBone Blackagain brought developersextra MHz and memory,restored the HDMI and all ata price below 50!In 2011, BeagleBoard.org gotdown to the bare bones anda single cable developmentexperience with the originalBeagleBone at under 90Mint tin sizedBeagleBone

Third party productthat licenses use oflogo Verified to runBeagleBoard.orgsoftware image Open hardware designmaterials Targeting newapplications11

Available now Compared to Black– Removes HDMI– Adds Grove connectors Affordable and great forquick-connect to I2Cand UART sensors SCL P9 19SDA P9 20 TXD P9 21RXD P9 2212

To be released soon Compared to Black– Adds RAM to 1GB– Ethernet to 1Gbit/s– Adds IMU, barometer,temperature sensors– Adds WiFi/Bluetooth viadaughterboard– Adds 3 USB ports For those that want allthe bells and whistles,but still BeagleBonecompatibility13

To be released May 2016 Compared to Black– Removes cape headers,HDMI and Ethernet– Adds wireless connectivity– Adds battery support– Adds DC and servo motorcontrol– Adds IMU and barometersensors– Adds CAN and severalquick expansionconnections Open robotics educationsolution14

To be released Feb2016 Compared to Black– Similar Debian Linuxdistribution– No cape interface– PRUs– Many more cores– Many more I/Os– Lots more connectivity The “what if” machine15

USB3.0 Host3x HUBHigh performance Sitara AM5728 processor 1.5GHz ARM Cortex -A15 forprocessing and user interface 750-MHz C66x DSP for analytics Quad core PRU and dual coreCortex-M4 for real time control Video and Graphic accelerationBottom sideµSD card slotMicro USB 2.0 slaveReset buttonAudio inAudio outeMMC4GBBottom sideExpansion connectors20-pin ARM JTAG2x Ethernet PortsGigabiteSATAHDMIDDR3L2GB12V DC PowerTPS659037PowerManagement ICPower button16

CapesHDMIFlashSpecialBeagleBoard.org BeagleBoneYNNJTAGBeagleBoard.org BeagleBone BlackYYY-Arrow BeagleBone Black IndustrialYYYIndustrialElement14 BeagleBone Black Industrial YYYIndustrialSeeedStudio BeagleBone GreenYNYGroveSanCloud BeagleBone EnhancedYYY1GB, 1Gbit,wirelessBeagleBoard.org BeagleBone BlueNNYRoboticsBeagleBoard.org BeagleBoard-X15NYNBig jump inCPUs and I/O17

18

Built-in HDMI audio– connect to TV or HDMI-audio adapter Audio cape– SPI, I2S and I2C available USB Bluetooth dongles– BlueZ https://wiki.debian.org/Bluetooth/Alsa USB audio adapter this will be our approach– Easy to find adapters on Amazon, etc. http://www.amazon.com/s/ref nb sb noss 2?url searchalias%3Daps&field-keywords linux usb audio19

Connect to the board per recipe 1.2– http://beagleboard.org/getting-started Verify the software image per recipe 1.3 andpotentially updating per recipe 1.9– http://beagleboard.org/latest-images20

Power up with USBaudio adapter inserted– Some kernels don’t likeUSB hotplugging– USB power typicallysufficient, but add apower adapter if yousee issues Verify driver loaded– lsusb– dmesg21

Discover devices– man aplay– aplay -l– aplay -L Playback samples– aplay -D "default:CARD Device"/usr/share/sounds/alsa/Front Center.wav22

Use the mixer to set the input gain– alsamixer Record a sample– man arecord– arecord -f dat -D "default:CARD Device" test.wav23

Write to /.asoundrc Enables you to useapplications withoutspecifying the cardeach time Examplerequires ‘apt-get install flite’– flite –t "Hello!"pcm.!default {type plugslave {pcm "hw:1,0"}}ctl.!default {type hwcard 1}24

Includes user spacelibrary for applicationprogramming Supports manydevices ALSA SoC supportsadding codecs toembedded boards25

Nice set of tutorials from 13-year old Alek Mabry– http://einsteiniumstudios.com/speak.html Shortcuts to updates and examples from the book– http://beagleboard.org/cookbook26

27

Connect to the board per recipe 1.2– http://beagleboard.org/getting-started Verify the software image per recipe 1.3 andpotentially updating per recipe 1.9– http://beagleboard.org/latest-images28

29

ot/jQueryDemo.js html head title BoneScript jQuery Demo /title script src "/static/jquery.js" /script script src "/static/bonescript.js" /script script src "jQueryDemo.js" /script /head setTargetAddress('192.168.7.2',{initialized: run});function run() {var b require('bonescript');b.pinMode('P8 19', b.INPUT);getButtonStatus();function getButtonStatus() {b.digitalRead('P8 19', onButtonRead);}function onButtonRead(x) { onStatus, 20);}} body h1 BoneScript jQuery Demo /h1 p buttonStatus span id "buttonStatus" /span /p /body /html 30

var port 9090, h require('http'),u require('url'), f require('fs');var s h.createServer(servePage);s.listen(port);function servePage(req, res) {var p u.parse(req.url).pathname;f.readFile( dirname p,function (err, data) {if (err) return;res.write(data, 'utf8');res.end();});} BeagleBone Blackships with Debian andNode.JS Using Node.JS is easyto serve up a simpleweb page Run with:node server.js Browse to port 9090and a local file31

var h require('http'),f require('fs'),b require('bonescript'),g 'P8 19', p 9090;var htmlStart " !DOCTYPE html \ html body h1 " g " /h1 data ";var htmlEnd " /body /html ";var s h.createServer(servePage);b.pinMode(g, b.INPUT);s.listen(p);function servePage(req, res) {var data b.digitalRead(g);res.write(htmlStart data htmlEnd, 'utf8');res.end();} Builds on simpleNode.JS web server BoneScript libraryutilized on server Content served usingvariables, not files Full example usesURL path– distinguish content Refresh manually32

Great tool to make content dynamic jsfiddle.net provides a playground for learning Learn more about the API at jquery.com33

Provides a setTargetAddress() function to definethe global require() functiondigitalWrite() Utilizes the built-in Node.JS based web serverbuilt into the BeagleBone Black default ter/src/server.js On-board bonescript.js provides the require()function and utilizes socket.io to define remoteprocedure ter/src/bonescript.js34

35

See demo code at– /blob/master/06iot/flotDemo.js– /blob/master/06iot/flotDemo.html This is just the beginning– Lots of different types of hardware interactions– Lots of different visualizations possible in the browser36

JavaScript tricks– http://beagleboard.org/project/javascript-tricks/ Shortcuts to updates and examples from the book– http://beagleboard.org/cookbook37

38

Connect to the board per recipe 1.2– http://beagleboard.org/getting-started Verify the software image per recipe 1.3 andpotentially updating per recipe 1.9– http://beagleboard.org/latest-images Establish an Ethernet-based Internet connectionper recipe 5.11 or a WiFi-based Internetconnection per recipe 5.12– WiFi adapters: http://bit.ly/1EbEwUo39

40

41

42

Installation is simple, but requires a networkconnection Installing the developer version has changed slightlywith a build step, but it is easier just to install using‘npm’ Requires a live Internet connection Steps to install and run from root promptbone# npm install --unsafe-perm -g node-red@0.12.1bone# node-red Add BeagleBone specific nodesbone# cd /.node-redbone# npm install node-red-node-beaglebone43

44

Drag nodes from theleft side into the sheetto add them Configure the nodes Use debug nodes totest the outputs Be sure to click‘Deploy’ to start theapp45

‘msg’ is a JavaScriptobject ‘msg’ contains theelement ‘payload’,which is what youmost likely want tomanipulate46

Learn more about Node-RED– http://nodered.org Shortcuts to updates and examples from the book– http://beagleboard.org/cookbook47

48

Connect to the board per recipe 1.2– http://beagleboard.org/getting-started Verify the software image per recipe 1.3 andpotentially updating per recipe 1.9– http://beagleboard.org/latest-images Components– BeagleBone Black– L293D H-Bridge IC– 5V DC motor For other voltages, verify H-bridge compatibility– Breadboard and jumper wire Alternatively, I’ve had a PCB fabricated49

DC voltage causes motorto turn Brush contact resets driveafter partial revolution Drive strength isproportional to inputvoltage There’s a maximum inputvoltage Reversing voltagereverses direction BeagleBone Black doesn’tsupply enough current onits I/O pins50

Enables approximatinga voltage by turning onand off quickly BeagleBone Black has8 hardware PWMs PRU can produceanother 25 more withappropriate firmware51

Enables reversingdirection of the motor Integrates driver aswell52

Pin 1 is the speedcontrol Pin 2 is the forwarddrive Pin 7 is the backwarddrive53

Pin 1 to P9 14 “EN”Pin 2 to P8 9 “FWD”Pin 3 to “Motor ”Pin 4 and 5 to DGNDPin 6 to “Motor -”Pin 7 to P8 11 “BWD”Pin 8 to VDD 5VPin 9 to VDD 3V354

var b require('bonescript');var motor { SPEED: 'P9 14', FORWARD:'P8 9', BACKWARD: 'P8 11' };var FREQ 50;var STEP 0.1;var count 0;var stop false;b.pinMode(motor.FORWARD, b.OUTPUT);b.pinMode(motor.BACKWARD, b.OUTPUT);b.analogWrite(motor.SPEED, 0, FREQ, 0, 0);var timer setInterval(updateMotors, 100);function updateMotors() {var speed Math.sin(count*STEP);count ;Mset(motor, speed);} Define the pinsKeep track of stateSetup pins initiallyUse a 100ms timer toupdate the motors Use a sine wave toincrement/decrementthe speed for test Call ‘Mset’ to updatethe PWM and direction55

function Mset(motor, speed) {speed (speed 1) ? 1 : speed;speed (speed -1) ? -1 : speed;//console.log("Setting speed " speed);b.digitalWrite(motor.FORWARD, b.LOW);b.digitalWrite(motor.BACKWARD, b.LOW);if(speed 0) {b.digitalWrite(motor.FORWARD, b.HIGH);} else if(speed 0) {b.digitalWrite(motor.BACKWARD, , FREQ);} Put a cap on themaximum andminimum at 1 and -1 Set the drive signalsfor direction Adjust PWM basedupon the speed56

function doStop() {clearInterval(timer);Mset(motor, 0);} Detect when programis being stopped by a C Stop the timer anddisable the motorprocess.on('SIGINT', doStop);57

58

Learn more about H-Bridges and motors– otors-the-basics/ My simple PCB– https://oshpark.com/shared projects/Mz40o0aN Shortcuts to updates and examples from the book– http://beagleboard.org/cookbook59

60

Throughput vs. latencyHard, soft and firmContext switchingTask schedulingLinux RT PREEMPTUsing ‘strace’ and‘oprofile’61

/dev/mem is a character device that is an image ofthe main physical memory of the computer mmap() is a system function to map devices into(virtual) memory Together, they can be used to provide anapplication that has only a virtual memory spacewith access to specific physical addresses Directly accessing the registers bypasses systemcalls and avoids context switches This is really just a step towards writing your owndevice driver62

Connect to the board per recipe 1.2– http://beagleboard.org/getting-started Verify the software image per recipe 1.3 andpotentially updating per recipe 1.9– http://beagleboard.org/latest-images Components––––BeagleBone BlackPush button or 3.3V function generatorJumper wireLED with resistor or (preferred) oscilloscope63

Input on GPIO 7 and output on GPIO 3164

bone# wget # gcc -o devmem2 devmem2.c && mv devmem2 /usr/local/bin/bone# ln -s /sys/class/gpiobone# echo 31 gpio/exportbone# echo out gpio/gpio31/directionbone# echo 1 gpio/gpio31/valuebone# echo 0 gpio/gpio31/valuebone# devmem2 0x44E07138bone# devmem2 0x44E07190 w 0x80000000bone# devmem2 0x44E07194 w 0x80000000bone# devmem2 0x44E0713865

bone# cbone# hbone# gcc -O3 –o pushLEDmmap pushLEDmmap.cbone# ./pushLEDmmap C66

AM335x Technical Reference Manual– http://bit.ly/1B4Cm45 StarterWare for Sitara– http://www.ti.com/tool/starterware-sitara Enabling RT PREEMPT– http://elinux.org/Beagleboard:BeagleBoneBlack Debian#4.1.x-ti Learning to write a device driver in Recipe 7.2 Program GPIO with PRU in Recipe 8.6 Shortcuts to updates and examples from the book– http://beagleboard.org/cookbook67

http://beagleboard.org/cookbook68

community collaboration BeagleBone at under 90 In 2010, BeagleBoard-xM provided extra MHz and memory, without extra cost In 2011, BeagleBoard.org got down to the bare bones and a single cable development experience with the original In 2013, BeagleBone Black again brought developers extra MHz and memory, restored the HDMI and all at