Arduino

A short Android library to communicate with Arduino through usb.

License

License

GroupId

GroupId

me.aflak.libraries
ArtifactId

ArtifactId

arduino
Last Version

Last Version

1.4.4
Release Date

Release Date

Type

Type

aar
Description

Description

Arduino
A short Android library to communicate with Arduino through usb.
Project URL

Project URL

https://github.com/omaflak/Arduino
Source Code Management

Source Code Management

https://github.com/omaflak/Arduino

Download arduino

How to add to project

<!-- https://jarcasting.com/artifacts/me.aflak.libraries/arduino/ -->
<dependency>
    <groupId>me.aflak.libraries</groupId>
    <artifactId>arduino</artifactId>
    <version>1.4.4</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/me.aflak.libraries/arduino/
implementation 'me.aflak.libraries:arduino:1.4.4'
// https://jarcasting.com/artifacts/me.aflak.libraries/arduino/
implementation ("me.aflak.libraries:arduino:1.4.4")
'me.aflak.libraries:arduino:aar:1.4.4'
<dependency org="me.aflak.libraries" name="arduino" rev="1.4.4">
  <artifact name="arduino" type="aar" />
</dependency>
@Grapes(
@Grab(group='me.aflak.libraries', module='arduino', version='1.4.4')
)
libraryDependencies += "me.aflak.libraries" % "arduino" % "1.4.4"
[me.aflak.libraries/arduino "1.4.4"]

Dependencies

compile (1)

Group / Artifact Type Version
com.github.felHR85 » UsbSerial jar 6.1.0

runtime (1)

Group / Artifact Type Version
com.android.support » appcompat-v7 jar 28.0.0

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Arduino Download

A lightweight Android library to communicate with Arduino through USB.

Gradle

build.gradle Project

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

build.gradle Module

implementation 'me.aflak.libraries:arduino:1.4.5'

Usage

Arduino arduino = new Arduino(Context);

@Override
protected void onStart() {
    super.onStart();
    arduino.setArduinoListener(new ArduinoListener() {
        @Override
        public void onArduinoAttached(UsbDevice device) {
            arduino.open(device);
        }

        @Override
        public void onArduinoDetached() {
            // arduino detached from phone
        }

        @Override
        public void onArduinoMessage(byte[] bytes) {
            String message = new String(bytes);
            // new message received from arduino
        }

        @Override
        public void onArduinoOpened() {
            // you can start the communication
            String str = "Hello Arduino !";
            arduino.send(str.getBytes());
        }
        
        @Override
        public void onUsbPermissionDenied() {
            // Permission denied, display popup then
            arduino.reopen();
        }
    });
}
@Override
protected void onDestroy() {
    super.onDestroy();
    arduino.unsetArduinoListener();
    arduino.close();
}

Custom vendor id

The library currently filters the vendor id 9025, but you can add your own filter by calling :

Arduino arduino = new Arduino(Context);
arduino.addVendorId(1234);

Custom delimiter while reading

You can set a custom delimiter byte (default is \n) :

Arduino arduino = new Arduino(Context);
arduino.setDelimiter(';');

Arduino Side

Example code which sends back every character received

void setup() {
    Serial.begin(9600);
}

void loop() {
    if(Serial.available()){
        char c = Serial.read();
        Serial.print(c);
    }
}

Sample Code

See MainActivity.java

Special thanks

This code is using UsbSerial library : https://github.com/felHR85/UsbSerial

License

MIT License

Copyright (c) 2017 Michel Omar Aflak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Versions

Version
1.4.4
1.0