SlideShare a Scribd company logo
1 of 36
Download to read offline
Android Development For Arduino 101
By: Bryan Jones Richardson
Software Engineer
stable|kernel

bryan.richardson@stablekernel.com
stablekernel.com
We’re stable|kernel.
stable|kernel is an Atlanta-based mobile development company 

to craft smartly-designed mobile applications that connect brands 

directly with their users. 



The Internet of Things?
@stablekernel
@stablekernel
The internet of things (IoT) is the
network of physical devices,
embedded with electronics, software,
sensors, actuators, and network
connectivity that enable them to
collect and exchange data.
• Transportation (Street Lights)
• Healthcare
• Agriculture
• Durables & Wearable
• Object Oriented World
What Is Arduino?
@stablekernel
@stablekernel
Arduino is an open-source electronics
platform based on easy-to-use hardware
and software. It's intended for anyone
making interactive projects.
(Basically, a small computer that you can
connect to anything).
• Uno
• Mega
• Yun
• Minimal Cost Barriers
• Raspberry Pi, Edison, etc.
Let’s Make Music
@stablekernel
Arduino Communication Strategies
@stablekernel
•USB
•Bluetooth
•Network
Android & Arduino via USB
@stablekernel
@stablekernel
Android USB Classes
• UsbManager
• UsbDevice
• UsbDeviceConnection
• UsbInterface
• UsbEndpoint
• UsbConstants
@stablekernel
Detect Android USB Connection
private final BroadcastReceiver usbConnectionAttachedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(@NonNull Context context, @NonNull Intent intent) {
activeUsbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
connectUsb();
}
};
private final BroadcastReceiver usbConnectionDetachedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(@NonNull Context context, @NonNull Intent intent) {
UsbDevice detachedDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (detachedDevice == activeUsbDevice) {
disconnectUsb();
}
}
};
@stablekernel
Determine if Arduino is Connected
for (int i = 0; i < activeUsbDevice.getInterfaceCount(); i++) {
UsbInterface usbInterface = activeUsbDevice.getInterface(i);
if (usbInterface.getEndpointCount() == 2) {
for (int j = 0; j < endpointCount; j++) {
UsbEndpoint endpoint = usbInterface.getEndpoint(j);
if (endpoint.getType() != UsbConstants.USB_ENDPOINT_XFER_BULK) {
continue;
}
if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
endpointOut = usbInterface.getEndpoint(j);
} else if (endpoint.getDirection() == UsbConstants.USB_DIR_IN) {
endpointIn = usbInterface.getEndpoint(j);
}
}
}
}
}
@stablekernel
Establish Communication w/ Arduino
private void setupUSBComm() {
UsbManager manager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE);
Boolean permitToRead = manager.hasPermission(arduinoDevice);
if (permitToRead) {
connection = manager.openDevice(arduinoDevice);
if (connection != null) {
connection.claimInterface(activeUSBInterface, true);
//requestType, SET_CONTROL_LINE_STATE, value, index, buffer, length, timeout
connection.controlTransfer(RQSID_SET_REQUEST_TYPE, RQSID_SET_CONTROL_LINE_STATE, 0, 0, null, 0, 0);
connection.controlTransfer(RQSID_SET_REQUEST_TYPE, RQSID_SET_LINE_CODING, 0, 0, encodingSetting, 7, 0);
}
} else {
manager.requestPermission(arduinoDevice, permissionIntent);
}
}
@stablekernel
Send Android Data to Arduino
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
playNote(position);
}
public void playNote(int note_value) {
byte[] bytesOut = new byte[]{ (byte) note_value};
if(arduinoDevice != null) {
usbArduinoConnection.bulkTransfer(endpointOut, bytesOut, 1, 0);
}
}
@stablekernel
Process Android Data on Arduino
int speakerPin = 9;
int tones[] = { 440, 494, 523, 587, 659, 698, 784};
void setup() {
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
int incomingByte = Serial.read();
if (incomingByte > -1) {
playNote(incomingByte);
}
}
}
void playNote(int note) {
tone(speakerPin, tones[note], 200);
}
@stablekernel
Hardware Setup
Ground Pin 9
Piezo BreadBoardUno USB
Android & Arduino via Bluetooth
@stablekernel
@stablekernel
Android Bluetooth Classes
<uses-permission android:name = "android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name = “android.permission.BLUETOOTH”/>
private BluetoothAdapter bluetoothAdapter;
private BluetoothSocket bluetoothSocket;
private Set<BluetoothDevice> pairedBluetoothDevices;
static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
@stablekernel
Connect To BlueTooth Device
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice btDevice = bluetoothAdapter.getRemoteDevice(bluetoothAddress);
btSocket = btDevice.createInsecureRfcommSocketToServiceRecord(myUUID);
BluetoothAdapter.getDefaultAdapter().cancelDiscovery();
btSocket.connect();
@stablekernel
Send Android Data to Arduino
byte[] bytesOut = new byte[]{ note_value };
try {
btSocket.getOutputStream().write(bytesOut);
} catch (IOException e) {
// handle exception
}
@stablekernel
Debugging on Arduino
@stablekernel
Debugging on Arduino
digitalWrite(ledPin, LOW);
digitalWrite(ledPin, HIGH);
serialPrint(…);
@stablekernel
Hardware Setup
Bluetooth
Transmitter
LED
Android & Arduino via Network
@stablekernel
@stablekernel
Configure Yun For Connectivity
@stablekernel
Configure Yun For Connectivity
@stablekernel
Configure Yun For Connectivity
@stablekernel
Implement Arduino Code
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
YunServer server;
...
@stablekernel
Implement Arduino Code
void setup() {
...
Bridge.begin();
server.listenOnLocalhost();
server.begin();
}
@stablekernel
Implement Arduino Code
void loop() {
YunClient client = server.accept();
if (client) {
process(client);
client.stop();
}
delay(50);
}
void process(YunClient client) {
String incomingNote = client.readStringUntil('/');
playNote(incomingNote.toInt());
}
@stablekernel
Send Android Data to Arduino Yun
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
String[] musicalNotes = new String[] { "A","B","C","D","E","F","G"};
ArrayAdapter<String> musicalNotesAdapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, musicalNotes);
notesListView.setOnItemClickListener(this);
notesListView.setAdapter(musicalNotesAdapter);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String note = String.valueOf(position);
HttpClient client = new DefaultHttpClient();
String URL = “http://10.0.0.19/arduino/“ + note;
HttpGet request = new HttpGet(URL);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
client.execute(httpget, responseHandler);
}
@stablekernel
Hardware Setup
Live Demo
@stablekernel
Questions?
Business Inquiries:
Sarah Woodward
Director of Business Development
sarah.woodward@stablekernel.com
Bryan Jones Richardson
Software Engineer
bryan.richardson@stablekernel.cm
blog.stablekernel.com

