Pages: [1]   Go Down
Author Topic: Android tablet with Arduino UNO communication over USB - basic program  (Read 6850 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I just bought Arduino UNO and i would like to switch on and off LED 13 from Android tablet (Nexus 7). Can someone gime me some tutorial how to set up USB communication from both sides (Arduino-Android) where Android tablet is host.

Thanks for help

 
Logged

BHZ, MG, Brazil
Offline Offline
Sr. Member
****
Karma: 10
Posts: 346
Android developer; Arduino enthusiast
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Unless you have the USB shield (which turns the Uno into a host as well) or use the Arduino Leonardo or the Arduino MEGA ADK, you can't simply connect the 2 devices via USB and expect them to work.

Your PC doesn't seem the UNO's USB port. What it sees is a serial port that the UNO emulates through USB. That is called a "Virtual COM Port", and part of the magic is done through drivers. Unless you have those drivers written and compiled for Android (they have to be very specific to your android and kernel versions), what you want can't be done.
Logged

Learn to live: Live to learn.
Showing off my work: http://arduino.cc/forum/index.php/topic,126197.0.html

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 30
Posts: 1670
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I understand your best bet is to use bluetooth. Some people have had success with the BlueTerm app. Much kooler too.....
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I understand that. Now i can see when i connect Arduino to Android tablet that arduino is powered and working (Flashing LED from program Blink). I guess that means that Tablet is working as Host. Now i shloud access normal Android USB API to send message over Serial port to Arduino. Where i can received it and turn LED on - off. Can this work?
Logged

BHZ, MG, Brazil
Offline Offline
Sr. Member
****
Karma: 10
Posts: 346
Android developer; Arduino enthusiast
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I understand that. Now i can see when i connect Arduino to Android tablet that arduino is powered and working (Flashing LED from program Blink). I guess that means that Tablet is working as Host. Now i shloud access normal Android USB API to send message over Serial port to Arduino. Where i can received it and turn LED on - off. Can this work?

All that says is that the tablet is powering the Arduino, nothing else. Since it is powered, it is running the sketch in it.

Please try and understand that 1 of the 2 conditions must be true:

- BOTH devices need to be HOST
- The tablet must have the Virtual COM Port driver installed.
Logged

Learn to live: Live to learn.
Showing off my work: http://arduino.cc/forum/index.php/topic,126197.0.html

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 50
Posts: 1766
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It depends on your cell phone.  On my Galaxy S-II, I can buy a USB host cable and then connect it via a few APPs, and the apps transmit serial data that you can read/write with the Serial class.

As others have said, bluetooth is an option as well.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have at home one JY-MCU i guess that i need to connect (Arduino UNO -> JY-MCU) RX->RXD, TX->TXD, 3.3V->VCC , GND(Two options) -> GND and bluetoth module shloud be connected. Is there any simple program for bluetooth ECHO (recieved and send back) on Arduino site? Android side program i already have. 

Sorry for this stupid questions but this languge made from C++, Java and Assembler language is really hard for me.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 65
Posts: 2926
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have at home one JY-MCU i guess that i need to connect (Arduino UNO -> JY-MCU) RX->RXD, TX->TXD, 3.3V->VCC , GND(Two options) -> GND and bluetoth module shloud be connected. Is there any simple program for bluetooth ECHO (recieved and send back) on Arduino site? Android side program i already have. 

Sorry for this stupid questions but this languge made from C++, Java and Assembler language is really hard for me.

Bluetooth is wireless serial, so what you can do is, write a simple sketch on the arduino to look at the serial monitor and do a function.
Many start with the Led ON/OFF test. But for an echo test, you would simply store the incoming chars from Serial.read() and send them right back out with Serial.write(), or Serial.print().
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could i ask you for sketch that will turn ON/OFF Led when recieved something form bluetooth if you have any? I really need something where i can start if you would be so kind.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 65
Posts: 2926
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This uses the on-board LED located next to pin 13.
Code:

void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
char state = Serial.read();
   if(state == 'H' ||state == 'h' || state == '1') {
      digitalWrite(13, HIGH);
   } //end of if

   else if (state == 'L' || state == 'l' || state == '0') {
     digitalWrite(13, LOW);
  } //end of else if

  else {
    //do nothing
  } //end of else
}// end of loop
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Sweden
Offline Offline
Sr. Member
****
Karma: 11
Posts: 253
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You only need HOST on one side for this to work.. My phone (HTC One X) and tablet (ASUS TF300) can both act as HOST and work flawlessly over USB with my UNO (NO HOST-SHIELD!!!!!!!)... Upload a Serial sketch to your UNO and download the following app to your phone/tablet: https://play.google.com/store/apps/details?id=jp.ksksue.app.terminal&feature=search_result#?t=W251bGwsMSwxLDEsImpwLmtza3N1ZS5hcHAudGVybWluYWwiXQ.... It's a free and simple app that communicates through USB Serial..
Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 50
Posts: 1766
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You only need HOST on one side for this to work.. My phone (HTC One X) and tablet (ASUS TF300) can both act as HOST and work flawlessly over USB with my UNO (NO HOST-SHIELD!!!!!!!)...
Obviously, if you plug an Arduino into an Android device without a secondary battery, the Android device is going to power the Arduino, and drain the batteries much quicker.  Given how power hungry modern smart phones and tablets are, this may be an issue if you use the phone/tablet/arduino for a long period of time.
« Last Edit: April 03, 2013, 11:16:52 am by MichaelMeissner » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for reply when i tried this and connected bluetooth module to it and try to uploud sketch on it i got
avrdude: stk500_getsync(): not in sync: resp=0x04
I can connect to bluetooth module and when i send something i can see that LED diode TX goes ON for second but nothing happens. But Led 13 is all time ON. When i unpluged bluetooth module message disappeared. Can someone help me?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You only need HOST on one side for this to work.. My phone (HTC One X) and tablet (ASUS TF300) can both act as HOST and work flawlessly over USB with my UNO (NO HOST-SHIELD!!!!!!!)... Upload a Serial sketch to your UNO and download the following app to your phone/tablet: https://play.google.com/store/apps/details?id=jp.ksksue.app.terminal&feature=search_result#?t=W251bGwsMSwxLDEsImpwLmtza3N1ZS5hcHAudGVybWluYWwiXQ.... It's a free and simple app that communicates through USB Serial..

How that serial sketch shloud look like?
Logged

Pages: [1]   Go Up
Jump to: