Analog value with I2C display ssd1306

For general Flowcode discussion that does not belong in the other sections.
xiran
Posts: 6
http://meble-kuchenne.info.pl
Joined: Fri Oct 17, 2025 5:46 pm
Been thanked: 1 time

Re: Analog value with I2C display ssd1306

Post by xiran »

The variables are declared:

unsigned char d[4], i;
unsigned int volt, res ;

And used:
A) Not working:

for(i=0;i<4;++i){
d=res %10;
res=res/10;
}
drawChar4(d[3], 0, 0);
drawChar4(d[2], 0, 2);
drawChar4(d[1], 0, 3);
drawChar4(d[0], 0, 4);

B) Working:

for(i=0;i<4;++i){
d=volt %10;
volt=volt/10;
}
drawChar4(d[3], 0, 0);
drawChar4(d[2], 0, 2);
drawChar4(d[1], 0, 3);
drawChar4(d[0], 0, 4);

Steve-Matrix
Matrix Staff
Posts: 1611
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 224 times
Been thanked: 380 times

Re: Analog value with I2C display ssd1306

Post by Steve-Matrix »

The only potential difference I can see is the value or "res" or "volt" immediately before entering the for loop will affect things. You should try setting it to a known value.

xiran
Posts: 6
Joined: Fri Oct 17, 2025 5:46 pm
Been thanked: 1 time

Re: Analog value with I2C display ssd1306

Post by xiran »

Thx for answer steve.

If i put a know value (res=9876), it shows fine. So maybe the calculation is the bad thing

Edit:

If i made the real calculation, "res" calculation, is a negative answer, because volt it´s a 4 digits value (not less 5v value), so, if i have 4v, volt is equal to 4000, not only 4

Edit2:
So, i need to rething the res calculation

Edit3:
The short answer, is treat the result of volt (like a mV), so:

res= ((330 * volt) /(5000 - volt));

But the result, it´s not accurate yet...

xiran
Posts: 6
Joined: Fri Oct 17, 2025 5:46 pm
Been thanked: 1 time

Re: Analog value with I2C display ssd1306

Post by xiran »

Changed R fixed from 330 to 100 ohms, and measure values to max 100 ohms:

volt=((unsigned int)ADRESH*256 + ADRESL)*5;
res= ((100 * volt) /(5000 - volt));

I´ve upload some values:
Real v Oled R Oled V Calc
21 10 1095 29
33 13 1300 35
82 19 2280 83
100 24 2550 104

Where:
Real v:
are the color code from R
Oled R:
Value from "res" math showed in oled dspy
Oled V:
Value from "volt" math showed in oled dspy
Calc:
Real Value calculated at hand

xiran
Posts: 6
Joined: Fri Oct 17, 2025 5:46 pm
Been thanked: 1 time

Re: Analog value with I2C display ssd1306

Post by xiran »

Finally, at the end, this was be the answer:
"
volt=(ADRESH << 8) | ADRESL;
// Calcular la resistencia desconocida usando solo aritmética de enteros, float no, long no en 12f675
r_x = (unsigned int)((unsigned int)100 * volt) / (1023 - volt);
"
It give it to me, the same result as multimeter

With this method, don't care if 5v are not stable

Post Reply