maple serial on Android?

WindyYam
Fri Jan 26, 2018 2:48 am
I have some Blue pill projs run fine on pc , and now i have to do some interactivity with unity3d on android through serial interface. so question is, does maple serial directly acceptable on android(with otg) ? or does it need drivers like pc to be installed?

mrburnette
Fri Jan 26, 2018 4:23 am
The bootloader appears to the host PC as a DFU device.

After a sketch is running, serial is enumerated as discussed here:
http://docs.leaflabs.com/static.leaflab … oader.html
Newest bootloader includes a small “sketch” that loads into the program area so that the bootloader has a program into which the timeout will invoke & the PC will enumerate to a serial port … assuming the drivers have been properly configured.

There is a HID library available, but no OTG on Maple Mini or blue pills (to my knowledge.)

Reference: http://www.emcu.it/STM32/STM32_USB_Devi … t_OTG.html

Ray


WindyYam
Fri Jan 26, 2018 4:44 am
thanks for the reply, what i want to do is access the maple serial usb from Android(unity3d). the blue pill send quaternion data out to usb serial. it’s ok on pc processing 3d visualize, but i have to run that on unity with android. after some google i dont find useful information (for unity mono)

ag123
Fri Jan 26, 2018 8:46 am
i’m not familar with unity3d hence won’t be able to comment about it.
but in general to make android talk usb-serial, you probably need something like this:
https://github.com/felHR85/UsbSerial

i’d think it should work e.g. the above UsbSerial for android and maple/BP, but havn’t tried it myself
another thing would be that OTG from a phone is possibly low/under powered and you may need to feed power directly to the maple/BP in addition


mrburnette
Fri Jan 26, 2018 1:48 pm
[WindyYam – Fri Jan 26, 2018 4:44 am] –
thanks for the reply, what i want to do is access the maple serial usb from Android(unity3d). the blue pill send quaternion data out to usb serial. it’s ok on pc processing 3d visualize, but i have to run that on unity with android. after some google i dont find useful information (for unity mono)

So, where does OTG come into play? As stated, I do not believe you will get a blue pill to OTG.
Connecting an Android tablet or smartphone over serial is another matter… http://stm32duino.com/viewtopic.php?f=45&t=767


csnol
Fri Jan 26, 2018 6:14 pm
Suggestions:
1. Need a USB-TTL adapter for Android OTG >> USB-TTL >> BluePill (PA9 PA10 or other pins) serial communication,
2. change to STM32F107 or others STM32 MCU which native support USB port.
3. unity3d support HTML5 and WEB, you can use WiFi2Serial modules (ESP8266 or ESP32) to control STM32 or replace it directly.
4. Any Tiny LinuxARM boards (Raspberry Zero) >> Android OTG, the Serial and USB is easy to controlled on Linux.

BTW, Just wonder for it , Why use the Serial Interface for Android project and don’t use USB and WiFi even BLE? . so many MCUs native support.


RogerClark
Fri Jan 26, 2018 9:03 pm
I have not looked at USB Serial on Android for some time, but on AVR boards I recall needing to use a separate library on Android to use USB Serial with the VID/PID even of the official Arduino AVR boards.

The LibMaple Core, implements the standard USB CDCACM Serial device, but the phone will not recognise the VID/PID identification numbers for Leaflabs, as I don’t know any OS which recognises the Maple without being told what driver to use.

If it’s a personal project, you could change the VID/PID numbers in the core, to match another device which Android knows is a USB CDCACM device ( but I don’t know what those values would be)


WindyYam
Sat Jan 27, 2018 1:18 am
[csnol – Fri Jan 26, 2018 6:14 pm] –
Why use the Serial Interface for Android project and don’t use USB and WiFi even BLE? . so many MCUs native support.

because that’s simple enough… I tried WiFi version with 8266, but that would be at the cost of the WiFi connection, and you always have to match the socket ip address/match the hotspot ssid, i don’t know how to. BLE is okay, but I want my application to be able run on both PC and Android , many PC dont have BT. so that’s why I use unity


WindyYam
Sat Jan 27, 2018 1:50 am
OK forget about Android unity for a moment …

I encountered a new problem, on PC unity.

the unity use .net api script so It’s okay to call serial port. But, I found something different between Maple serial and Arduino UNO usb serial(ATMEGA16U2)

with Arduino UNO the serial packet is serial.ReadByte() , it blocks until data come, then run to the next line
with Maple serial the serial packet will block in serial.ReadByte() Forever, nothing comes

the samething happens on Matlab and Processing so I assume it’s something more fundamental in driver or something. I recall my programming on Processing I have to call read in serialEvent in order not to block. i tried event handler in unity but nothing changes


ag123
Sat Jan 27, 2018 5:28 am
i tend to use Serial.available() to check if there is data in the queue so that to an extent i did some kind of ‘non-blocking’ reads
viewtopic.php?f=18&t=2752
if(Serial.available()) {
while(Serial.available()) {
char c = Serial.read();
...........
}
}

