Android Question Arduino > Android USB connection

Discussion in 'Android Questions' started by Declan, Sep 8, 2015.

  1. Declan

    Declan Active Member Licensed User

    Hi,
    Please be gentle - I am a complete newbie :(
    I have purchased the Full Version of B4A and am looking for an example of an app that will read messages sent from an Arduino UNO R3 connected to the USB port of my Android Tablet and display the message in a window.
    The message is sent at regular intervals from the Arduino UNO.
    What I am trying to mimic is that the Android Tablet will act as a Serial Monitor (similar to the Serial Monitor in the Arduino IDE).
    All the examples that I have found are way more complex than expect and after reading and searching for hours - I finally succumb.
     
  2. giga

    giga Well-Known Member Licensed User

  3. Declan

    Declan Active Member Licensed User

    Yes, I did.
    However, that refers to the Arduino Mega 2560 or Mega ADK.
    If I select either of those Arduino boards in the Arduino IDE, the code compiles with no problem.
    But the code will not compile if I select the Arduino UNO board in the Arduino IDE.

    The errors on compile are:
    C:\Program Files\Arduino\libraries\USB_Host_Shield\Max3421e.cpp: In static member function 'static void MAX3421E::setRST(uint8_t)':
    C:\Program Files\Arduino\libraries\USB_Host_Shield\Max3421e.cpp:58: error: 'PORTJ' was not declared in this scope
    C:\Program Files\Arduino\libraries\USB_Host_Shield\Max3421e.cpp:58: error: 'PJ2' was not declared in this scope
    C:\Program Files\Arduino\libraries\USB_Host_Shield\Max3421e.cpp:60: error: 'PORTJ' was not declared in this scope
    C:\Program Files\Arduino\libraries\USB_Host_Shield\Max3421e.cpp:60: error: 'PJ2' was not declared in this scope
    C:\Program Files\Arduino\libraries\USB_Host_Shield\Max3421e.cpp: In static member function 'static uint8_t MAX3421E::readINT()':
    C:\Program Files\Arduino\libraries\USB_Host_Shield\Max3421e.cpp:65: error: 'PINE' was not declared in this scope
    C:\Program Files\Arduino\libraries\USB_Host_Shield\Max3421e.cpp:65: error: 'PE6' was not declared in this scope
    C:\Program Files\Arduino\libraries\USB_Host_Shield\Max3421e.cpp: In static member function 'static void MAX3421E::pinInit()':
    C:\Program Files\Arduino\libraries\USB_Host_Shield\Max3421e.cpp:77: error: 'DDRE' was not declared in this scope
    C:\Program Files\Arduino\libraries\USB_Host_Shield\Max3421e.cpp:77: error: 'PE6' was not declared in this scope
    C:\Program Files\Arduino\libraries\USB_Host_Shield\Max3421e.cpp:78: error: 'DDRJ' was not declared in this scope
    C:\Program Files\Arduino\libraries\USB_Host_Shield\Max3421e.cpp:78: error: 'PJ2' was not declared in this scope
     
  4. Licht2002

    Licht2002 Member Licensed User

  5. camolas

    camolas Member Licensed User

  6. Declan

    Declan Active Member Licensed User

    Thanks Licht2002,
    That worked for me and I can see the data coming in to a edittext control that I placed in the Android app.
    This needs a bit of work on so that I can filter-out the data I need from the received message.
    I can also send a message to the Arduino (to change certain parameters in the Arduino) which seems to be working OK.

    I am busy searching for some code examples of reading the message received with Astreams_NewData.
    I need to wait - or fill the Buffer - until a ETX character arrives ("#"), then I have a complete string.
    The message that is received is "$2,19,0,1,155#. The commas "," are delimiters.
    Where:
    $ = STX
    2 = Device number (from an I2C bus on the Arduino)
    19 = Sensor Data
    0 = Sensor Fault condition (if any)
    1 = Sensor Output State
    155 = Sensor Setpoint.
    # = ETX (End of Text)

    So, I need to wait for the "#" to confirm complete string received.
    If complete string is received, I must extract (parse) the data between the delimiters (",").
     
  7. Declan

    Declan Active Member Licensed User

    Tom,
    Checking the manifest, the code below was already inserted.
    Is that what you mean?
     
  8. Roycefer

    Roycefer Well-Known Member Licensed User

    If you don't need access to the raw bytes, you're better off using the AsyncStreamsText class which will give you a simple to use _NewText(Text as String) event. This class takes care of waiting for the buffer to fill, end of message characters, etc... In your example, you would receive "2,19,0,1,155" in the _NewText() event and you need only use Regex.Split(",", Text) to split it up into an array.
     
  9. Declan

    Declan Active Member Licensed User

    The AsyncStreamsText did not work for me:
    After the USB connection, the app bombs
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice