1

I'm trying to connect Arduino Leonardo to an Android tablet. I would like to make the Arduino send commands (using pushbuttons or a slider for example) to the tablet to switch between pages, to select a file on the desktop, to scroll up and down the screen, etc.

0

4 Answers 4

1

Perhaps this is not exactly what you are looking for, but from your examples it seems like using navigational commands from the keayboard/mouse would accomplish a lot of what you are requesting.

Android has USB HID support from honecomb, so you should be able to create a sketch to emulate a keyboard and mouse based on the IO data and it should work with your android device just by plugging the USB cable (if emulating a mouse, it will display the mouse cursor as soon as it is connected).

-1

First, get a Lightblue Bean, http://punchthrough.com/bean/

It has everything you need: - arduino - bluetooth - API - code example - android sdk - ...

Develop your product using this platform.

If you want to scale and build your own platform, then you will have a foundation to validate your work.

2
  • Half you answers refer to this product. Are you associated with it? You need to disclose any personal stake in it if you are. Commented Oct 2, 2014 at 20:22
  • not associated with the company, but a happy customer of their product. Commented Oct 13, 2014 at 19:07
-1

It is a good idea to use a LightBlue Bean, only if you are using the Android SDK! https://bitbucket.org/littlerobots/beanlib

You can read more about the SDK, and get advice from people who are actually using it. http://beantalk.punchthrough.com/t/announcing-unofficial-android-sdk/394

-1

Android code:

function OnStart() {
    //Create a layout with objects vertically centered.
    lay = app.CreateLayout("linear", "VCenter,FillXY")  

    //Create a toggle button.
    btn = app.CreateToggle("LED On/Off", 0.4)
    btn.SetOnTouch(btn_OnTouch)
    lay.AddChild(btn)

    //Add layout to app.    
    app.AddLayout(lay)

    //Create USB serial object.
    usb = app.CreateUSBSerial() 
    if (!usb) {
        app.ShowPopup("Please connect your Arduino and restart")
        return;
    }
    usb.SetOnReceive(usb_OnReceive)
    app.ShowPopup("Connected")
}

//Called when user touches our toggle button.
function btn_OnTouch(isChecked) {
    if (!usb) return;
   
    //Send LED command to Uno.
    if (isChecked) usb.Write("ledh")
    else usb.Write("ledl")
}

//Called when we get data from Espruino.
function usb_OnReceive(data) {
   console.log(data)
}

Arduino code:

void setup() {
  pinMode(2,1);
  serial.begin(9600);
    
  loop() {
    if (serial.Read()="ledh) {
      digitalWrite(2,1);
    }
    if (serial.Read()="ledl) {
      digitalWrite(2,0);
    }
  }
}
2
  • 2
    The Arduino code has clear syntax errors; please review. Commented Jul 28, 2022 at 5:00
  • 2
    this doesn't answer the question. OP wants to use USB HID capability (emulate keyboard) of the Leonardo Commented Jul 28, 2022 at 5:48

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.