Page 2 of 2
					
				Re: Analog value with I2C display ssd1306
				Posted: Thu Oct 23, 2025 1:07 am
				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);
			 
			
					
				Re: Analog value with I2C display ssd1306
				Posted: Thu Oct 23, 2025 9:11 am
				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.
			 
			
					
				Re: Analog value with I2C display ssd1306
				Posted: Thu Oct 23, 2025 6:57 pm
				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...
			 
			
					
				Re: Analog value with I2C display ssd1306
				Posted: Sat Oct 25, 2025 1:37 am
				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
			 
			
					
				Re: Analog value with I2C display ssd1306
				Posted: Sun Oct 26, 2025 7:08 pm
				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