Arduino Button check in a MIT APP

Limit Switches are used for CNC machines and so you can just Google Search for how to do that, you will find plenty of information.

Connect a second Serial for the App to receive signals from the Limit Switches via the HC-05.

Just because i wrote the limit switch, because, this is on the agricultural maschine ( see the Picture)

. To me is important, only if the button/switch close the circuit, i see it.
Did you mean this Serial? If yea, unfortinatly i do not know it.
I write the ARduino code, like if i try the Data write on the Serial Monitor in the Arduino IDE?

Sorry if i am very slow brain man.

Currently, you are sending commands to the Arduino via Bluetooth and the Arduino is waiting for those incoming commands (values) via a hardware Serial Channel. It needs a second Serial Channel connected to send the Limit Switch signals to the App. Your Arduino Mega has four Serial Channels available.

So, as I said in my previous post, search Google for examples of CNC machines using Arduino as they will show you how to wire-up Limit Switches.

Here Arduino UNO, HC-06 BT, two potentiometers.

A Timer in App Inventor continually queries for its values.

https://community.appinventor.mit.edu/t/bluetooth-hc-06-arduino-send-receive-send-text-file-multitouch-image/9518/8

Here two Push Button

https://community.appinventor.mit.edu/t/bluetooth-hc-06-arduino-send-receive-send-text-file-multitouch-image/9518/7

Maybe you can get some ideas.

thanks for the help, because now the Arduino can a indication back to me in to the App.
For a another test, i want to got indicate from the Arduino, but, via OTG. I want to make a Joystick. The arduino code is "done", and i trty to tesst, in the serial monitor, than there is everything good. I have tried the data recevied in the App, ( The Serial blocks looked, like Bluetooth variant) but not worked. Someone can help to me , how can i the Blocks made? Or can give me a examlpe.

Arduino code:

const int buttonPin7 = 7;
const int buttonPin8 = 8; // the number of the pushbutton pin
int buttonState7;
int lastButtonState7;
int buttonState8;
int lastButtonState8;
String Bt;

void setup()
{

pinMode(buttonPin7, INPUT);
pinMode(buttonPin8, INPUT);// initialize the pushbutton pin as an input
Serial.begin(9600);
}

void loop()

{
{delay(5);

int reading = digitalRead(buttonPin7);
if (reading != lastButtonState7)
{
if (reading == 1)
{ Bt = "FEL1";
Serial.print(Bt);
}
if (reading == 0)
{ Bt = "FEL2";
Serial.print(Bt);
}

}
lastButtonState7 = reading;
}
int reading = digitalRead(buttonPin8);
if (reading != lastButtonState8)
{
if (reading == 1)
{ Bt = "LE1";
Serial.print(Bt);
}
if (reading == 0)
{ Bt = "LE2";
Serial.print(Bt);
}

}
lastButtonState8 = reading;
}

OTG, try this extension:

Hello,

I tried the OTG extension, but i dont know why, i did not can chose the SerialPrint Block, and on the Desinger site, i cant set the Buffer size. What is the wrong.
But when i downloaded, your aia file, and tested, than there everithing is okaywith the OTG extension, only, if i import the extension than wrong.
My import.


Your app if i import to MIT

And the desinger site in my app

Try with
Write
and
WriteLn

Hello,
Can you help me, because when i problay mde a app, than i cant conected the Serial, for the Phone or tablet. I have a Samsung Galaxy S51 and a Tab S6 Lite. All of this two devices has OTG, i tested. But when i tried conected the Serial than i become this Error message all of twoo Devises.

That seems to be a bug in the extension that is not adapted to Android 12.

Maybe the author of the extension will decide to fix it.

Search this community about the FLAG_IMMUTABLE FLAG_MUTABLE error

When before you send me your Comment, then i looked in other Topics, and there i saw, this is a relative great problem. But thanks the answer.

Hello,
i tried the Data send from arduino via Otg. i do not find all of the blocks, like in yours App-s.
My app worked right, via Bluetooth, but i have to use on Otg. The Arduino code stayed the same like the bluetooth version. Can you help me, that what is wrong?

From what I can see, you are expecting an answer immediately after you send the request.
Please take a look at my documentation SerialOTG_1.4.pdf and examples:

“Remember that serial line communication is just a stream of bytes. There is no packet handling.
Each byte takes some time to transfer on the line. So if you send a request, then you have to wait for
a while, before you get an answer.
You have to add some kind of message handling yourself by timing, message length, content etc.

WriteLn(), ReadLn() implements a kind of message handling. It uses new line character to end an
UTF-8 message. Use ASCII char set (7-bit) to avoid problems if you communicate with Arduino.”

Have you tested the new version adapted to Android12, see Using serial with FTDI - #102 by Jambo ?

1 Like

Yeah , i tested with Android 12 ( Galaxy Tab S6 Lite) and i can data send to the Arduino. ( Led, on-off) , The device/app do not freez by me and it dont give Warning message to me.

Thanks, then I know.
I think the easiest way to communicate if you are not familiar with serial communication is by using writeln, readln, You can look at my examples ArduinoTime.aia, Time.ino to see how it works.

813f35e56d7b004ad477539ecbe565857c532fe0_2_397x500

Your csv to list conversion is backwards unnecessary. Does ReadBytes return a list of Bytes?

Also, it is wise to check length of list before attempting to select list items.

1 Like

I did not write in my before answer. When am i tested your new Extension for the OTG, than i used only the nb190 bugfixed MIT App Inventor.
http://nb190a-bugfixes.ai2-ewpatton-temp.appspot.com
I hope, that i linked right the URL.

Hi,

I didn't give up on this thing. I made a version, found a good sub-base for the app. For some reason it randomly throws this message, but when I touch the tablet, it disappears and then appears again.

Arduino Code:

int value_pot0;
int value_pot1;
String value;

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

void loop() {
value_pot0 = analogRead(A0);
value_pot1 = analogRead(A1);
value = (String) value_pot0 + "," + (String) value_pot1;
Serial.println(value);
delay(200); // It should be slower than the Clock Interval.
}


Cannot see a csv Block in your code?

Sorry i don't understand, so the App do not see the csv Block, or what?