More Related Content

What's hot

Arduino Programming Software Development
Arduino Programming Software DevelopmentArduino Programming Software Development
Arduino Programming Software DevelopmentSanjay Kumar
 
Iot development from prototype to production
Iot development from prototype to productionIot development from prototype to production
Iot development from prototype to productionMender.io
 
Introduction To Arduino
Introduction To ArduinoIntroduction To Arduino
Introduction To Arduinounsheffield
 
Arduino Based Smart Parking System
Arduino Based Smart Parking SystemArduino Based Smart Parking System
Arduino Based Smart Parking SystemIRJET Journal
 
Show & Tell.- Introduction
Show & Tell.- IntroductionShow & Tell.- Introduction
Show & Tell.- Introductionzvikapika
 
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & ArduinoEchelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & ArduinoAndri Yadi
 
Microcontrollers (Rex St. John)
Microcontrollers (Rex St. John)Microcontrollers (Rex St. John)
Microcontrollers (Rex St. John)Future Insights
 
Embedded system introduction - Arduino Course
Embedded system introduction - Arduino CourseEmbedded system introduction - Arduino Course
Embedded system introduction - Arduino CourseElaf A.Saeed
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to ArduinoYong Heui Cho
 
Arduino and Internet of Thinks: ShareIT TM: march 2010, TM
Arduino and Internet of Thinks: ShareIT TM: march 2010, TMArduino and Internet of Thinks: ShareIT TM: march 2010, TM
Arduino and Internet of Thinks: ShareIT TM: march 2010, TMAlexandru IOVANOVICI
 
