Bluetooth Not Receiving Data Correctly from Arduino Uno

Hello

I am hoping you can assist me as well when you have the time. I will probably start a new topic on this.
I have a somewhat similar problem. I am sending data from my Arduino to my application, but it looks as though the app is not receiving the data packages correctly, or I have not conditioned it to do so properly. For example I will send 127.9 to the app, and at first it will read the whole number, then when I send a different value to replace that one, it displays the data almost as though it is scrolling across the screen, .9 --> 7.9 ---> 27.9 ---> 127.9 --->.9 and then it just stays as .9 until I send in a different value. What I need is for the value to display fully every time.
NB, this is for a coin acceptor. So when the person enters a coin, the value of the coin is subtracted from CreditDue and then CreditDue is sent to the app to be displayed.

void CreditCounter(float CreditDue)
{
float CreditAmountStorage = 0;

while(CreditInserted < CreditDue)
{
  i=i+1;
  Serial.println(CreditDue);
  
  if (i >= 30 and impulsCount == 1){CreditInserted = CreditInserted + 0.2; impulsCount = 0; EEPROM.put(0, CreditInserted);}
  delayMicroseconds(2);
  
  if (i >= 30 and impulsCount == 2){CreditInserted = CreditInserted + 0.5; impulsCount = 0; EEPROM.put(0, CreditInserted);}
  delayMicroseconds(2);
  
  if (i >= 30 and impulsCount == 3){CreditInserted = CreditInserted + 1; impulsCount = 0; EEPROM.put(0, CreditInserted);}
  delayMicroseconds(2);
  
  if (i >= 30 and impulsCount == 4){CreditInserted = CreditInserted + 2; impulsCount = 0; EEPROM.put(0, CreditInserted);}
  delayMicroseconds(2);
  
  if (i >= 30 and impulsCount == 5){CreditInserted = CreditInserted + 5; impulsCount = 0;}
  delayMicroseconds(2);
  
  if(CreditInserted > 0){CreditDue = CreditDue - CreditInserted; CreditInserted = 0; break;}/*Reduces outstanding amount by amount inserted and 
  zeros the amount inserted variable to prevent the code from deducting the inserted amount with every cycle of the while loop.*/
  
}    

}

Also, the logic on my second "if" block is not correct as the value of total price never changes after the Bluetooth connects. I am struggling to find a way to compute the value coming in from the Arduino as it is stored in a label, and not a variable. I should be able to figure this out in the next hour. However, please feel free to assist with that as well if you can.

Okay, I think I worked out the issue with the "if" block. My blocks now look like this.

I doubt this will work. Looks like I'm comparing a string to and integer. I'll keep working on it though.

It may be easier to send Strings instead of Bytes.

1 Like