Hardware Reference
In-Depth Information
SPI and ADK
On the Mega ADK, as with other shields, the functionality to allow for the communication happens through a USB
host processor that uses the SPI protocol to communicate with the microcontroller. To demonstrate that other
SPI-capable devices still work with the ADK quite effectively, this last example reads a file from an SD card connected
to the Mega ADK board and prints the contents to the ADK monitor installed on the Android device. Listing 4-16
requires an SD card and an SD breakout board. The SD board that was used in the development of this example was
the microSD breakout made by Adafruit Industries ( www.adafruit.com/products/254 ) and was chosen for its
level-conversion feature, which converts from 5V to 3.3V logic and has the form factor of a breakout instead of a shield.
A microSD card will also be needed for the Adafruit board. If a different SD board is currently available, there is no
need to get the Adafruit board, provided your board has the capability to directly connect to the correct SPI pins.
Shields for Atmel 328-based Arduino boards, such as the UNO, will not work because of the different SPI pin location.
Listing 4-16 is an Arduino sketch and uses the same Android application developed in the first example in this
chapter. The Mega ADK needs to be connected to the SD breakout board as described in Figure 4-7 . The pins marked
DO (data out), DI (data in) and Clk (clock) on the SD breakout are connected to the MISO, MOSI, and SCK pins on
the Arduino Mega ADK board. Also on the SD breakout, the pin marked CS (chip select) is connected to pin 10 on the
Arduino. The power pins complete the setup, with 5V to 5V and ground to ground.
Figure 4-7. Layout for the ADK monitor
The sketch created in Listing 4-16 uses two libraries, SD.h and AndroidAccessory.h ; to solve any pin definition
conflicts the SD.h library need to be included first. A byte array of 80 elements is created to buffer the data gathered
from the SD file before sending to the Android device. This is done to speed up the transfer, accommodating for both
devices on the SPI bus. The accessory object is defined in the same way as in the other examples. Once the code
enters the setup function, the ADK object is started and waits for the connection to be ready before proceeding to
 
Search WWH ::




Custom Search