Analog to Digital Conversion Using Microcontroller Education Boards
Analog to Digital Conversion Using Microcontroller Education BoardsAnalog to Digital Conversion Using Microcontroller Education Boards
Analog to Digital Conversion Using Microcontroller Education BoardsKyle VanDruten
 
Introducing the Arduino
Introducing the ArduinoIntroducing the Arduino
Introducing the ArduinoCharles A B Jr
 
Microcontroller arduino uno board
Microcontroller arduino uno boardMicrocontroller arduino uno board
Microcontroller arduino uno boardGaurav
 

What's hot (20)

Arduino Programming Software Development
Arduino Programming Software DevelopmentArduino Programming Software Development
Arduino Programming Software Development
 
Iot development from prototype to production
Iot development from prototype to productionIot development from prototype to production
Iot development from prototype to production
 
Introduction To Arduino
Introduction To ArduinoIntroduction To Arduino
Introduction To Arduino
 
Arduino Based Smart Parking System
Arduino Based Smart Parking SystemArduino Based Smart Parking System
Arduino Based Smart Parking System
 
Show & Tell.- Introduction
Show & Tell.- IntroductionShow & Tell.- Introduction
Show & Tell.- Introduction
 
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & ArduinoEchelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
 
Microcontrollers (Rex St. John)
Microcontrollers (Rex St. John)Microcontrollers (Rex St. John)
Microcontrollers (Rex St. John)
 
Embedded system introduction - Arduino Course
Embedded system introduction - Arduino CourseEmbedded system introduction - Arduino Course
Embedded system introduction - Arduino Course
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Intro to Arduino.ppt
Intro to Arduino.pptIntro to Arduino.ppt
Intro to Arduino.ppt
 
WHD global 2017 - Smart Power Plant
WHD global 2017 - Smart Power PlantWHD global 2017 - Smart Power Plant
WHD global 2017 - Smart Power Plant
 
Wi-Fi Esp8266 nodemcu
Wi-Fi Esp8266 nodemcu Wi-Fi Esp8266 nodemcu
Wi-Fi Esp8266 nodemcu
 
Particle Core
Particle Core Particle Core
Particle Core
 
Arduino day
Arduino dayArduino day
Arduino day
 
Arduino and Internet of Thinks: ShareIT TM: march 2010, TM
Arduino and Internet of Thinks: ShareIT TM: march 2010, TMArduino and Internet of Thinks: ShareIT TM: march 2010, TM
Arduino and Internet of Thinks: ShareIT TM: march 2010, TM
 
Analog to Digital Conversion Using Microcontroller Education Boards
Analog to Digital Conversion Using Microcontroller Education BoardsAnalog to Digital Conversion Using Microcontroller Education Boards
Analog to Digital Conversion Using Microcontroller Education Boards
 
Introducing the Arduino
Introducing the ArduinoIntroducing the Arduino
Introducing the Arduino
 
Brain controlled robot
Brain controlled robotBrain controlled robot
Brain controlled robot
 
Microcontroller arduino uno board
Microcontroller arduino uno boardMicrocontroller arduino uno board
Microcontroller arduino uno board
 
Internet of Things
Internet of ThingsInternet of Things
Internet of Things
 

Similar to Connect.Tech- Android Development For Arduino 101

Hack the Real World with ANDROID THINGS
Hack the Real World with ANDROID THINGSHack the Real World with ANDROID THINGS
Hack the Real World with ANDROID THINGSDevFest DC
 
