Hi guys, I’m relatively new to arduino and programming, I’m trying to develop some sort of relay-based thermostat with blynk. It’s been a couple of days I am dealing with this issue: I’m trying to memorize on the EEPROM the value of the slider, the same value is printed on a value-display (widget).
the code I’ve been using is this one:
BLYNK_WRITE(V16) // Slider control
{
int destemp = param.asInt(); // assigning incoming value from pin V16 to a variable
Blynk.virtualWrite(V17, destemp); // print on value-display
EEPROM.write(0, highByte(destemp)); //write the first half on eeprom slot0
EEPROM.write(1, lowByte(destemp)); //write the second half on eeprom slot1
}
The void function “bot” do all the job:
void bot(boolean vacexp, boolean heatexp, int margh)
{
float h = dht.readHumidity();
float t = dht.readTemperature();
byte high = EEPROM.read(0); //read the first half
byte low = EEPROM.read(1); //read the second half
int destemp = high + low; // desired temperature
heatxp is a boolean variable connected to a button to manually activate the heater.
Glancing at your sketch, it seems you have a good grasp on Blynk commands, so aside from the eprom issue, which is not specific to Blynk and I don’t think it would be affected by it, have you tried just reading the value directly to confirm the rest of your code works?
Also something to be aware of, the DHT11 is slow, recommended minimum of 5-10 seconds between readings, so get a timer running… and really no sense in anything less than a minute or so for a basic thermostat. The DHT11 is also inaccurate at ±2 degrees.
Finally, the function you seem to be calling in the main loop, sendSensor() doesn’t make sense to me… I recognise the variables referenced as also being in the void bot, but how they work together doesn’t compute for me (amateur programmer ), so I might not be able to offer much more help, sorry.
I’m only looking at this code on a tablet, so I might be missing something, but I can’t see how this could compile without errors. You’re calling a function called sendSensor() from void loop, but no such function exists in your code. You’re never calling the bot() function, so if assume you’ve done some manual editing of the code before uploading, and you were previously calling bot() function from your void loop?
The Arduino EEPROM has a finite number of write functions for each memory location before you “burn out” that location. Each location is supposed to be good for >100k write/erase functions, so with the way you’ve structured your code this shouldn’t be an issue, but as @Costas says, using the Blynk server to store this data makes more sense.
OK, so I wasn’t seeing some newfangle coding methods… I sometimes get gun shy when I think I understand some strange looking code, then some uber coder comes along and proves me wrong … so I erred on the side of caution… and got proven wrong anyhow Go fig, but all is good
Blynk server already has the latest virtual pin data and that can be recalled if needed. e.g. via Blynk.syncVirtual(vPin)
Also, as recommended before, replace your bot() call in the main loop with a timer call.
timer.setInterval(60000L, bot(vacexp, heatexp, margh)); // Run this loop every minute
yeah, got it, adding a timer would be a good idea to avoid the imprecision of the DHT11.
the point I’m missing is how can i store and recall that value.
For example, if I add Blynk.syncVirtual(V17) ( the printed value display from the slider ) in the “slider control” BLYNK_WRITE(V16)
how can I recall the destemp value, stored in the blynk server in my “bot” function?
I’m sure it’s easy than i think, but i can’t get it.
The only reason to “recall” it is if after a disconnect or device reboot, otherwise the variable destemp already contains the integer value from the slider… just use it.
Although I think you will need to assign int destemp as a global variable, as you do for int margh and int addr and then change this: