[Free] Arduino USB Serial Extension

usb
serial
otg
arduino

#225

Hello,

I have already managed to get my app to read the arduino series when I press a button, but I would need to do this in a loop continuously, so that pressing an arduino button will change something on the mobile screen …

That is to say, I need to make a loop that is continuously reading the arduino, but I do not know how to do it.

Can you help me? Thanks


#226

You can use while test "true" loop as continuous loop.


#227

All,

thank you for sharing your ideas here. I am still in trouble receiving data from my arduino, the “AfterRead” block is simply not entered :frowning: Here is my code, any ideas about that?

This is the arduino part of it:

//variable for Serial input
int input = 0;

//Pins for LED
const int LED = 13;

// the setup function runs once when you press reset or power the board
void setup() {

//Start the serial monitor at 9600 baud  
Serial.begin(9600);

//Declare the LEDs to be outputs  
pinMode(LED, OUTPUT);

}

// the loop function runs over and over again until power down or reset
void loop() {

//check if there's incoming data,  
if (Serial.available() > 0) {
	//if so, then read the incoming data.    
	input = Serial.read();

	//make different colours depending on the input value    
	if (input == '1') {
		digitalWrite(LED, HIGH);
		Serial.write(100);
		Serial.flush();
	}
	else if (input == '2') {
		digitalWrite(LED, LOW);
		Serial.write(101);
		Serial.flush();
	}
}

}

“send” works, the LED switches its state. But I never see the “after read” notice…


#228

So I have a theory as to why its not working.
Using the serial send command, you send the state you want the LED to be in via the Button1.click or Button2.click functions.
But here’s the thing, I think you need to make the arduino.afterread command a function block of its own that you can call as part of each button.click.
The Arduino code tells it to serial.write(“Some status”) then, immediately clears that message with the serial.flush, that is happening faster than the App clock timer triggers the arduino.afterread… which means it reads a blank value, aka no data, so the arduino.afterread code is not working because its told it needs to have data to display or it fails(does nothing)


#229

Hi James,

thank you for stepping in here!
In fact what you see above is one of several tries that did not work before. I started with a “read” call after each “write” in the “button.click” functions. I added the "flush"es on arduino side as it did not work without them either…

I do not understand the timing aspects of the Arduino “Serial.write()” and the “Read()”/“After Read” part of the Android app. I asked Pavi about that here yesterday: https://community.kodular.io/t/arduino-connection-using-usb-otg/12475

“What I dont understand is the timing between “arduino sends” and “android calls read()”… Logically, is there some kind of buffer on the android side? Will it return something if called after the data was sent? Or is “read()” blocking and waiting until it receives something? Or is it necessary to call “read()” in an endless loop or controlled by a timer event to catch whatever was sent?”

Can you clarify that part of the story?

Thanks and best regards
Keith


#230

Hi Keith, glad to help!

when you used the .read code you mentioned, did you send it any data first?

The Arduino code checks to see if serial is available by seeing if the incoming data is something greater than 0. Could it be that the .read failed because the Arduino code ignored it since it didn’t get past the serial.available logic test?
I can post my Arduino code I used when I get home tonight. But I know that i did NOT need the serial.flush on my to get it to work. I started with a basic serial echo code to test proof of concept before getting deeper into it.


#231

Hi James,

ok, I will remove the flush() calls… What I want to achieve: I want to receive some log data from the arduino. The transmission should be started by a trigger being sent from the android app. Therefore I check for incoming data and whenever that is the triggering command it should start to send the log data. That is what I try to achieve with the lines I added to the simple “LED” example.

Meanwhile I had a look at Pavi’s code:

As far as I understand, EVERY “read()” call should fire the AfterRead event and should therefore show my “after read” alert. Regardless if data that was received or not. Makes it even harder for me to understand what happens here… Maybe the “get(data)” hard fails when “success” was false and thus the alert is not issued? Any log (file) access would be helpful for such debugging purposes…


#232

Also, try swapping out the serial.write for serial.print instead in the Arduino code?


#233

Started with print() and already swapped that for write() as one of my tests :wink:


#234

Next simple try:


In my understanding this app should present an “After Read…” alert after every click of the “Read” button. But it does not do so on my S8.

Any idea anybody…?

Here is the .aia in case anybody wants to check on another device:
arduino_read_test.aia (2.1 KB)


#235

nobody?


#236

Hi ksau,

Did you ever figure this out? I am trying to achieve the same thing, i.e. push a button on the app to send a short request to the arduino, and then have the arduino send back some data it has previously collected. Your simple LED example would be a good testing ground if you have gotten it working. Thanks!


#237

The extension just doesn’t seem to work for me. The problem appears to be that my phone is never asking for permission to allow my test app to access the USB device. (I am using domhnall’s LED test app).

When I use the Universal Serial Terminal app (free in Google Play Store), it does ask me for permission, and when I click OK, that app works perfectly, i.e. I can send commands to the arduino from within the Universal Serial Terminal app on my Android.

Based on this, it does not appear to be a problem with my phone or phone setup.

I also tried downloading and installing the apk version of the test app, thinking that perhaps the emulator version might be causing some problem. But, unfortunately, even the apk version has the same problem, i.e. the app never asks for permission to connect to the USB device. From that point on, the test app does nothing of course. Any button clicks, or attempts to initialize/open Arduino1, do nothing.

I’m soooo frustrated after working on this for days now! Can anyone give me any hints/suggestions? Thanks!


#238

Ummm


#239

Meu chip Ftdi não reconhece, Sony Xperia z1.
Espero que melhorem a extensão.


#240

Hi Zimbu,

No news from my side unfortunately. I simply gave up and solved the problem completely different way. Still interested in a solution though…

Best,
Keith


#241

Thanks for getting back to me.

Because of the character of the app that I am building, I was hoping to use a wired connection because it seems more “old school”. But, alas, I couldn’t figure it out.

I finally gave up and went with Bluetooth Low Energy 4.0 instead. I think a lot more people are working with BLE, plus I am much more familiar with it, so I got it up and running easily.


#242

hi @kasu did you find the way i am also searching for this but my problem is the app i make cant see arduino ie it dosent ask me to allow this app to use the usb


#243

did you figured it out
i have a problem that my app is not asking that allow permision for using usb any help


#244

@ksua I think your problem maybe caused by " … A 32u4 based arduino has a low DTR, it refuses to output serial data, even though it is receiving data." (please see this issue from forum.arduino.cc : https://forum.arduino.cc/index.php?topic=266308.0 )

Maybe this extension NOT set DTR to High ?

More Detail from above issue’s reply:

"I’ll explain differently, then go read sheet.

FTDI based (and similar) “USB Serial Ports” are happy to send data to PC applications regardless of whether the PC software they are talking to sets DTR (data terminal ready) to HIGH, indicating it is actually ready for data. Serial.print() from arduino works great regardless of DTR settings…and the PC software in question sets DTR to low (and can actually use a normal serial DTR wire for a non-standard purpose.)

Unlike FTDI based USB Serial devices, 32u4 based “USB Serial Ports” refuse to send data to the PC, unless DTR is set to high, which only the PC based software side can set. If the PC software does not set DTR to true (high?), then Serial.print() on Arduino goes into a black hole, and the software never gets the responses from the Arduino.

End result…the software can send commands to my board, but because the PC software does not set DTR, my Serial.print() responses are not received…the 32u4 essentially blocks the responses because DTR is low…even though serial is data is going TO the arduino."