Display issue with an OLED

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
fredfit
Posts: 10
Joined: 17 Jun 2020 12:50

Display issue with an OLED

Post by fredfit »

Hello,

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);
}
I would have expected that a command line like "oled.clrline" exist, that I would place just before "oled.print(valueHygro);", but not ...
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 !

User avatar
PoltoS
Posts: 5946
Joined: 26 Jan 2011 19:36

Re: Display issue with an OLED

Post by PoltoS »

You can print old value with background color before printing the new one. Typical trick for small displays

fredfit
Posts: 10
Joined: 17 Jun 2020 12:50

Re: Display issue with an OLED

Post by fredfit »

Thank you PoltoS for this trick.
Unfortunately, I don't see any available "oled." command that can change the color of the text.
Could you be more precise ?
By the way, I woud also be interested in having a full list of the available commands.

p0lyg0n1
Posts: 187
Joined: 04 Aug 2016 07:14

Re: Display issue with an OLED

Post by p0lyg0n1 »

Hi,
1. About OLED:
the simpliest way is method void fillRect(byte w, byte h, byte fill);

Code: Select all

oled.gotoXY(needed_x_in_pixels,needed_y_in_pixels/8); 
oled.fillRect(needed_x_size_in_pixel, needed_y_size_in_pixels/8, 0);
2. If you have some problems with stack don't use map() function. It's to fat for i8051, because it use 4 32bit values as operands and one for return.

Best regards,

Alex.

fredfit
Posts: 10
Joined: 17 Jun 2020 12:50

Re: Display issue with an OLED

Post by fredfit »

Thank you p0lyg0n1 !
I will try to use oled.fillRect (I just realized that "Rec" stands for "Rectangle" !), even if I cannot figure out what sizes I should give to x and y when font_numbers16 is being used ... I will give it a try.

I don't have any problem with the map() function for the time being.

Post Reply