Internet of things
Internet of thingsInternet of things
Internet of thingsBrockanurag
 
Internet of things - The Present & The Future
Internet of things - The Present & The FutureInternet of things - The Present & The Future
Internet of things - The Present & The Futureiotians
 
Taller IoT en la Actualidad
Taller IoT en la ActualidadTaller IoT en la Actualidad
Taller IoT en la ActualidadLaurence HR
 
Intel IoT Edge Computing 在 AI 領域的應用與商機
Intel IoT Edge Computing 在 AI 領域的應用與商機Intel IoT Edge Computing 在 AI 領域的應用與商機
Intel IoT Edge Computing 在 AI 領域的應用與商機Amazon Web Services
 
arduino 320126512170.pptx
arduino 320126512170.pptxarduino 320126512170.pptx
arduino 320126512170.pptxpriyaanaparthy
 
Global Azure Bootcamp 2016 - Real-world Internet of Things Backend with Azure...
Global Azure Bootcamp 2016 - Real-world Internet of Things Backend with Azure...Global Azure Bootcamp 2016 - Real-world Internet of Things Backend with Azure...
Global Azure Bootcamp 2016 - Real-world Internet of Things Backend with Azure...Andri Yadi
 
Bare metal Javascript & GPIO programming in Linux
Bare metal Javascript & GPIO programming in LinuxBare metal Javascript & GPIO programming in Linux
Bare metal Javascript & GPIO programming in LinuxAlexander Vanwynsberghe
 
How To Electrocute Yourself using the Internet
How To Electrocute Yourself using the InternetHow To Electrocute Yourself using the Internet
How To Electrocute Yourself using the InternetAlexander Roche
 
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...
Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/...Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/...
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...The Internet of Things Methodology
 
ARUDINO UNO and RasberryPi with Python
 ARUDINO UNO and RasberryPi with Python ARUDINO UNO and RasberryPi with Python
ARUDINO UNO and RasberryPi with PythonJayanthi Kannan MK
 
Interoperability in Internet of Things (IOT)
Interoperability in Internet of Things (IOT)Interoperability in Internet of Things (IOT)
Interoperability in Internet of Things (IOT)manditalaskar123
 
RAHUL NASKAR IOT.ppt
RAHUL NASKAR IOT.pptRAHUL NASKAR IOT.ppt
RAHUL NASKAR IOT.pptPrakasBhowmik
 
Road to Republic of IoT - IoT Technologies & Machine Learning
Road to Republic of IoT - IoT Technologies & Machine LearningRoad to Republic of IoT - IoT Technologies & Machine Learning
Road to Republic of IoT - IoT Technologies & Machine LearningAndri Yadi
 
Introduction to iot and arduino uno r3
Introduction to iot and arduino uno r3Introduction to iot and arduino uno r3
Introduction to iot and arduino uno r3Saurav Chaudhary
 
Internet of things (IoT) with Azure
Internet of things (IoT) with AzureInternet of things (IoT) with Azure
Internet of things (IoT) with AzureVinoth Rajagopalan
 
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...Codemotion
 
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...Codemotion
 

Similar to Connect.Tech- Android Development For Arduino 101 (20)

Hack the Real World with ANDROID THINGS
Hack the Real World with ANDROID THINGSHack the Real World with ANDROID THINGS
Hack the Real World with ANDROID THINGS
 
Internet of things
Internet of thingsInternet of things
Internet of things
 
Internet of things - The Present & The Future
Internet of things - The Present & The FutureInternet of things - The Present & The Future
Internet of things - The Present & The Future
 
Tech Talk IOT
Tech Talk IOTTech Talk IOT
Tech Talk IOT
 
Taller IoT en la Actualidad
Taller IoT en la ActualidadTaller IoT en la Actualidad
Taller IoT en la Actualidad
 
