Abbott Analytical Products

Raleigh, North Carolina, USA
Local Weather


Copyright © 1988-2021 by Abbott Analytical Products. All Rights Reserved.

Contents of Page

This web page contains a disclaimer/license, a brief discussion concerning evolution of this "Gamepad-Arduino-OTG-Android" subsystem, a set of references, and a collection of helpful details. Additional details are provided on Page 2.

Disclaimer/License:

1> No warranty is made regarding the servicability or fitness for use of this Gamepad-OTG subsystem.

2> A user may employ, enjoy, or engage in this project under the terms of he GNU General Public License (GNU GPL or GPL) as OpenSource software licenses that guarantee end users the freedom to run, study, share, and modify the software. All copyrights privildeges are reserved.



Evolution of Project

The goal of this project was to provide a gamepad style user interface that could communicate via the Android as a front-end for remote control of the squirrel-chase vehicle.

Working Assumptions:

The working assumptions are:

Reference:

Note: ** Some browsers do not allow links to these sites from their anchors.

Gamepad -OTG- Android Host

Project Conclusion

This project concluded by demonsrating the feasibility of controlling a ground mobile vehicle using a "Gamepad style navigation" over OTG with an Android device serving as Host. It also demonstrate feasibility of Compass style navigation Android app for controlling the same vehicle. Finally it demonstrated that the Android could transmit/receive vehicle motion control data bundles WIFI UDP access point to effectively control a vehicle.


Link to first Road Test 200927


Link to second Road Test 201005


Link to third and final Road Test 210103



Project Summary

The original vision for this project to provide a user front-end of a second generation squirrel-chaser. The first generation of squirrel-chaser employed an Arduino driven vehicle which was controlled via WiFI from an Android tablet. Initial testing of the first generation squirrel-chaser produced a static run video video and a active motion test video. But producing these two videos quickly demonstrated the "need for a user control interface" that support a "gamepad" style user interface, UI.

The first order criteria for fulfilling that "need" quickly focused on a gamepad component UI front-end connected to an Android tablet. A second order criteria was the utilization of material/components already on hand. The third order criteria was to employ the MIT App2Inventor development, A2I, platform for the Android. This criteria allowed the re-use of the work already successfully completed during the first generation of the squirrel-chaser.

The initial solution suggested using the available Logitech F310. The Ubuntu PC operating system had two drivers, xboxdrv and xpad, available to support the F310. Also there is a host of applicaations that data could readily be transferred. That solution was discarded after painfully learning that there was no OpenSource driver available for the Android. It was determined that de-engineering of the available drivers was feasible. But although feasible there was a very high risk due to the learning curve of the tools involved.

Looking around the lab/shop suggested that there was at least one alternate solution. That first alternate solution included an Makeblock Orion Inventor Electronic Kit (UNO board, joystick, potentiometer, rj25 adapter board), an available OTG cable, Arduino prototype boards, test clips, etc.

After gathering and assembling the components for the proposed first solution the focus of the project's effort returned to the "driver". A possible solution was found the the A2I's Serial component and the OpenSource Arduino.aix extension. But it was discovered that both entities were essentially the same sketch and relied upon the Physicaloid driver. Separate attempts to re-use these two entities were made. Both support only turning LED's on and off at the Android end. Neither readily supported moving a data package for processing.

Fortunately, an example was found that demonstrated that data packages could be transmitted over the OTG to the Android. The example employed the USBSerial driver. The example was re-used on the "proposed solution assembly of components" and satisfactorily demonstrated "gamepad UI" potential. However, the example and the "re-used" versions were built using the Android SDK Studio. The "example-USBSerial" approach was de-engineered and re-generated using the mit-cml/extension-template authored by ewpatton.

The resulting solution provides a level of satisfactory project maturity. At this level of maturity that permits the data capture of joystick movement, speed control, and command buttons and transmission that data the the target Android tablet. The technical details leading to the solution are given below in the Project Details section.




