Problem with app sending a text command

Hi
I have a trouble with an app that i created everything works fine but the problem is as follows:

  1.    I send a "1" from serial monitor to bluetooth arduino starts a task and stops after sometime which is good i want it to happen. like blinking LED.
    
  2.    I send a "1"  using Blutooth Terminal App from playstore , the arduino starts the task and stops after the required duration which is good.
    
  3.    I send a "1" using my app Created with   App Inventor on button click arduino starts the task but the task does not stop after is made to stop i.e., arduino code fails and it seems that "1" is being transmitted continuously. please address this issue , i am in trouble..

Hi Younus

Can you post your App Inventor Blocks here? Right-mouse click in the Blocks work area and select "save blocks as image".

Before you do though, here is a guess - is the send performed in a Clock Timer Block? If so, the Clock Timer Block must switch itself off after the send. Also, in Designer, Clock Properties, Untick the options and control them in Blocks.

Snap1

Snap2

The Clock Timer should be enabled (true) just before it is called by whatever Block is calling it.

I unchecked my both clocks even the clock that is used to connect to bluetooth
the first task you gave is also good but i am unable to fing the option " save the blocks as image" how to do this.

i will get back to you after testing the app again

Why there is an interval of thousand between firing and enabling.

There isn't? In the Initialize Block, those are just important settings. For your App, Timer Always Fires should never be on (never true), that's a facility for games and such like.

The timer interval is the how often the timer will run - 1000 milliseconds = 1 second - when enabled, the timer will run once every 1 second (or whatever interval value you define) until timer enabled = false. This has to be set approx 20% faster than the time interval of the Arduino main loop, and both should be set at as large an interval as is practical for the purpose of the setup - this eliminates errors and prolongs the life of the hardware.

If you uncheck your clocks, nothing will work!

Sorry, proper term is "Download Blocks as Image" (Right-Click pop-up menu)

Snap3

But you have shown above in image to check those.

And one thing I want to make clear is that I run two LEDs I.e., blink them with a command from my phone and after some duration arduino stops it which is good for me. One important thing is in my app the button also enables after arduino stops the code but virtually no connection between arduino and my app for this action. Arduino and app has their separate timers with no link between. I will send you image of blocks but this time I am busy see you later.

here are my blocks see

my all main buttons 12 - 19 send a "1" and Clock2Timer responds to each buttons as they call it and Clock1Timer is for Bluetooth connect. I do not know when a button sends a one the arduino code does not stop at the target interval.

Well, I can't make head nor tail of what your App is supposed to do - the Blocks certainly do not fit with your original description :upside_down_face:

So, I think we need a description of what the App should do - perhaps a screenshot of the GUI would help. Where you enable and disable buttons, that is taking up a lot of real estate, "Any Component" loops and Procedures could reduce the Blocks a bit :thinking:

I assume you are using Clock1 to constantly check that there is a BT connection. Is that because the device (phone) is moving?

The discription is as follows:
I need Eight Buttons that transmit a "1" to start a code for certain time and Aduino stops it. But each Button uses a CLock2Timer to display the time for which arduino code works and then decrements it to
0 and at last the clock enables the button again.

  • I have a reset button that can Reset Timer and Buttons And arduino code on Sending a "9".
    I have Button 10 for OFF and Button 11 for ON

I may have my phone Moving but most of times it has to be at rest and in range.

More simple Description is as this:

  •  I need a Button that sends a "1" or whatever to start a code in arduino Say for one minute and only arduino stops it . In the means time this Button enables a count DownTimer for one minute.
    
  •  The time (minutes left with seconds counting down) is displayed on phone screen using labels .
    

That is all I need.

I am new to App inventor and I do not Know how and for what Anycompnents are used and when they should be used.

OK - The App and the Arduino will always be slightly out of synch. The Arduino can count down 60 seconds very accurately, whereas App Inventor's Clock Timer is reliant on an Android service and is system low priority.

Attached is a Project that I have butchered to show how to send the value and countdown after the send. There are only 2 buttons in this example but that should be enough for you to see how to and more. The butchered code is untested, but it is based on code that has been used many times.

BT_Send_One.aia (9.1 KB)

OH here we ran into a confusion:
synchronization is not my concern i use App inventors Clocks just for user interface to monitor . Arduino does not Know anything about my Apps Clocks. There is just one relation between my app and arduino and that is sendind "1" by App and receiving "1" by arduino.
my Clock has nothing to do with arduino.
Yes i need to learn about this clock synchronization in future .

Two Questions Arise:
why in this image the is Button Scan Can not we use directly list picker to choose BT Devise?

Capture4

should I check both of these boxes before using your blocks?

You have to scan for devices. This produces a list of Devices to pick from. It's set this way only because it's based on my tutorial file and as such it's better not to hide anything. You can of course change it to a List Picker, they do the same job.

It is best not to set timer properties in the Properties Palette - safer to only do it in the Blocks, where you can see the overall picture of your code without having to switch to the Designer. As I said before, your App should never have Timer Always Fires set to true.

So the plan of action is - test my Project to see if it works. If it does, you can copy the methods used to your own Project - you can of course copy the Blocks themselves via the BackPack.

It did not work can you please present simple blocks that has only ONE Button that sends a command "1" to arduino NO need of Clock CountDownTimer as I do not want my App to stop arduino code But arduino must stop it by itself. Also using Clock CountDownTimer makes it Difficult and Time consuming . If you just do it then i will ADD Clock CountDownTimer by myself for user interface later.

Hi Younus

At what stage did the App fail?

1 Like

I have reached to an important stage after i researched the Playstore app it was not only sending a "1" but also a line feed as ending character that makes it possible to stop my code in arduino when i unchecked line feed '\n ' the code did not stop even with this app that means it is clear that code will not stop until you send your command character with a line feed. please see my screenshot of the App.

Now my target is to see how to send a "1" with a line feed "\n" i thing i need to join the texts!!