All Projects → felHR85 → Usbserial

felHR85 / Usbserial

Licence: mit
Usb serial controller for Android

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Usbserial

Node Serialport
Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them!
Stars: ✭ 5,015 (+285.47%)
Mutual labels:  hardware, serial, serialport, iot
Node Escpos
🖨️ ESC/POS Printer driver for node
Stars: ✭ 752 (-42.2%)
Mutual labels:  hardware, usb, serialport
Johnny Five
JavaScript Robotics and IoT programming framework, developed at Bocoup.
Stars: ✭ 12,498 (+860.65%)
Mutual labels:  serial, spi, iot
Swiftygpio
A Swift library for hardware projects on Linux/ARM boards with support for GPIOs/SPI/I2C/PWM/UART/1Wire.
Stars: ✭ 1,188 (-8.69%)
Mutual labels:  spi, serialport, iot
Iotsecurity101
A Curated list of IoT Security Resources
Stars: ✭ 1,302 (+0.08%)
Mutual labels:  hardware, iot, iot-device
Lib Python
Blynk IoT library for Python and Micropython
Stars: ✭ 140 (-89.24%)
Mutual labels:  hardware, iot, iot-device
Blynk Library
Blynk library for embedded hardware. Works with Arduino, ESP8266, Raspberry Pi, Intel Edison/Galileo, LinkIt ONE, Particle Core/Photon, Energia, ARM mbed, etc.
Stars: ✭ 3,305 (+154.04%)
Mutual labels:  hardware, serialport, iot
Wrmhl
⚡️ Super fast communication beetwen Unity3D and Arduino. Create Interactive experiences in a minute ⏱
Stars: ✭ 601 (-53.8%)
Mutual labels:  hardware, iot
Attifyos
Attify OS - Distro for pentesting IoT devices
Stars: ✭ 615 (-52.73%)
Mutual labels:  hardware, iot
Platformio Vscode Ide
PlatformIO IDE for VSCode: The next generation integrated development environment for IoT
Stars: ✭ 676 (-48.04%)
Mutual labels:  hardware, iot
Cbj smart Home
If you are searching for an easy way to deploy a smart home 🏡 by yourself CyBear Jinni 🦾🐻🧞‍♂️ is here for you. Join the community and make your home smarter than yesterday.
Stars: ✭ 37 (-97.16%)
Mutual labels:  iot, iot-device
Androbd
Android OBD diagnostics with any ELM327 adapter
Stars: ✭ 573 (-55.96%)
Mutual labels:  usb, serial
Sensors Software
sourcecode for reading sensor data
Stars: ✭ 469 (-63.95%)
Mutual labels:  iot, iot-device
Send altitude cocoos
IoT program for Arduino Uno / STM32 Blue Pill (libopencm3) that reads BME280 temperature + humidity + altitude sensors, via I2C or SPI with DMA and multitasking. Sends sensor data to Sigfox via Wisol Sigfox module on UART. Runs on cocoOS task scheduling library http://www.cocoos.net
Stars: ✭ 24 (-98.16%)
Mutual labels:  spi, iot
Pulsesensorstarterproject
The Best Way to Get Started with your PulseSensor and Arduino
Stars: ✭ 38 (-97.08%)
Mutual labels:  hardware, serial
Platformio Atom Ide
PlatformIO IDE for Atom: The next generation integrated development environment for IoT
Stars: ✭ 475 (-63.49%)
Mutual labels:  hardware, iot
Lsusb
Most popular USB devices and lsusb reports
Stars: ✭ 19 (-98.54%)
Mutual labels:  hardware, usb
Ehal
Embedded Hardware Abstraction Library
Stars: ✭ 84 (-93.54%)
Mutual labels:  usb, iot
Rfsec Toolkit
RFSec-ToolKit is a collection of Radio Frequency Communication Protocol Hacktools.无线通信协议相关的工具集,可借助SDR硬件+相关工具对无线通信进行研究。Collect with ♥ by HackSmith
Stars: ✭ 1,085 (-16.6%)
Mutual labels:  hardware, iot
Blinker Library
An IoT Solution,Blinker library for embedded hardware. Works with Arduino, ESP8266, ESP32.
Stars: ✭ 1,095 (-15.83%)
Mutual labels:  hardware, iot

UsbSerial Build Status AndroidArsenal Join the chat at https://gitter.im/UsbSerial/Lobby

UsbSerial wiki available. Read it first

Getting started
Create UsbSerialDevice objects
Asynchronous api
Synchronous api
InputStream and OutputStream I/O
Multiple Serial ports
Projects using UsbSerial
Debugging over Wifi
UsbSerial video tutorials

I am looking for collaborators to keep this project updated

Support UsbSerial