Project Details

  1. Discarded F310 artifacts that may be helpful in the future.
  2. ASCII table and Alt Codes
  3. Alternate ASCII table and links to Alt Codes
  4. Highly useful WiFly manual with link to basic low level command set.
  5. Converting Joystick movement to tank steering equation.
  6. Critical differnetial steering algorithm.
  7. OTG Pinouts See further discussion and information on DIY and purchasing.
  8. The gold standard for joystick caliration
  9. Joystick calibration project employing Arduion boards. The project's sketch requires adaptation to suit board and joystick.
  10. Helpful deeper thoughts regarding joysticks and usage with Arduino boards.
  11. App2Inventor Android -OTG - AdruinoFull Project thread under Arduino Projects
  12. My inputs to thread regarding F310 -otg to Android/Arduino.
    APK as shown running on an Android tablet was developed via MIT A2I which relies upon the Arduino.aix extension. The Extension depends upon the Physicaloid.jar USB communication driver/library. See the Serial component available from MIT A2I packaged as com.google.appinventor.components.runtime.Serial.java for the design boilerplate/template for using the Physicaloid driver.








  13. Arduino-OTG- Android example using the Android Studio IDE. Invoke f038)Arduino_Otg.apk with a Mega256 Arduino
    running f038_serial_test.ino. Android code available at github project for android side
    with links to felHR85's UsbSerial Library. The USBSerial driver is valid only for Arduino and
    a substantial number of other devices identified by their VID/PID.


  14. The Arduino USB Serial Extension kind-of-works. Recommend avoiding this approach. Use the email form at the bottom of this page for query on details.
  15. Almost useful android-otg-arduino. But uses the Android Studio SDK.
  16. FTC Gamepad and FTC OpMode. Recommend avoiding this approach. Use the email form at the bottom of this page for query on details.
  17. A2I Extensions: List of available extensions
  18. The original Mik3y/kai-morich Android SDK example further supporting the USBSerial driver approach.
    See the README.md for a list USB to serial converter chips supported bu the USBSerial driver.

  19. Nearing a Solution Switch to USBSerial Driver, Tooling, Eclipse/Ant Build Process of AIX
  20. Tool for building Extension for A2I
  21. Helpfull how to build extensions.
  22. Creating a2i Extensions
  23. But the Most Helpful Winner Is Still: Android SDK Ardurino-Android-USB Project authored by hariharan-m with useful driver code.
  24. Positive. It works allowing Arduino-OTG-USB-Host Android communication of active joystick/speed/button data.
    Positive. His code has an article which provides a good introduction to the thought process behind the application.
    Negative. The code is written is such a fashion/style that makes it difficult to read, maintain, or extend/reuse. But that is the nature of the Android SDK IDE.
    Negative. Requires usage of Android SDK IDE to change functionality or behavior.
    Negative. Integrating an appropriate solution with exisitng Abbottanp A2I-APK WIFI Remote Control will be difficult.
    Negative. The AIX-A2I extension annotations syntax will need to be reconciled with the USBSerial driver and this example.
  25. Implemented decision to abort Android-OTG-USB-F310 design path. Substituted orion, joystick,
    and speed control potentiometer plus buttons. Working gamepad prototype 200816.
    Using the "ewpatton" github.com repository/solutions
    (see link "Tool" above) from an Eclipse (3.8.1) to create
    suitable extension for App2Inventor.

    Android Studio IDE version using USBSerial

    Maturing Solution: A2I IDE employing extension using USBSerial.


    Next Evolution of Solution using the g038_OTG_serial Extension.
    Compass Mode playingfield. Gamepad Mode playingfield.


    Gamepad Hardware Assmbly:

    With the collection of basic hardware components already collected to develop and test the
    software the actual rendering of the assembly was almost moot. The Makeblock Orion version
    Arduino UNO board was employed. As was the MeRJ25 Adapter, MeJoystick, and MePoteniometer.
    A surplus push-button switch was used to replace the earlier high/low test clip switch
    mechanism. The Orion was connected to the Makeblock components using RJ25 cable/connectors.
    A low end plastic storage box provided the strucutre . Cable ties were used to firmly
    attach the components the top and bottom of the storage box's lid.
    Images which may prove helpful can be found in the gallery

    Gamepad Code Elements of Solution: (As Of 201005) Project repositiory contains:

    • s016_orion_otg sketch for Gamepad joystick, speed, and button employing the Orion Uno.
    • g038_otg_serial.java project source used to build the "key" extenstion from Eclipse.
    • Compiled copy of com.extensions.g038_otg_serial.aix extension ready for import to A2I.
    • Various archived *.aia files used for development of the project ready for import into MIT A2IIDE.
    • A2I build of Android application package, a038_973_ gamepad_otg_wifi.apk ready to load and install.

    Gamepad Software Development Tools
    Same tools as those used for the vehicle's software
    The Gamepad software development tools required the additional tools beyond those employed
    during the development of the software for the vehicle .
    Additional tools used in Gamepad development
    Extension Creation Tools
    1> Earlier in the presentation above are three extension creation topics that should be reviewed .
    2> For this project's extenssion, Eclipse 3.8.1 was employed as the JAVA development IDE with ANT. The
    Java IDE and build tool that is appropriate to the user's level of epxerience and
    skill should be employed.
    Spreadsheet analytical tool for vector analysis was used with atan2()to calculate the inverse trigonometric
    tangent of the specified x and y coordinates (Y: opposite over X: adjacent).
    NOTE: see Steering for helpful insight.





    Big Time Gotcha for WiFi Control
    1> See the Sparksfun WiFly tutorial Troubleshooting First bullet locate the "Setting Up a Simple Server"
    about three-quarters of the way down the webpage. This bullet states ..."data transmission of the wireless
    network is NOT instantaneous. It may take up to several seconds for your request to be sent to and
    processed by the Wifly shield depending on the size and configuration of your wireless network. If you are
    experiencing problems, there are many links in the chain to investigate."
    2> But recall the critical restriction of this project was to use components that were available already in the
    Abbott workshop inventory.
    3> As such this unwanted performance delay was forced to be acceptable.
    3.1> Road Testing demonstrated the awkwardness this delay caused in response and control.
    3.2> Both the Compass Mode and the Gamepad Mode exhibited related response issues.
    3.3> Radio Remote Control, IR Control, and Bluetooth may offer greatly increase response performance.



    Thinking Beyond This Project
    Moving beyond the scope limits of the project.



    Android Playingfield Evolution
    The design evolution is depicted in the gallery of helpful images.



    Future Enhancements
    A set of potential design enhancements is provided in the gallery of helpful images.



    Link to first Road Test 200927

    Link to first Road Test 201005




    Table 1. Helpful Commands:

    Command Comment
    dmesg provides detail information about components/devices managed by the kernel.
    lsusblist the various usb devices. Logitech, Inc. F310 Gamepad [XInput Mode]
    lsinput list all input devices
    lsmod generates a list of active modules. "0" indicates not used.
    lsmod | grep xpad looks specifically for xpad module
    ls -l /dev/input/js0 Response: crw-rw-rw-+ 1 root input 13, 0 Aug 7 15:38 /dev/input/js0 shows js0 is available to members of input group
    qjoypad --device /dev/input & starts an gamepad session
    cat /dev/input/js0 Displays Raw gamepad traffic for js0
    jstest-gtk Displays axis/buttons of gamepad devices for mapping and calibration
    sudo xboxdrv {--silent} starts driver if not already active. flip switch on bottom to X run xbox driver.
    sudo xboxdrv --detach-kernel-driver never used
    sudo service xboxdrv stop halts the xboxdrv service and removes events & js* from /dev/input.
    sudo service xboxdrv restart starts ubuntu-xboxdrv
    sudo cat /sys/kernel/
    debug/usb/devices
    Confirms xpad loading of gamepad
    sudo rmmod xpad shuts-down the xpad mode
    cat /proc/bus/input/devices list devices
    sudo service joystick restart default gameport module/service
    sudo modprobe xpad starts the xpad module
    lsmod | grep xpad list xpad and dependent modules
    cat /etc/group verify input group exists
    ls -l /dev/input obtain a list of input devices that are installed
    sudo xpad status verbose confirm xpad is active
    sudo usermod -a -G groupName userName add user to a group. Need to restart session
    cat /etc/group verify input group exists
    members inputcheck to see who is in group
    cat /dev/input/js0 |xxd -g 2 -c 8 Displays the characters reflecting F310 play/press
    python parser_main.py Displays the button & stick parse hex values.
    cd /media/tom/Silo_002/TechWork/DIY_projects/p006_squirrelChaser/011_gameport/001_grub/F310_Gamepad_Parser-master
    {Ctrl}z from cmd prompt stops python instance of parser_main.py
    http://ai2.appinventor.mit.edu/your_account_number URL: log-in to my workspace at MIT app2inventor
    adb logcat From Ubuntu cmd line for log
    GTK-Term Port Configuration:
    ==>>/dev/input/js0
    Displays USB as Byte Traffic Packages.
    GtkTerm at 9600 Parity None Bits 8. Hex
    set view: Hexadecimal and Hexadecimal Char 8
    adb logcat View the android's logcat file from Ubuntu with USB and adb
    {ctrl}z halts {ctrl} s stops scroll
    ./doa2i_local.sh
    ==>> URL: http://localhost:8888
    bash script in ~/ for executing ./java_dev)appserver.sh
    ./java_dev_appserver.sh Google Cloud SDK/bin/
    arguments: java_dev_appserver.sh --port=8888 --address=0.0.0.0
    /media/tom/Silo_002/TechWork/appinventor-sources/appinventor
    /appengine/build/war
    ant from /media/tom/Silo_002/TechWork/appinventor-sources/appinventor
    to build a new app2Inventor
    ant extensions To fire-up the a2i Extensions Tool from a terminal locate and navigate to
    the target folder: i.e
    cd /media/tom/Silo_002/TechWork/appinventor_tool4extesnionsl/g038_999_gamepad_otg_serial
    Then enter the ant command with its option as shown.
    sudo Nutty. Then set for wireless and devcies Network utility for viewing devices status and information. See Ubuntu version download site or use Ubuntu Software to install "nutty". No longer works due to system changes on my specific PC.
    sudo wireshark Download and run WireShark to monitor WiFi-UDP communication in near real time.
    Spare Spare








    Working Notes:

    1. OTG Details The android's OTG, On-The-Go cable is different than the USB-C. The OTG is a five USB micro to a 4 pin USB-A male/female. The USB-C is a connector with 24 pin double-sided connector. But both the OTG and USB-C support Dual-Role-Data (DRD) ports. A Dual-Role-Data (DRD) devices detects whether it is to have a host or client role.

      DIY merges USB-C with OTG DIY Video adding a resistor


    Please send comments or questions using e-mail, voice telephone at 919-846-7705. (Last update: January 4, 2021 tar)