Intel IoT Edge Computing 在 AI 領域的應用與商機
Intel IoT Edge Computing 在 AI 領域的應用與商機Intel IoT Edge Computing 在 AI 領域的應用與商機
Intel IoT Edge Computing 在 AI 領域的應用與商機
 
arduino 320126512170.pptx
arduino 320126512170.pptxarduino 320126512170.pptx
arduino 320126512170.pptx
 
Global Azure Bootcamp 2016 - Real-world Internet of Things Backend with Azure...
Global Azure Bootcamp 2016 - Real-world Internet of Things Backend with Azure...Global Azure Bootcamp 2016 - Real-world Internet of Things Backend with Azure...
Global Azure Bootcamp 2016 - Real-world Internet of Things Backend with Azure...
 
Bare metal Javascript & GPIO programming in Linux
Bare metal Javascript & GPIO programming in LinuxBare metal Javascript & GPIO programming in Linux
Bare metal Javascript & GPIO programming in Linux
 
How To Electrocute Yourself using the Internet
How To Electrocute Yourself using the InternetHow To Electrocute Yourself using the Internet
How To Electrocute Yourself using the Internet
 
Android meets Arduino
Android meets ArduinoAndroid meets Arduino
Android meets Arduino
 
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...
Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/...Getting Started with the Internet of Things  - Allianz Hackrisk Hackathon 29/...
Getting Started with the Internet of Things - Allianz Hackrisk Hackathon 29/...
 
ARUDINO UNO and RasberryPi with Python
 ARUDINO UNO and RasberryPi with Python ARUDINO UNO and RasberryPi with Python
ARUDINO UNO and RasberryPi with Python
 
Interoperability in Internet of Things (IOT)
Interoperability in Internet of Things (IOT)Interoperability in Internet of Things (IOT)
Interoperability in Internet of Things (IOT)
 
RAHUL NASKAR IOT.ppt
RAHUL NASKAR IOT.pptRAHUL NASKAR IOT.ppt
RAHUL NASKAR IOT.ppt
 
Road to Republic of IoT - IoT Technologies & Machine Learning
Road to Republic of IoT - IoT Technologies & Machine LearningRoad to Republic of IoT - IoT Technologies & Machine Learning
Road to Republic of IoT - IoT Technologies & Machine Learning
 
Introduction to iot and arduino uno r3
Introduction to iot and arduino uno r3Introduction to iot and arduino uno r3
Introduction to iot and arduino uno r3
 
Internet of things (IoT) with Azure
Internet of things (IoT) with AzureInternet of things (IoT) with Azure
Internet of things (IoT) with Azure
 
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
 
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
 

More from stable|kernel

Mobile Development For Arduino 201 - ConnectTech
Mobile Development For Arduino 201 - ConnectTechMobile Development For Arduino 201 - ConnectTech
Mobile Development For Arduino 201 - ConnectTechstable|kernel
 
Striking a Balance With UI Tests - ConnectTech
Striking a Balance With UI Tests - ConnectTechStriking a Balance With UI Tests - ConnectTech
Striking a Balance With UI Tests - ConnectTechstable|kernel
 
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor ExtensionsConnect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensionsstable|kernel
 
Connect.Tech- Aqueduct: A server-side framework in Dart
Connect.Tech- Aqueduct: A server-side framework in DartConnect.Tech- Aqueduct: A server-side framework in Dart
Connect.Tech- Aqueduct: A server-side framework in Dartstable|kernel
 
Connect.Tech- Level Up Your Game With TravisCI
Connect.Tech- Level Up Your Game With TravisCIConnect.Tech- Level Up Your Game With TravisCI
Connect.Tech- Level Up Your Game With TravisCIstable|kernel
 
Connect.Tech- Swift Memory Management
Connect.Tech- Swift Memory ManagementConnect.Tech- Swift Memory Management
Connect.Tech- Swift Memory Managementstable|kernel
 

More from stable|kernel (6)

Mobile Development For Arduino 201 - ConnectTech
Mobile Development For Arduino 201 - ConnectTechMobile Development For Arduino 201 - ConnectTech
Mobile Development For Arduino 201 - ConnectTech
 
