Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf

所需积分/C币:17 2012-11-27 19:47:12 9.96MB PDF
收藏 收藏
举报

Beginning Android ADK with Arduino Book Description Whether you’re new to Arduino and Android development, or you’ve tinkered a bit with either one, this is the book for you. Android has always been a natural fit with Arduino projects, but now that Google has released the Android Open Accessory De
Contents at a glance About the author ■■■■■■■口■■■■■ About the technical reviewer ■■■■■■■ ■■■■■■■ ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■I ■■■■ ■ Acknowledgments XI Preface ■■■■■■ Chapter 1: Introduction.. ■■■■■■■■ Chapter 2: Android and arduino: Getting to know each other mmmmmammaa 33 Chapter3: Outputs,… 69 国 Chapter4: Inputs,,,,,,,,,,,,,,,,,,99 Chapter 5: Sounds. ■■■■■■■■■■■■■■■■■■■口■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 127 Chapter 6: Light Intensity Sensing ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 147 Chapter 7: Temperature Sensing ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 161 Chapter 8: A Sense of Touch A RRRBMRRRRRRRIER a 183 Chapter 9: Making Things Move ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ ■■■■■■■■■■■■■■■■■■■■■■■■■■国■ 207 Chapter 10: Alarm Systema 1■■■■■■■■■■■■■■■■■I 241 Index 293 CHAPTER 1 Introduction In may 2011, Google held its annual developer conference, the google io, to present its newest technologies to approximately 5,000 attendees. In addition to improvements in its already well-known technologies such as the Google APIs or the core search technology, Google placed the focus on two major themes: Chrome and android as always, the newest advances in the android platform were presented and discussed, but what google announced a bit later in the android keynote was a bit of a surprise: Google's first standard for Android devices to communicate with external hardware The Android Open Accessory Standard and the Accessory Development Kit (ADk) will be the key for communicating with hardware and building external accessories for Android devices. To encourage development, Google handed out ADK hardware packages to interested attendees and showed some examples of ADK projects, such as a treadmill which transmitted data to a connected android device and a huge tilt labyrinth, which could be controlled with an android device. Shortly after the event, the first DIY projects surfaced which already showed the great potential of the ADK Since i couldn't attend the event, i had no chance to get my hands on one of those kits; at the time, there was only one distributor for the Google adk boards and this distributor wasnt prepared for such a big demand That didn' t stop me from building an alternative myself and from experiencing the joy of this new field in Android development. Over time, many more distributors have produced derivatives of the original Google ADk boards, which are, for the most part, cheaper and only provide the basics to get you started hacking your project together You probably just want to dive right in, but first you should learn about the specifics of the ADK and set up your development environment. You wouldn 't build a house before you knew how to do it or without having the proper tools, would you? What ls the aDK? The Accessory Development Kit(ADk is basically a micro-controller development board that adheres to the simple Open Accessory Standard Protocol created by Google as a reference implementation Although that could be any board fulfilling the specification to be aDK compatible, most boards are based on the arduino design, which is an open hardware platform created in 2005. Those boards are JSB-enabled micro-controller boards based on the Arduino Mega2560 and the implementation of the Circuits @Home USB Host Shield. However, there are other board designs known to be aDK compatible such as PIC-based boards or even plain USB host chip boards such as the vncii by FTDI. google decided to build its reference kit upon the arduino mega2560 design and provided the software and tremendously over the last years, enabling designers, hobbyists, and average Joes to easily make their p hardware resources as open source. This was a clever move because the arduino community has grow ideas come to life. With the ever-growing communities of both factions of Android and arduino enthusiasts, the AdK had a pretty good start CHAPTER 1 INTRODUCTION To communicate with the hardware boards, an Android-enabled device needs to fulfill certain criteria With Android Honeycomb version 3. 1 and backported version 2.3.4, the necessary software APIs were introduced. However, the devices also have to ship with a suitable USB driver. This driver enables general USB functionality but, in particular, it enables the so-called accessory mode. The accessory mode allows an android device that has no USB host capabilities to communicate with external hardware, which in turn acts as the usb host part The specification of the Open Accessory Standard stipulates that the USB host has to provide power for the usb bus and can enumerate connected devices The external device has to provide 500mA at 5V for charging purposes of the android device according to the USB 2.0 specification The ADK also provides firmware for the development board which comes in the form of a set of source code files, libraries, and a demokit sketch which is the arduino term for a project or source code file. The firmware cares about the enumeration of the usb bus and finding a connected device that is accessory mode-compatible Google also provides an example app for the android device that easily accesses and demonstrates the capabilities of the reference board and its sensors and actuators if you are working with a derivative board that doesnt have the same variety of sensors, you still can work with the example app, but you might want to strip the code down to only the basic part of the communication When you set up an adK hardware project you are building a so-called android accessory. Your hardware project is an accessory for the android device such as, for example, a keyboard would be for a PC, with the difference being that your accessory provides the power for the whole system Accessories need to support the already mentioned power supply for the device and they must adhere to the android accessory protocol. The protocol dictates that the accessory follows four basic steps to establish a communication to the android device 1. The accessory is in wait state and tries to detect any connected devices 2. The accessory checks for accessory mode support of the device 3. The accessory tries to set the device in accessory mode if it is necessary If the device supports the android accessory protocol, the accessory establishes the communication If you want to learn more about the ADK and the Open Accessory Standard have a look at the Androiddeveloperpagesathttp://developer.androidcom/guide/topics/usb/adk.html Hardware Development boards This section will give you an overview of the variety of ADK-compatible development boards that are currently on the market. Note that i cant guarantee the completeness of this list because the community advances at such a pace that new boards could pop up at any time. i will concentrate on the most popular boards out there as of this writing The Google aDK The Google adk is the reference kit presented at the google io in May 2011 and it was the first board adhering to the Open Accessory Standard. The kit comes with the adk base board and a demo shield,as shown in Figure 1-1 2 CHAPTER1■ NTRODUCTION 8 F?16 oooC C∩32o1 Figure 1-1. Google adk board and Demo Shield The base board(Figure 1-2 )contains the DC power connector, the USB connector(A-type receptacle)to connect your phone or tablet to, and the micro USB connector(micro B-type receptacle to connect to your computer for programming and debugging purposes. It has an ATmega2560 AVR chip from Atmel mounted on top, optimized for C-compiled code, which makes it pretty fast and easily programmable instead of comparable microcontrollers that have to be programmed in the assembler language. The ATmega2560 has an internal flash memory of 256 Kbytes and an 8-bit CPU and it operates at 16MHz. It provides 8KB of SRAM and 4KB of EEPROM. The IO ports of the aTmega chip control 16 analog pins that provide 10 bits of input resolution enabling analog-to-digital conversion of 1,024 different values. They measure from ground to 5v by default. The chip has 54 digital pins with 14 of them being PWM (pulse width modulation)enabled to allow, for example, dimming of lEDs or controlling servos. In the middle of the board is a reset button to reset the program execution on the board. The board's operating voltage is 5V. Although you can power the board via a USB cable, you should consider using a power adapter if you intend to control servos or drive motors CHAPTER 1 INTRODUCTION ≌了 ③: pun a∩23o| conMUNICATION Dog 样 d POWER ANALOG GND Figure 1-2. A closer look at the Google adk board The Demo Shield is an additional board containing a broad variety of different sensors and actuators. Shield is an Arduino term for an extension board that can be put on top of an arduino base board. The connection is made via stackable pin headers. The io pins of the base board are mostly delegated to the pins of the shield so they can be reused. However, certain shields might occupy pins to operate their sensors. The demo shield itself is presoldered with male pin headers so no additional shields can be stacked on top This doesnt come as a surprise, since the shield uses most of the pins to et the base board communicate with all of its sensors since the shield hides the reset button of the base board, it contains one itself so that you can still make use of the reset functionality. The most important parts, however, are the sensors and actuators and there are a lot of them One analog joystick Three buttons Three RGB leds a transistor functioning as a temperature sensor An iC with an integrated photo diode for light sensing CHAPTER1■ NTRODUCTION A capacitive touch area in the form of the android logo Two relays with screw terminals which can switch external circuits with 24V up to 1A Three servo connectors The Google adk was originally produced by a Japanese company for the Google Io. It can be orderedatwww.rt-net.ip/shop/index.phpmainpage=productinfo&cpath=348productsid=1.Ataprice of approximately $400(not including sales tax), it is one of the priciest boards out there The Arduino adk The Arduino ADK(Figure 1-3)is an ADK-compatible base board from the makers of the Arduino series themselves. It is also based on the aTmega2560 and only differs slightly from the google reference board COUNICATON 30 36a 38 ⊙AD ,四 ARDU工 NO for Android LA⊥UL⊥N cm守诉 Figure 1-3 Arduino ADK board The arduino adk board also has a dC power connector and a USB connector(A-type receptacle mounted to connect to an android device. The programming and debugging connector, however, differs in being a standard USB connector (B-type receptacle). The reset button is situated at the far end of the board and the atmega chip sits in the middle of the board. The io pin layout is exactly the same as in 5 CHAPTER 1 INTRODUCTION the google board and it has the same analog and digital pin characteristics. The Arduino ADK, however, has two ICSP 6-pin headers for In-Circuit Serial Programming (ICSP)of microchips. Sharing the same pin layout and form factor, the arduino adk and the google adK are compatible with the Demo Shield and other arduino based shields The arduino adk is made in Italy and can be ordered directly from the arduino site at http://store.arduino.Cc/Ww/index.phpmain_page=productinfo&cpath=11128prOductsid=144orfrom oneofitsnumerousdistributorsworldwidefoundathttp://arduino.cc/en/main/buy At a price of about $90 (not including possible shipping costs and taxes), it is way more affordable than the google adk for the average hobbyist and hardware hacker. The Ioi The Ioio (pronounced yo-yo) board(Figure 1-4)is a PIC micro-controller-based development board developed by Sparkfun Electronics before the announcement of the Open Accessory Standard dano 12w8乙 c乙 9乙 s乙 乙 E乙 乙乙 Figure 1-4. Sparkfun Iolo board The ioio board was designed to work with all android devices with version 1.5 and above. The original firmware design was targeted to work with the android Debug Bridge (aDb), which is normally used within the development process of an Android application for debugging processes and for file system operations. After the announcement of the Open Accessory Standard the ioio was updated with a new firmware to support both the Open Accessory Protocol and, as a fallback, the aDB protocol to still 6 CHAPTER1■ NTRODUCTION support older devices. The firmware is still in beta as of the time of writing this book. Since you need to update the firmware of the board through a PiC programmer in order to make the board ADK compatible, it might not be the perfect choice for an inexperienced tinkerer The hardware specifics of the board are as follows. The ioio has a form factor of about a quarter of the size of a regular adK-compatible board which makes it one of the smallest boards available Nevertheless, it nearly keeps up with the numerous IO pins of its big brothers. Many of the overall 48 I0 pins have several operating modes, which can make the pin assignments a bit confusing From the 48 I0 pins, all pins can be used as general purpose input output ports. Additionally, 16 of hose pins can be used as analog inputs, 3 pairs of pins can be used for I2C communication, I pin can be used as a peripheral input, and 28 pins can be used for peripheral inputs and outputs. Normally, the pins are 3. 3V tolerant only, but 22 pins are capable of tolerating 5V inputs and outputs. The 12C pins provide a fast and simple two-wire interface to communicate with external integrated circuits such as sensor boards Apart from the Io pins the board provides 3 Vin pins for power supply of the board. On the bottom side of the board you can solder an additional jSt connector to connect a LiPo battery as the power supply. An operating voltage of 5V to 15V should be supplied. Additionally, it has 3 pins for 3. 3V output, 3 pins for 5V output, and a 9 pin-area for ground The only connector on this board is the required USB(A-type receptacle) connector That is because programming the hardware is not necessary, unlike for the other ADK-compatible boards, which need C-compiled code for the hardware part. The Ioio provides a firmware that implements all necessities You only need to write the android part by using a high-level aPI for easy pin access One interesting component of the board is a small trimmer potentiometer that can limit the charging current of the android device so that it won't draw too much power when the board is in battery mode. The IOIo has a PIC micro-controller chip instead of the avR chip most of the other boards use The PIC24FJ256-DA206 chip operates at 32MHZ, has 256KB of programmable memory and 96KB of RAM The iolo was developed by Sparkfun Electronics and can be ordered via the Sparkfun web site at Www.sparkfun.com/products/10748orthroughoneofitsdistributors noo. with a price ofabout $50 before shipping and taxes, it is one of the cheapest boards out there but one of the friendliest to beginners The Seeeduino adk main board The Seeeduino ADK board(Figure 1-5), also derived from the ATmega board, looks quite similar to the standard Arduino adk board but, at second glance, it has some nice extra features

...展开详情
试读 127P Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf
立即下载 低至0.43元/次 身份认证VIP会员低至7折
一个资源只可评论一次,评论内容不能少于5个字
wayneskyline 感謝分享,文件很清楚
2015-03-08
回复
htox 不错,是我想要的
2014-12-11
回复
南山云 很好的参考书,详细,全面。谢谢楼主分享。
2014-05-19
回复
dixin03 不错,是真的,感谢共享
2013-06-22
回复
关注 私信 TA的资源
上传资源赚积分,得勋章
最新推荐
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf 17积分/C币 立即下载
1/127
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第1页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第2页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第3页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第4页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第5页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第6页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第7页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第8页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第9页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第10页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第11页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第12页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第13页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第14页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第15页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第16页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第17页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第18页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第19页
Apress.Beginning.Android.ADK.with.Arduino.Mar.2012.pdf第20页

试读结束, 可继续阅读

17积分/C币 立即下载 >