program • Android+Arduino projects • examples from around the web • what protocols exist • Hands on time! • try out “ADK Andy” • build your own circuits from instructions • in-depth circuit creation
using computer logic Affect something physical (or virtual) Sense something happening in the physical world Scenario #1: Sense real world events The computer analyzes the weight of the pressure input to be larger than a sparrow’s weight. Squirrel?? A water hose is triggered and a spray of water is sent out in the direction of the intruder! A pressure sensor detects that something is trying to take seeds from a bird feeder. Examples The computer analyzes the levels to be lower than normal. The interface on a mobile phone app updates and warns the diabetic that they should eat an apple. A diabetic uses a glucose sensor to measure their blood-sugar level.
Notification of something happening in the virtual world The computer analyzes the sender to be your best friend. A LED sitting on your desk blinks urgently to get your attention. A Twitter @mention to your Twitter handle is detected. Examples Analyze incoming data using computer logic Scenario #2: Affect real world objects from online events
https://www.sparkfun.com/arduino_guide How to choose an Arduino Uno Leonardo LilyPad Micro Chip Speed Memory Input/Output Pins Price Best used for ATmega328 ATmega32u4 ATmega328 ATmega32u4 16 MHz 16 MHz 8 MHz 16 MHz 32 KB 32 KB 32 KB 32 KB 14 20 14 20 ~$30 ~$25 ~$22 ~$23 general, all purpose general, all purpose, built-in USB comm wearables tiny spaces
ADK Yún Chip Speed Memory Input/Output Pins Price Best used for ATmega32u4 ATmega2560 ATmega2560 ATmega32u4 & Atheros AR9331 16 MHz 16MHz 16MHz 16MHz 32 KB 256Kb 256Kb 32Kb 20 54 54 20 ~$25 ~$60 ~$80 ~$90 general, all purpose, built-in USB comm more pins or longer programs USB host, supports Android Open Accessory API networked projects (Ethernet or WiFi), SD card Need more detail? Check out the Sparkfun buying guide: https://www.sparkfun.com/arduino_guide
(Model A) $25 + additional computer, usb cord $35 + mouse, keyboard, monitor, connectors micro-controller mini-computer runs firmware/programs runs an operating system designed to quickly prototype single-purpose electronics projects additional libraries needed to control pins (SPI and I2C missing) established ecosystem of shields and add-ons can buy plain BT or WiFi adapters, more coming? vs MAKE has a good comparision
extension for Arduino version 1.0+ .pde for older sketches • Called a “sketch” because it should feel like picking up a pencil and making a quick drawing
or when reset button is pressed. • loop() Executes forever, as long as there is power and no code errors 2 functions are required for every Arduino program:
a pin to send outgoing commands • digitalWrite( pin#, HIGH ); Output to a pin: HIGH / 5 volts / “on” / 1 • digitalWrite( pin#, LOW ); Output to a pin: LOW / 0 volts / “off” / 0
a pin be used as a digital input pin with an internal “pull-up resistor” (to avoid erratic “floating” values when the switch is open) • digitalRead( pin# ); Listen for input values on a pin. Since it’s a digital signal, it will be either HIGH (1) or LOW (0)
) • in loop() use Serial.print() or Serial.println() • To see the serial monitor console, go to Tools > Serial Monitor while your Arduino is hooked up to your computer via USB. Make sure that the baud rate in the lower righthand corder is also the same as that in Serial.begin().
<AndroidAccessory.h> AndroidAccessory acc("Manufacturer", "Model", "Description", "1.0", "http://www.android.com", "0000000012345678"); Google-supplied C++ library USB and USB host libraries Create a new instance of the AndroidAccessory void setup() { acc.powerOn(); } void loop() { byte msg[0]; if (acc.isConnected()) { //send something to the Android app acc.write(msg, 1); //or read something int len = acc.read(msg, sizeof(msg), 1); } } Note: You can get a fully working but barebones Arduino ADK sketch here: iheartrobotics.com/2011/07/arduino-mega-adk-setup-notes.html Convenience method that simply calls the powerOn() method in the Max3421e library. Continually check for connection to Android app Create data that the Android app can read Read data from Android app into msg variable
<application ...> <activity ...> <meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" android:resource="@xml/accessory_filter" /> <intent-filter> <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"/> </intent-filter> </activity> </application> </manifest> In AndroidManifest.xml (3.1+): From previous slide Use intent filter to launch this activity when ADK is plugged in
getSystemService(Context.USB_SERVICE); UsbAccessory accessory = (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY); ParcelFileDescriptor fileDescriptor = manager.openAccessory(accessory); FileDescriptor fd = fileDescriptor.getFileDescriptor(); FileInputStream inputStream = new FileInputStream(fd); byte[] buffer = new byte[16384]; int ret = inputStream.read(buffer); FileOutputStream outputStream = new FileOutputStream(fd); mOutputStream.write(buffer); In the .java file for your Activity (3.1+): Read data from the Arduino via a FileInputStream Write data to the Arduino via a FileOutputStream
Adafruit and Sparkfun have invested a lot of time to make tutorials • Makertronic (makertronic.com) Go find Mike Eber around the BBQ tonight and thank you for a 10% discount code: BABBQ13