Go Down

Topic: Android tablet with Arduino UNO communication over USB - basic program (Read 11 times) previous topic - next topic

kuburoman

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


AlxDroidDev

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.
Learn to live: Live to learn.
Showing off my work: http://arduino.cc/forum/index.php/topic,126197.0.html

Nick_Pyner

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

kuburoman

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?

AlxDroidDev


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.
Learn to live: Live to learn.
Showing off my work: http://arduino.cc/forum/index.php/topic,126197.0.html

MichaelMeissner

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.

kuburoman

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.

HazardsMind


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().
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

kuburoman

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.

HazardsMind

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


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
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

baselsw

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..

MichaelMeissner

#11
Apr 03, 2013, 06:09 pm Last Edit: Apr 03, 2013, 06:16 pm by MichaelMeissner Reason: 1

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.

kuburoman

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?

kuburoman


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?

pushthebutton

#14
Sep 02, 2014, 03:25 pm Last Edit: Sep 02, 2014, 03:27 pm by pushthebutton Reason: 1


Hello baselsw. I have an arduino pro with the usb-serial-ftdi shield. Do you think it's possible to find a cable to connect those two? Would I have to make it? If the arduino pro is externally powered, it should work, right?


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..

Go Up