I'm trying to do a simple display on a 128x64 I2C OLED of the humidity value from a soil moisture sensor like this one:
https://www.smart-prototyping.com/image ... 50x750.jpg
I can well retrieve the humidity value (named "valueHygro" in my sketch) from the sensor module connected to ADC1 (pin 4 of the Z-Uno) but get an issue when displaying it on the OLED (SCL to pin 9, SDA to pin 10) :
- if I leave the sensor outside (no humidity), a 0 is well displayed
- now if I put the sensor into a glass of water, I get 100 displayed
All is well so far, but if I now remove the sensor from the water, it now displays 000 instead of 0. It seems that the 2 last zeros of "100" that were not displayed at step 1 now remains displayed ...
Is there a way to avoid this ?
My sketch:
Code: Select all
#include "Wire.h"
#include "ZUNO_OLED_I2C.h"
#include "ZUNO_OLED_FONT_NUMB16.h"
#include "ZUNO_OLED_FONT_RUS8.h"
OLED oled;
#define pinHygro 4 // ADC1
int valueHygro;
void setup() {
pinMode(pinHygro, INPUT);
oled.begin();
oled.clrscr();
}
void loop() {
valueHygro = analogRead(pinHygro);
valueHygro = constrain(valueHygro,400,1023);
valueHygro = map(valueHygro,400,1023,100,0);
oled.gotoXY(0,4);
oled.setFont(zuno_font_numbers16);
oled.print(valueHygro);
delay(500);
}
In my project, I will have other things to display, I try to avoid to do a "oled.clrscr" command at the beginning of the loop.
Thanks !