Arduino not running updated code, analogRead returns same values

Please help me to solve this very strange problem. Often time, uploading my sketch doesn't executing the updated sketch. I was carefully removing the power and the tx/rx pin of the bluetooth, and most other pins.

Furthermore, I even hard coded some changes, but the programs return the values that I know it's not the latest. For example:

Version 1, return this via bluetooth:

Variable A: 12

Version 2: return this:

Variable x: 12

Here, I got 2 problems:

Instead of getting x, I keep getting A.

The value also changes from 12 to 13 and back to 12, which was valid for what my expected input is (12 and 13 is just an example). But it's not corresponding to the input that I changed, which I measured using a volt meter (analogRead) on the pin and on the arduino ground.

Sometimes, the sketch upload works. I switched to another arduino nano and same thing happend after 1st upload.

Here's a sample the console:

....

[e4] . [12] d [64] . [14] . [8d] . [12] . [b9] . [12] . [9d] . [12] . [d9] . [12] . [00] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff]
avrdude: Recv: . [10]

| 100% 1.77s

avrdude: avr_read(): skipping page 104: no interesting data
.....

avrdude: verifying ...
avrdude: 13290 bytes of flash verified
avrdude: Send: Q [51] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]

avrdude done. Thank you.

You mention analogRead() , but it looks like you do not even succeed in uploading the program or sketch containing this function call. You have to solve this uploading problem first.

Do you have any problem uploading say the example “blink” sketch to your Nano?
Interference with the tx/rx pins during uploading may explain some problems.

The upload didn't show any error. However, often times, the result shows previous version data.

I got an update though. So I switched to an arduino mega, and I got some answers!

Using the serial port of the mega for monitoring, and then using the Android studio to monitor the Android app's bluetooth receiving data.

Both should give the same value, since I send them the exact same data. I included a counter to compare.

The Serial port monitor shows up to date data, but the Android's data is way behind. For example, the counter is 1200 on the Serial port monitor of the Arduino, but 200 on the Android.

I was thinking either the bluetooth module of the Arduino or the Android. I send about 30 characters every 60 miliseconds (in this test).

So, it must be the Android. Since unplug the Arduino and reply, the Android still shows the old data.
Looks like now I am chasing another platform issue.

Thanks for trying to help though.

Further thinking, I still don't know if it's the bluetooth module or the phone that is causing the bottle neck.

I use the baud rate of 115200. The string I send over is 24 character longs. Which translate that approximately, it can handle 600 sends a second.

With 60 miliseconds between send, it's only about 17 sends a second. So technically, it should be able to handle it.

But, with all the data trailing behind, can the bluetooth HC-05 module cache that much of data or the data went through and accumulate somewhere in the Android phone?

1000x24 characters is 24 Kb of data. Does the HC have that much of cache? I disconnect the bluetooth in the app, and reconnect. When that happens, I reset the counter, and the Serial monitor shows the counter starts at 0 again. But the android app still printing the counter high up in the thousand.

What do you think where the issue is?

I have fixed the Andriod code. It's a simple bug. Reading data got multiple "record", while processing, I only process 1 for each read. So it's behind.

However, now that I process them all, in another thread, things are good, with an exception that bluetooth is 1 or 2 seconds behind, comparing with Usb serial communication (everything else is exactly the same).

I will open another thread to ask if this is HC-05 or it's android thing again. On android, I just print out what I read, so it is super simple.