If UsbSerial helped you with your projects please consider donating a little sum
Or consider buying DroidTerm Pro: A Usb serial port terminal using UsbSerial

Devices Supported

CP210X devices Default: 9600,8,1,None,flow off

CDC devices Default 115200,8,1,None,flow off

FTDI devices Default: 9600,8,1,None,flow off

PL2303 devices Default 9600,8,1,None,flow off

CH34x devices Default 9600,8,1,None,flow off

CP2130 SPI-USB

Known Issue

Due to a bug in Android itself, it's highly recommended to not use it with a device running Android 5.1.1 Lollipop. See issue #142 for more details.

How to use it?

Instantiate a new object of the UsbSerialDevice class

UsbDevice device;
UsbDeviceConnection usbConnection;
...
UsbSerialDevice serial = UsbSerialDevice.createUsbSerialDevice(device, usbConnection); 

Open the device and set it up as desired

serial.open();
serial.setBaudRate(115200);
serial.setDataBits(UsbSerialInterface.DATA_BITS_8);
serial.setParity(UsbSerialInterface.PARITY_ODD);
serial.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF); 

If flow control is needed (currently only supported in CP201x and FTDI devices)

/**
Values:
    UsbSerialInterface.FLOW_CONTROL_OFF
    UsbSerialInterface.FLOW_CONTROL_RTS_CTS 
    UsbSerialInterface.FLOW_CONTROL_DSR_DTR
**/
serial.setFlowControl(UsbSerialInterface.FLOW_CONTROL_RTS_CTS);

There is no need to be polling if you want to perform a bulk transaction to a IN endpoint. Define a simply callback

private UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() {

		@Override
		public void onReceivedData(byte[] arg0) 
		{
			// Code here :)
		}
		
};

And pass a reference of it

serial.read(mCallback);

Changes in the CTS and DSR lines will be received in the same manner. Define a callback and pass a reference of it.

private UsbSerialInterface.UsbCTSCallback ctsCallback = new UsbSerialInterface.UsbCTSCallback() {
        @Override
        public void onCTSChanged(boolean state) {
           // Code here :)
        }
    };
    
private UsbSerialInterface.UsbDSRCallback dsrCallback = new UsbSerialInterface.UsbDSRCallback() {
        @Override
        public void onDSRChanged(boolean state) {
           // Code here :)
        }
    };
    
serial.getCTS(ctsCallback);
//serial.getDSR(dsrCallback);

Write something

serial.write("DATA".getBytes()); // Async-like operation now! :)

Raise the state of the RTS or DTR lines

serial.setRTS(true); // Raised
serial.setRTS(false); // Not Raised
serial.setDTR(true); // Raised
serial.setDTR(false); // Not Raised

Close the device:

serial.close();

I recommend using UsbSerial as shown above but if you want to perform write and read operations in synchronous way it is possible using these methods:

public boolean syncOpen();
public int syncWrite(byte[] buffer, int timeout)
public int syncRead(byte[] buffer, int timeout)
public void syncClose();

In Android usb api, when a usb device has been close it must be reopened

UsbDevice device;
...
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
manager.openDevice(UsbDevice device)

How to use the SPI interface (BETA)

Support for USB to SPI devices was added recently but it is still in beta. Although I tried to keep the api as close to standard UsbSerial api as possible, be aware because the beta nature of this feature this api may change in the future. Only CP2130 chipset is supported at the moment.

UsbSpiDevice spi = UsbSpiDevice.createUsbSerialDevice(device, connection);
spi.connectSPI();
spi.selectSlave(0);
spi.setClock(CP2130SpiDevice.CLOCK_3MHz);

Define the usual callback

private UsbSpiInterface.UsbMISOCallback misoCallback = new UsbSpiInterface.UsbMISOCallback()
    {
        @Override
        public int onReceivedData(byte[] data) {
             // Your code here :)
        }
    };
//...
spi.setMISOCallback(misoCallback);
spi.writeMOSI("Hola!".getBytes()); // Write "Hola!" to the selected slave through MOSI (MASTER OUTPUT SLAVE INPUT)
spi.readMISO(5); // Read 5 bytes from the MISO (MASTER INPUT SLAVE OUTPUT) line. Data will be received through UsbMISOCallback
spi.writeRead("Hola!".getBytes(), 15); // Write "Hola!" and read 15 bytes synchronously

Close the device when done

spi.closeSPI();

Gradle

Add the jitpack repo to your your project's build.gradle at the end of repositories

/build.gradle

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

Then add the dependency to your module's build.gradle:

/app/build.gradle

implementation 'com.github.felHR85:UsbSerial:6.1.0'

TO-DO

  • RTS/CTS and DSR/DTR implementations for PL2303 and CDC
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].