Striking a Balance With UI Tests - ConnectTech
Striking a Balance With UI Tests - ConnectTechStriking a Balance With UI Tests - ConnectTech
Striking a Balance With UI Tests - ConnectTech
 
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor ExtensionsConnect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
 
Connect.Tech- Aqueduct: A server-side framework in Dart
Connect.Tech- Aqueduct: A server-side framework in DartConnect.Tech- Aqueduct: A server-side framework in Dart
Connect.Tech- Aqueduct: A server-side framework in Dart
 
Connect.Tech- Level Up Your Game With TravisCI
Connect.Tech- Level Up Your Game With TravisCIConnect.Tech- Level Up Your Game With TravisCI
Connect.Tech- Level Up Your Game With TravisCI
 
Connect.Tech- Swift Memory Management
Connect.Tech- Swift Memory ManagementConnect.Tech- Swift Memory Management
Connect.Tech- Swift Memory Management
 

Recently uploaded

why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 

Recently uploaded (20)

why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 

Connect.Tech- Android Development For Arduino 101

  • 1. Android Development For Arduino 101 By: Bryan Jones Richardson Software Engineer stable|kernel
 bryan.richardson@stablekernel.com stablekernel.com
  • 2. We’re stable|kernel. stable|kernel is an Atlanta-based mobile development company 
 to craft smartly-designed mobile applications that connect brands 
 directly with their users. 
 

  • 3. The Internet of Things? @stablekernel
  • 4. @stablekernel The internet of things (IoT) is the network of physical devices, embedded with electronics, software, sensors, actuators, and network connectivity that enable them to collect and exchange data. • Transportation (Street Lights) • Healthcare • Agriculture • Durables & Wearable • Object Oriented World
  • 6. @stablekernel Arduino is an open-source electronics platform based on easy-to-use hardware and software. It's intended for anyone making interactive projects. (Basically, a small computer that you can connect to anything). • Uno • Mega • Yun • Minimal Cost Barriers • Raspberry Pi, Edison, etc.
  • 7.
  • 8.
  • 11. Android & Arduino via USB @stablekernel
  • 12. @stablekernel Android USB Classes • UsbManager • UsbDevice • UsbDeviceConnection • UsbInterface • UsbEndpoint • UsbConstants
  • 13. @stablekernel Detect Android USB Connection private final BroadcastReceiver usbConnectionAttachedReceiver = new BroadcastReceiver() { @Override public void onReceive(@NonNull Context context, @NonNull Intent intent) { activeUsbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); connectUsb(); } }; private final BroadcastReceiver usbConnectionDetachedReceiver = new BroadcastReceiver() { @Override public void onReceive(@NonNull Context context, @NonNull Intent intent) { UsbDevice detachedDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); if (detachedDevice == activeUsbDevice) { disconnectUsb(); } } };
  • 14. @stablekernel Determine if Arduino is Connected for (int i = 0; i < activeUsbDevice.getInterfaceCount(); i++) { UsbInterface usbInterface = activeUsbDevice.getInterface(i); if (usbInterface.getEndpointCount() == 2) { for (int j = 0; j < endpointCount; j++) { UsbEndpoint endpoint = usbInterface.getEndpoint(j); if (endpoint.getType() != UsbConstants.USB_ENDPOINT_XFER_BULK) { continue; } if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) { endpointOut = usbInterface.getEndpoint(j); } else if (endpoint.getDirection() == UsbConstants.USB_DIR_IN) { endpointIn = usbInterface.getEndpoint(j); } } } } }
  • 15. @stablekernel Establish Communication w/ Arduino private void setupUSBComm() { UsbManager manager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE); Boolean permitToRead = manager.hasPermission(arduinoDevice); if (permitToRead) { connection = manager.openDevice(arduinoDevice); if (connection != null) { connection.claimInterface(activeUSBInterface, true); //requestType, SET_CONTROL_LINE_STATE, value, index, buffer, length, timeout connection.controlTransfer(RQSID_SET_REQUEST_TYPE, RQSID_SET_CONTROL_LINE_STATE, 0, 0, null, 0, 0); connection.controlTransfer(RQSID_SET_REQUEST_TYPE, RQSID_SET_LINE_CODING, 0, 0, encodingSetting, 7, 0); } } else { manager.requestPermission(arduinoDevice, permissionIntent); } }
  • 16. @stablekernel Send Android Data to Arduino @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { playNote(position); } public void playNote(int note_value) { byte[] bytesOut = new byte[]{ (byte) note_value}; if(arduinoDevice != null) { usbArduinoConnection.bulkTransfer(endpointOut, bytesOut, 1, 0); } }
  • 17. @stablekernel Process Android Data on Arduino int speakerPin = 9; int tones[] = { 440, 494, 523, 587, 659, 698, 784}; void setup() { pinMode(speakerPin, OUTPUT); Serial.begin(9600); } void loop() { if (Serial.available()) { int incomingByte = Serial.read(); if (incomingByte > -1) { playNote(incomingByte); } } } void playNote(int note) { tone(speakerPin, tones[note], 200); }
  • 18. @stablekernel Hardware Setup Ground Pin 9 Piezo BreadBoardUno USB
  • 19. Android & Arduino via Bluetooth @stablekernel
  • 20. @stablekernel Android Bluetooth Classes <uses-permission android:name = "android.permission.BLUETOOTH_ADMIN"/> <uses-permission android:name = “android.permission.BLUETOOTH”/> private BluetoothAdapter bluetoothAdapter; private BluetoothSocket bluetoothSocket; private Set<BluetoothDevice> pairedBluetoothDevices; static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  • 21. @stablekernel Connect To BlueTooth Device bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); BluetoothDevice btDevice = bluetoothAdapter.getRemoteDevice(bluetoothAddress); btSocket = btDevice.createInsecureRfcommSocketToServiceRecord(myUUID); BluetoothAdapter.getDefaultAdapter().cancelDiscovery(); btSocket.connect();
  • 22. @stablekernel Send Android Data to Arduino byte[] bytesOut = new byte[]{ note_value }; try { btSocket.getOutputStream().write(bytesOut); } catch (IOException e) { // handle exception }
  • 24. @stablekernel Debugging on Arduino digitalWrite(ledPin, LOW); digitalWrite(ledPin, HIGH); serialPrint(…);
  • 26. Android & Arduino via Network @stablekernel
  • 30. @stablekernel Implement Arduino Code #include <Bridge.h> #include <YunServer.h> #include <YunClient.h> YunServer server; ...
  • 31. @stablekernel Implement Arduino Code void setup() { ... Bridge.begin(); server.listenOnLocalhost(); server.begin(); }
  • 32. @stablekernel Implement Arduino Code void loop() { YunClient client = server.accept(); if (client) { process(client); client.stop(); } delay(50); } void process(YunClient client) { String incomingNote = client.readStringUntil('/'); playNote(incomingNote.toInt()); }
  • 33. @stablekernel Send Android Data to Arduino Yun @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); String[] musicalNotes = new String[] { "A","B","C","D","E","F","G"}; ArrayAdapter<String> musicalNotesAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, musicalNotes); notesListView.setOnItemClickListener(this); notesListView.setAdapter(musicalNotesAdapter); } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String note = String.valueOf(position); HttpClient client = new DefaultHttpClient(); String URL = “http://10.0.0.19/arduino/“ + note; HttpGet request = new HttpGet(URL); ResponseHandler<String> responseHandler = new BasicResponseHandler(); client.execute(httpget, responseHandler); }
  • 36. Questions? Business Inquiries: Sarah Woodward Director of Business Development sarah.woodward@stablekernel.com Bryan Jones Richardson Software Engineer bryan.richardson@stablekernel.cm blog.stablekernel.com