The operation <= cannot accept the arguments: , [*empty-string*], [35]

Record or Store? You could add records to a List in the App and draw a graph from those at the end of a Robot test. Records can be stored/recalled from TinyDb.

I selected the option "Download Blocks as Image" and uploaded it. If you click on the image, it will expand to show all the blocks.

I have fixed it although i don't know what block to put under "then" so i just left it blank. I hope it's not going to create any issues with the app? Here are all the updated blocks.


I tested the updated app, but there are some issues:

  1. The sensor values are not received in the app but the commands sent to the Arduino work. I somehow managed to fix it by removing under Clock1.Timer, the block "set Clock1.TimerEnabled false". Not sure why that was the problem though.
  2. After disconnecting the hardware while the app is running, the Label1.Text still shows "Connected". But then after a few seconds, there is a temporary notification: Error 517: Unable to read: bt socket closed, read return: -1

Isn't that the same? Forgive my ignorance. I am not sure what's the difference. Basically, i am thinking of keeping a list of all the angles data with respect to time. The Arduino is sending a new angle to the app every 300 ms.

OK, i will do some research and report back with my attempt.

Oops you did indeed and the Clock Timer Block is correct.

That goes back to the shared channel I think, though you are having a lot of trouble with what is a fairly common set up that you will find across the Forum in bucket loads.

The disconnect should be detected immediately. There isn't more than one source of power or a capacitor in the mix? What we can do is to add a "get data attempts count". If there is no data after n cycles of the clock, assume the connection has failed.

There are other possibilities concerning a lack of data flowing to the App - firstly, the fact that HC-06 is receiving well does not mean it can send well. Ensure there is nothing in the vicinity of the robot, or a component of the robot, that can interfere with the BT signal (the motors for example). If you have an unused HC-06, try that one - re Patryk's comments, it is possible that the HC-06 is already damaged. I'm an expert at damaging electronics :innocent:

It's very important to keep everything cool. Incorporate a cooling fan into your design (simple DC PC case fans are good). How good are the sensors in terms of quality and reliability?

https://www.professorcad.co.uk/appinventortips#TipsBluetooth

I'm not sure what might still be causing this problem, but i think i found an error (probably unrelated) in the ListPicker1.AfterPicking block. There was a second ListPicker1.Elements block as well as in the ListPicker1.BeforePicking block. I replaced the first original block with the second block.

After looking again at the Arduino code, i think that it is not possible for data to be sent and received at the same time on the Serial channel, since the entire code is running in a loop. So, first, there is always a check done for any data received (command) from the app and then the sensor output data are printed out to be sent to the app for display.

Here is the current state of my app (click on the image to enlarge and see all the blocks). Every time i tried to incorporate the block "set Clock1.TimerEnabled false" somewhere, it ended up with some issues with not being able to read the sensor data.

The Arduino UNO setup is only powered via its USB port through a data cable connected to the PC. No added capacitors. Just a standard HC-06 module connected to the UNO along with a sensor.

There is no communication interference with the Arduino setup. I only have those few electronics turned on and it is right next to my phone. Motors are not connected at this point. I am using the onboard LED of the Arduino to simulate turning on or off the motors. I also tried another HC-06 and also an HC-05 module. Same results. The Arduino is not overheating. The room is also at a relatively cool temperature so i don't think that's the cause. The HC-06 is sending data as expected at 300ms interval from the Arduino and displayed without issues in the app, so i doubt that it's a fault in the HC-06 hardware.

I think the problem might be in the Clock1.Timer block. From my testing, while the app is connected to the Bluetooth module and everything is working in the app, if i simulate a disconnection error, by simply removing the USB cable, then the entire Arduino UNO turns off, but the app is unable to detect the disconnection. My phone uses Android 9 and it is unmodified and working with no issues.
btconnectdetect
After disconnection of power, the incoming sensor data label stays the same in the app and the status of the connection still shows "Connected". The Else condition in the Clock1.Timer block is therefore not being processed for some odd reason. The clock apparently still assumes that the Bluetooth client is still connected, or the BluetoothClient1.IsConnected block is still returning true. Maybe it's a bug in MIT App Inventor 2??

