Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8126457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:09:17+00:00 2026-06-06T07:09:17+00:00

I followed this tutorial to get started using Android host api with an Arduino

  • 0

I followed this tutorial to get started using Android host api with an Arduino board. I am using the Arduino Uno. I am able to transmit data and turn on a LED on the Arduino board and I can receive feedback from the Arduino board. I am trying to write to my Android device over the USB connection from the Arduino board like so:

 Serial.print("Test");

I am receiving the Arduino data on the Android side like this:

byte[] buffer = new byte[10];
int bytes;
//try-catch statements omitted for simplicity
bytes = mUsbConnection.bulkTransfer(mUsbEndpointIn, buffer, buffer.length, 0);

Every once and awhile the data will be intact but more often than not, what I receive from the Arduino is a garbled mix of those letters from my original message(t,e,s, and t). Many times only 1 or 2 letters are displayed. If anyone could point me in the right direction or share some similar experience I would be appreciative. Thanks.

Edit

When I print out the data into Logcat, there are multiple copies of the data. For example, if I receive "ste" from Arduino, it will be printed out 2-5 times in Logcat.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:09:19+00:00Added an answer on June 6, 2026 at 7:09 am

    I think I found something that works at least temporarily:

    public void run(){
    
            int i = 0;
    
            byte[] buffer = new byte[4];
            byte[] finalBuffer = new byte[8];
            byte[] sendBuffer = new byte[8];
    
            int bytes = 0;
    
            while(true){
                try{
    
                    bytes = mUsbConnection.bulkTransfer(mUsbEndpointIn, buffer, buffer.length, 0);
    
                    if (bytes == EXIT_CMD) { 
                        return;
                    } 
    
                    if (bytes > 0){
    
                        byte[] temporaryBuffer = new byte[bytes];
    
                        System.arraycopy(buffer, 0, temporaryBuffer, 0, bytes);
    
                        System.arraycopy(temporaryBuffer, 0, finalBuffer, i, bytes);
    
                        i += bytes;
    
                        java.util.Arrays.fill(buffer, (byte) 0);
                    }
    
                    //Dollar sign terminates string to indicate end of line
                    if (finalBuffer[7] == 36){
    
                        i = 0;
    
                        System.arraycopy(finalBuffer, 0, sendBuffer, 0, sendBuffer.length); 
    
                        messageHandler.obtainMessage(UsbHostTestActivity.ARDUINO_MESSAGE, 
                                sendBuffer.length, -1, sendBuffer).sendToTarget();
    
                        java.util.Arrays.fill(finalBuffer, (byte) 0);
                    }
    

    I had to send strings that were 8 characters exactly from Arduino and they had to end with a dollar sign($) in order to indicate the end of the line, but the data being passed to my message handler always seemed to be correct. It’s not the most robust solution but maybe someone can modify it to make it better or take another approach? Please let me know!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have followed this tutorial to get my ListView populating data -- http://android.amberfog.com/?p=296 .
My computer runs Ubuntu 12.04 and I followed this tutorial to get started with
I followed this tutorial: https://github.com/EllisLab/CodeIgniter/wiki/PDF-generation-using-dompdf However, I can't seem to set the path right.
I followed this tutorial http://www.tugberkugurlu.com/archive/api-key-authorization-through-query-string-in-asp-net-web-api-authorizationfilterattribute to create custom Authorization filter. I have CarController with
I've followed this tutorial but when I try to run the application I get
I've followed this tutorial to get a Cocoa application that plays mov files in
i am using a php script (followed this tutorial http://www.bitconsultants.net/2010/geocoding-with-google-maps-and-the-zend-framework/ ) to get the
I just made a Chrome extension. I followed this tutorial to get a nice
I just started getting into node.js and followed this great tutorial on node.js at
I followed this tutorial to create a color state list for a particular Android

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.