i have a rotary encoder to set a value for a setpoint(calibration).
Everything works fine as it should ! But when the device reboots it adds one increment to the stored value Ex: if the value was 7.0 before reboot, after reboot the value will be 7.1 and subsequent reboots will keep on adding 0.1 to the previous value !!
Here are my observations (in no particular order)…
The title of the topic is “Blynk.syncVirtual adding value on reboot”, but your code does not contain any BLYNK_CONNECTED() callback or and Blynk.syncVirtual command.
So what does your fill working code look like, because simply adding this additional function in to your original code won’t work, as there are missing variable declarations.
No kidding!
Comment-out this line: Blynk.virtualWrite(V6, setpoint);
from your BLYNK_WRITE(V6) callback.
Yes. Please post the full code that you are currently using, and forum members will take a look at it. Posting irrelevant snippets and incomplete code simply wastes our time.
This is the complete code !! Compiles and works here !! I have configured a LABELED VALUE widget and as i turn the rotary encoder the values changes !!
But once the device reboots the value increments by 0.1
Without having some details of your rotary encoder it’s difficult to know for sure, but I think the code in your void loop may be incrementing the value of setpoint the first time it runs.
You’ll be able to check this by commenting-out everything in your void loop after timer.run(); and rebooting your device.
Some well placed and informative Serial.print statements would also allow you to track the value of the various variables involved in the nested if statements to work-out exactly what’s happening.
Well i took it in a different way !
The rotary encoder has a inbuilt push button.
I am reading the push button, and when its high i will set the flag == 0 and call the encoder function encoder() under if condition
at the same time rotate the encoder to change the the value. Once the button is released the flag is set to 1 under else condiion and nothing can happen further !!
Now reboot does not effect the set value !!
This is crude\bad method, but works well !! (Really bad at coding)
If anyone can guide me with a right way that will be really appreciated…
Does it increment only once at boot or continually?
This has got to be what’s doing it but like @PeteKnight says add a serial print to test Serial.println ("Adding 0.1"); it then figure out why it is running…
What does the app look like? Especially settings on V6
There is some flaw in your code, but that depends on the type of rotary encoder you use. Not all rotary encoders have a stop where both inputs are not connected (open).
Now when you understand rotary encoder better, there is some code with sufficient comment for you to adapt it for your needs. The code is written to allow Rotary Encoder Type to be defined later as a configuration option. Original code workts on MicroChip PIC processor but had proven to work for arduino as well.
If you know the type you can just pick the code for your type. Now put both inputs in a "byte now.
So you need to assign:
byte now=0;
bute prev=0;
In your code
now = digitalRead(encoder0PinA) * 2 ; // Read pin A and put it in bit 1
now += digitalRead(encoder0PinB); // Add bit B to now bit 0
…