Random characters being displayed in label instead of potentiometer values

I am trying to display values seen on the serial monitor in the MIT app but random characters pop in the label instead of actual values.
Here the the blocks section.

This is the app screen


(ON and OFF buttons are redundant )

And this is the code
image

I have tried changing the baud rate and also increasing the delay, but it still makes no difference.
Values read from the middle pin of the potentiometer to GPIO 25 are correctly displayed on the serial monitor.
PS: This code is written for ESP32 WEMOS LOLIN.
Any help will be greatly appreciated

Hello Meghana, welcome to the grey hair forum :upside_down_face:

Are you sure the output from the potentiometer is an integer? If the value type is not correct, that is going to cause an issue similar to your description.

Secondly, use SerialBT thus:

SerialBT.print(n);
SerialBT.println();

Now then, the time span. At such a speed (100 milliseconds) the delay() function should not be used - it could have an adverse effect on the readings. It must also be the case that the App timing must be faster, allowing the app to receive and process a value before the next value arrives. I can't see what you have set the Clock in your App to, but that always requires experimentation, starting with a much longer time period and tweaking faster if required. The human eye cannot tolerate 100 millisecond value changes so I suggest you set the time period to be longer - the longest that the project can accept.

What is the Bluetooth version number of your ESP32 WEMOS LOLIN?

It might be using BLE.......

When receiving the data, you need to tell the App what the data delimiter is. In my example above it is SerialBT.println() = ASCII Char 10.

Also, the 'Bytes available to receive' Block is exactly that - a flag stating there are bytes, but it does not necessarily mean it holds all of the bytes. We use the math symbol -1 to ensure all bytes are read.

Assuming your ESP32 isn't running BLE, the above tweaks should fix your issue.

To replace delay() (You will need to change this to suit your SerialBT output):

//Fake data stream to demo elapsed milliseconds timing


//vars
unsigned long lgUpdateTime;

void setup()
{
               Serial.begin(9600);
               lgUpdateTime = millis();
}

void loop()
{
	           if(millis() - lgUpdateTime > 1000)           //Loop approx every 1 second
               {
                         lgUpdateTime = millis();

                         //Bluetooth to App
                         Serial.print("Hello");
                         Serial.print("|");      //Value delimiter
                         Serial.print("World");
                         Serial.print("|");
                         Serial.println();        //This empty last line tells App "End of Data" = Ascii LineFeed Char Number 10
               }
}
1 Like

I am new to this mit and don't fully understand your reply I checked for the Bluetooth specification of Wemos lolin32, which uses Version 4.2 BR/EDR and BLE. I used SerialBT.print(). the clock rate is 10.
I have made a simple interface.


the blocks area s following

and the code is as follows
image

Since the ADC in Esp32 is 12 bits, so the value will be in the range of 0 to 4094, we will need to receive 2 bytes. These two bytes need to be converted to an integer value accordingly. Try these blocks:

1 Like