I have tried to come up with a solution, since it seems that for some reason the app and/or my phone is not detecting when the connection has failed.


I only changed the Clock1.Timer block. The label ErrorCount text is set to 0 in the Designer window. If there are 10 or more connection errors, then the status of the connection is set to Disconnected. The clock fires every 100 ms and data is sent from the Arduino every 300 ms, so i think 1 second should be enough to determine if the connection has been interrupted when no data is being received. But even when the connection is successful, no sensor data is received and no commands sent from the app are working. I don't understand why this change broke the app.

When the app connects, the Connection error count quickly increases from 0 to 10 and then the connection status shows Disconnected. During that time, there is no sensor data received in the Serial Data Stream.

I did a search and found this thread Change Text when Bluetooth disconnected so it seems like this problem is actually a limitation of Bluetooth and AI2. Although, there should be a workaround to make this work?

Do you mean you can't do that and so you are going to add software serial, or do you mean it won't happen because of the loops?

That's an issue - not actually getting enough power (I assume the motors do not have a seperate power supply?) See my website here:
https://www.professorcad.co.uk/appinventortips#TipsArduino

Ah, got my head twisted there - I thought the issue was receiving, not sending from the App, sorry.

I think your code is good, should not have broken the App as you put it, but presumably it means that the first data send takes more than one second somehow?

My bad. I wrongly expressed myself. I meant, it is possible for data to be sent and received on the hardware Serial channel without requiring an extra Serial port via Software Serial library. This works in this case since in every loop, the incoming data (command sent from the app) is first read from the Serial port and then sensor data from the Arduino is sent to the app via the same Serial port. Hence, from my understanding, there is no possibility of conflict. So, no need for an extra Serial port.

I think it should be OK, but you do have very short time intervals. That could be trouble on the App side because it is using Android's timer service, which is low priority and can be unreliable.

1 Like

Concerning the no show of data, I think it's possible that the sensor takes more than 1 second to produce the first value? You could have a one-off delay in the Sketch, to ensure that the sensor is given a little bit of time before streaming the data.

I managed to solve the disconnection by using this code hack: Bluetooth HC-06. Arduino. Send. Receive. Send text file. Image
But there is a time delay of 5-10 seconds before the disconnection error appears.

That is a big delay, considering your fast clock interval.

Can you list here:

  1. Phone Make and Model
  2. Exact Android Version
  3. Bluetooth version of the phone
  4. Version of Uno

The HC-06 should be BT v2.0 + EDR

Let's see if Evan Patton can think of any reason why recognition of disconnection should take so long.

1 Like
  • Phone Make and Model: Samsung S8 SM-G950F (perfectly working condition)
  • Exact Android Version: Android 9 (stock version, never modified nor rooted)
  • Bluetooth version of the phone: Bluetooth 5
  • Version of Uno: R3

There was a mistake in the "If Then Else" block of BluetoothClient1.IsConnected under the Clock1.Timer. I fixed it so the app now works but still, the disconnection is not detected if the Bluetooth module is removed, so the error count is actually never incremented. From my research, it seems like this is a limitation of AI2 or maybe Bluetooth 2?

AI2 only has a limitation on older Android and the BT Classic functions are aimed at v2 to v2.1 Bluetooth.

Since you have a BLE 5 phone, you might like to use BLE instead (see my chart of BLE compatible modules). AI2's MIT BLE extension has more to offer but is just as easy to use (well, almost :grin:).

https://www.professorcad.co.uk/appinventortips#TipsBluetooth

1 Like

The issue isn't with App Inventor, but with how the Android implementation of BluetoothSocket works for Bluetooth classic. The socket state is only reset to closed when the close() method is called. This state is never transitioned to automatically. In App Inventor, if you have DisconnectOnError set to true and you attempt to read/write the socket after the remote device has gone away, it will call Disconnect for you and then the IsConnected property will be false. So long as you never attempt to interact with the device after removing the Bluetooth module, the Android socket will happily report it is still connected.

1 Like