App hangs everytime the timer ticks

I need to control a bluetooth controlled car with a virtual joystick and measure the temperature and humidity of the environment.

My app works fine but it hangs for one second and comes back to normal everytime timer ticks.

I use DHT11 as sensor, Arduino Uno, HC-06 bluetooth module.

How can i fix this problem?

mit help.txt (816 Bytes)

tick

Remove that 2 second delay in your arduino code. Use millis instead. Delays are not good to use in anywhere in arduino code, it blocks your arduino program, and it cannot do anything but wait. That delay also activates again almost right away after it is end.

Your error is in the marked section:

b471d5aa54a38dcdce36377d55a43b941ee7022c_2_660x499

You should have only one BlueTooth ReceiveText block in there, and it should feed a global Message variable. From that point on, the Clock Timer should work with that variable, and leave further ReceiveText operations for the next Clock1.Timer event.

The damage done by the second and third ReceiveText is twofold:

  • They lose the data that was just read, if they don't save the data somewhere, and
  • They have lost the insurance from that test of BytesAvailable>0 that the readText won't block your app until more data arrives from BlueTooth.

Here is a stock set of blocks for this situation:

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

BlueTooth_delimiter_sample.aia (3.4 KB) global message

You can substitute your own message parsing code once you have gotten the critical global Message variable set up and removed th extraneous ReceiveText blocks.

If you're still unsure about the damage done by those extra ReceiveText blocks, here is a little coin flipping game to consider.

We will flip a coin.
If it comes up Heads, I win $5.
If it comes up Tails, you win $5.

Now let's apply your blocks logic to the game ...

If (flip a coin) result = Heads then
  give ABG $5
else if (flip the coin again) result = Tails then
  give you $5.

Can you see why I would like this game?

Thank you so much this helped a lot.