WindyYam
Sat Jan 27, 2018 7:17 am
[ag123 – Sat Jan 27, 2018 5:28 am] –
i tend to use Serial.available() to check if there is data in the queue so that to an extent i did some kind of ‘non-blocking’ reads

Thanks but what I’m blocking is in PC side. The serial.BytesToRead I got in C# call is always 0. but when it comes to a Arduino uno or CP2102 adapter everything runs fine


Pito
Sat Jan 27, 2018 8:32 am
For Android you want to install a driver for Maple Serial USB (Uno uses the FTDI, and the CP21xx as well have got drivers for all OSes)..
You may try, for example, the BlueTooth HC-05 module. Will work sure. And wireless :)

ag123
Sat Jan 27, 2018 9:53 am
[WindyYam – Sat Jan 27, 2018 7:17 am] –
Thanks but what I’m blocking is in PC side. The serial.BytesToRead I got in C# call is always 0. but when it comes to a Arduino uno or CP2102 adapter everything runs fine

if you are waiting for data on the PC side, you would need to send some data from maple (mini) or bluepill
i.e. use Serial.write(c); to send that data over. test out your skech in the serial terminal in arduino IDE for instance

the link i’ve given earlier is a usb-serial dongle sketch done with the maple mini
viewtopic.php?f=18&t=2752
you could use similar codes to test some kind of request / response using serial.read() or serial.write(c)

if you are having problems on the PC side it sounds likely you have a serial.read() call which blocks (on maple mini) and it stalls there. you could try out the serial.available() hack/workaround i used to do ‘non-blocking’ reads i posted earlier


RogerClark
Sat Jan 27, 2018 11:13 am
It expects DTR to be set

If you can’t set this, use the Zumspot branch of my repo, as that version was for a device which had the same problem

Note, the Zumspot branch does not get updated that often, but I updated it 2 weeks ago, so it’s fairly up to date at the moment.


WindyYam
Sat Jan 27, 2018 1:16 pm
[RogerClark – Sat Jan 27, 2018 11:13 am] –
It expects DTR to be set

many thanks, by setting DtrEnable = true the code start to work as normal Arduino Uno does :)

I will deal with the Android version later


RogerClark
Sat Jan 27, 2018 9:18 pm
As the AVR Arduinos and the Due etc, don’t require DTR to be set, the Core really needs to be updated to make it operate the same as the rest of the Arduino world.

However, when I looked it changing this, it had an impact on the blocking functionality of the USB Serial.

We had a poll about whether USB Serial should be blocking but I can remember the results .

But we definitely can’t have a situation where the code hangs, if USB Serial is not connected, as some libraries have print statements in them, and most projects do not end up with the board being deployed connected to a USB host


mrburnette
Sat Jan 27, 2018 9:36 pm
[RogerClark – Sat Jan 27, 2018 9:18 pm] –
… as some libraries have print statements in them …

IMHO, no library should have print statements! Example of where such a thing makes sense?

Ray


RogerClark
Sat Jan 27, 2018 9:52 pm
I agree

Libraries should not have print statements in them, but in the past I think I came across one or two libraries which still had print statements in them, left over from when they were debugging the lib.


mrburnette
Sun Jan 28, 2018 1:35 am
[RogerClark – Sat Jan 27, 2018 9:52 pm] –
I agree

Libraries should not have print statements in them, but in the past I think I came across one or two libraries which still had print statements in them, left over from when they were debugging the lib.

Ah, ha!
These lines are ideal candidates for the “// ” prefix. Even the lowly ArduinoIDE editor can manage this task.


ag123
Sun Jan 28, 2018 3:50 am
[mrburnette – Sat Jan 27, 2018 9:36 pm] –
IMHO, no library should have print statements! Example of where such a thing makes sense?

Ray

unfortunately sd fat actually tries to scream on the serial console at initialization if it can’t connect to the sd card, yup it is useful as quite a number of times i forget to insert the sd card :lol:

// Initialize at the highest speed supported by the board that is
// not over 50 MHz. Try a lower speed if SPI errors occur.
if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
sd.initErrorHalt();
}


BennehBoy
Sun Jan 28, 2018 12:55 pm
[ag123 – Sun Jan 28, 2018 3:50 am] –
unfortunately sd fat actually tries to scream on the serial console at initialization if it can’t connect to the sd card, yup it is useful as quite a number of times i forget to insert the sd card :lol:

// Initialize at the highest speed supported by the board that is
// not over 50 MHz. Try a lower speed if SPI errors occur.
if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
sd.initErrorHalt();
}


RogerClark
Sun Jan 28, 2018 8:37 pm
[ag123 – Sun Jan 28, 2018 3:50 am] –

unfortunately sd fat actually tries to scream on the serial console at initialization if it can’t connect to the sd card, yup it is useful as quite a number of times i forget to insert the sd card :lol:

I think that library is not alone, but perhaps someone should ask the author to make some changes,


Leave a Reply

Your email address will not be published. Required fields are marked *