Runtime error _cannot accept arguments

Hello to all guys,

I'm new to App Inventor.. still learning.

I'm trying to make an app to control a motor-driven shelf for my laser machine. I'm using an Arduino, relay bank, Bluetooth, and a distance sensor combo, on the machine. The shelf position is detected and data is transmitted to the app.

The user will have the option to set a predetermined distance. Once this distance is reached the motor will stop.

When comparing the values received from the Bluetooth variable an error sprouts out! Tried many variations but none worked.

I have attached all files including Arduino's code. Any help is MUCH appreciated. I don't know what else to this stage.

Best regards,
Kenneth


LaserBoxController.ino (2.4 KB)

version_7.aia (141.9 KB)

This looks like the standard missing end of message delimiter problem.

Here's the standard advice:

Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
BlueToothClient1_Properties
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

Thank you for your answer ABG,

I am really a beginner in App Inventor and to be honest, I tried and read all the links you sent. I didn't understand much but tried some solutions without success.

Can you be more specific rather than standard, please? Let me explain better...

  1. Is my Arduino code correct? I've tried to insert another Serial.println(). This resulted in a blinking label

  2. Delimiter is already set on 10. So changed nothing here

  3. What does really receiving -1 mean in BT?

  4. How can I compare a variable receiving data to a constant variable? Is it possible?

Thank you
Kenneth

Here is your most recently posted code section of relevance:


void loop() 
{
  //sends distance reading to mobile via BT
   getdistance();
    
    Serial.println(distance,0);
    

      //test relay UP
      state = Serial.read(); // Reads the data from the serial port
      if ( state== '0') 
      {
      digitalWrite(relay1Pin, HIGH); 
      delay(500); 
      }
      else if (state == '1') 
      {
...

My C is weak. Could you tell us what that ,0 in Serial.println(distance,0); is for?
It is to trim fractions off distance, or is it to pad your output messages?
(If in doubt, rip it out)

Did you see the tool tip for that block yet?

Since you have 10 (New Line) as your Delimiter, that will return exactly one message (or wait until there is one, which you don't want but that's okay since your request is guarded by that test to insure there are bytes available so you will never wait here.)

By The Way, your Clock Timer is way too slow, and will result in a growing backlog:
DataRxTimer

To avoid a message backlog piling up in the AI2 BT buffer, ask for data twice as often as it will arrive. I suggest maybe 75 ms since you delay(150) in your .ino file. Don't worry about running the Timer too fast, since it's okay for it to come up empty. As a precaution, show the BytesAvailable number in a Label, to warn you if you get a backlog.

First, make sure it is clean (no commentary from the sending device, just exactly one number or something you can parse easily like a JSON tag:value pair.)

AI2 uses Duck Typing, so don't worry about text to number conversion as long as you use a math (blue) comparison block and the incoming text reads like a number (No Hello World garbage)

Here is an updated blocks sample illustrating these ideas ...

BlueTooth_delimiter_sample.aia (3.4 KB) global message

Thank you, ABG. With your help, I'm getting something that finally works.

Serial.println(distance,0) means simply "no decimal point", a whole number or integer, no fractions.

Now the code is working but an error pops out every now and then.

Screenshot 2023-01-12 164712

What I'm understanding is that a blank string or "" is detected. The code is as below.

I've tried to correct it with an "if-then" statement but it's not working.

Can you help me to fix this, please?

Thank you once again, you have been super helpful. In my country, we say you're a "KING"

My regards,
Kenneth

  • only do one read from Bluetooth per clock timer cycle, into a variable.
  • test that variable to insure it is a number before trying to use it in a math block.
  • math blocks hate text that isn't a number.

Thank you, ABG for your help
Problem solved, very grateful.

I'm posting a screenshot of the correct code as suggested by your good self....For future reference, of course!

image

The other Power Users run rings around me.
I'm more of a Court Jester.