Battery indicator

Op 20 november 2018 12:54:38 schreef a.j nieuwlaat:
capri

toen ik die site zag met die sketch dacht ik dat zou ik wel graag voor mijn accu willen gebruiken

Maar na informatie te hebben ingewonnen bij de programmeur van Artekit Labs bleek het om 'n demo versie te gaan

heb hem toen gevraagd of hij dat in 'n werkende versie kon maken antwoordde hij negatieve,

dacht dat het eenvoudiger was

daarom riep ik de hulp in van Circuits online

Ik begrijp nu de delers

zoals ik zei weerstanden zij nu 20k en 10k

zijn al die regels nodig voor de demo aansprakelijk voor de errors
kan het programma daardoor niet eenvoudiger

het grootste deel code is het tekenen van de accu. ergens zit u arduino nu toch ook een dalend getal te introduceren, en die zit nu niet in de code (tenzij je andere code in de arduino hebt steken dan wat wij nu doen).
die grote blok waardes met 0x00 erin, is de tekening van de accu. persoonlijk had ik gewoon blokjes getekent of het veel compacter getekent.

dit deel code uit de demo was het leeglopen van de accu

c code:


    showBatteryLevel(percent);
    if (percent)
-        percent--;
    else
        percent = 100;
    delay(50);

stel dat de accu op 100 staat.
dan doet die een showBatterijlevel van 100 (vol dus)
daarna met die ifloop gaat die kijken

code:

if (percent)     zolang percent groter is dan 100, dan:
percent--        trek 1 af van 100 (99dus)
else             anders     
percent = 100    maak percent weer 100
delay(50)        wacht 50ms en herbegin

die doet niet anders dan 100% weergeven, 99% weergeven, 98% weergeven..... 1% weergeven, 0% weergeven, 100% weergeven
op 65% ging er een blokje uit op de tekening, op 32% ging er een blokje uit en op 0% ging er een blokje uit.
als je die code hebt vervangen door mijn code, dan gaat de arduino daadwerkelijk kijken naar de accuspanning en geeft dat weer.
als die bij u met niks aangesloten nog steeds van vol naar leeg terugloopt, is er fysiek iets verkeerd aangesloten (er verloopt een spanning op A0 en dat kan niet want die 10K weerstand hangt naar massa) of zit er een regel teveel in je programmeercode.

heb je nog andere schermpjes? of enkel dat ene kleintje? of heb je losse ledjes liggen?
ik zou anders een schakeling maken en code schrijven om het weer te geven met eigen code en niet die demo van internet

ik hou van werken ..., ik kan er uren naar kijken

capri

spanning gemeten tussen A0 en gnd 4.64V

Capri.

in de modelbouw is niet zoveel ruimte om alles netjes weg te werken

ik had dat programmetje van u ( void ) ertusen gezet

capri

wanneer er geen accu aangesloten blijft het display vol

ga alles eens opnieuw aansluiten

capri

alles opnieuw aangesloten display blijft wisselen(geen accu) aangesloten

capri
nogmaals de komplete sketch

#include <U8g2lib.h>
#include <U8x8lib.h>

// This is the display object. You will change this line if you are using pins
// other that 12, 11, 9 and 10.
U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI display(U8G2_R0, 12, 11, U8X8_PIN_NONE, 9, 10);

// This is the battery bitmap// This is the area inside the battery bitmap, in pixels
static const PROGMEM unsigned char battery_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00,
0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
#define CHARGE_AREA_START_X 20
#define CHARGE_AREA_START_Y 18
#define CHARGE_AREA_WIDTH 83
#define CHARGE_AREA_HEIGHT 28

// This is the battery fill mode
// BATTERY_MODE_SOLID = 1 means the battery bitmap will be filled with
// a solid rectangle according to the battery charge.
// BATTERY_MODE_SOLID = 0 means the battery will be filled with a
// rectangle subdivided in 3. If the battery level is 66% or more, it will
// draw 3 rectangles. If it's 33% or more, it will draw 2 rectangles. It will
// draw 1 rectagle if the battery is less than 33%.

#define BATTERY_MODE_SOLID 1

// This is the main function, and the one you will want to transplant to your
// code. Pass the battery charge percent and it will draw the battery with
// the corresponding charge level.
void showBatteryLevel(uint8_t percent)
{
uint8_t width;

if (percent > 100)
percent = 100;

display.clearBuffer();
display.drawXBMP(0, 0, 128, 64, battery_bitmap);

if (BATTERY_MODE_SOLID)
{
width = (percent * CHARGE_AREA_WIDTH) / 100;
display.drawBox(CHARGE_AREA_START_X, CHARGE_AREA_START_Y, width, CHARGE_AREA_HEIGHT);
} else {
uint8_t bars;

if (percent >= 66)
{
// Show three bars
bars = 3;
} else if (percent >= 33)
{
// Show two bars
bars = 2;
} else if (percent > 0)
{
// Show one bar
bars = 1;
} else {
// Show nothing
bars = 0;
}

uint8_t offset = CHARGE_AREA_START_X;
for (uint8_t i = 0; i < bars; i++)
{
display.drawBox(offset, CHARGE_AREA_START_Y, 27, CHARGE_AREA_HEIGHT);
offset += 28;
}
}

display.sendBuffer();
}

float accuspanning = 0.0;
float accuvol = 13.5; //(volle accu 12,6V)
float acculeeg = 11.0; //(lege accu 10,0V)
int percent;

void setup()
{
// Initialize the display object
display.begin();
pinMode(A0, INPUT); //neem ingang A0
}

void loop()
{
// Some test code to scan all the battery levels
accuspanning = ((analogRead(A0) * 5.0) / 1024.0 ) *3;

percent = map(accuspanning, accuvol, acculeeg, 100, 0);
showBatteryLevel(percent);
delay(200);
}

ok, heb HEEEL de display code eruit gegooid en enkel het meten eens laten lopen.
probleem 1: als je een spanning lager aanlegt dan de accu bekom je een negatief percentage (als ik 4V aanleg krijg ik -350%) en dan krijg je de zotste kuren.
ergens moet het percentage gedefinieerd worden tussen 0%-100%

probleem 2: er staat al een percent in de code bovenaan, en wij gebruiken percent ook beneden als variabele. 2 variabelen met dezelfde naam dus....

probeer dit eens

code:


#include <U8g2lib.h>
#include <U8x8lib.h>

// This is the display object. You will change this line if you are using pins
// other that 12, 11, 9 and 10.
U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI display(U8G2_R0, 12, 11, U8X8_PIN_NONE, 9, 10);

// This is the battery bitmap// This is the area inside the battery bitmap, in pixels
static const PROGMEM unsigned char battery_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00,
0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
#define CHARGE_AREA_START_X 20
#define CHARGE_AREA_START_Y 18
#define CHARGE_AREA_WIDTH 83
#define CHARGE_AREA_HEIGHT 28

// This is the battery fill mode
// BATTERY_MODE_SOLID = 1 means the battery bitmap will be filled with
// a solid rectangle according to the battery charge.
// BATTERY_MODE_SOLID = 0 means the battery will be filled with a
// rectangle subdivided in 3. If the battery level is 66% or more, it will
// draw 3 rectangles. If it's 33% or more, it will draw 2 rectangles. It will
// draw 1 rectagle if the battery is less than 33%.

#define BATTERY_MODE_SOLID 1
float accuspanning = 0.0;

// This is the main function, and the one you will want to transplant to your
// code. Pass the battery charge percent and it will draw the battery with
// the corresponding charge level.
void showBatteryLevel(uint8_t percent)
{
uint8_t width;

if (percent > 100)
percent = 100;

display.clearBuffer();
display.drawXBMP(0, 0, 128, 64, battery_bitmap);

if (BATTERY_MODE_SOLID)
{
width = (percent * CHARGE_AREA_WIDTH) / 100;
display.drawBox(CHARGE_AREA_START_X, CHARGE_AREA_START_Y, width, CHARGE_AREA_HEIGHT);
} else {
uint8_t bars;

if (percent >= 66)
{
// Show three bars
bars = 3;
} else if (percent >= 33)
{
// Show two bars
bars = 2;
} else if (percent > 0)
{
// Show one bar
bars = 1;
} else {
// Show nothing
bars = 0;
}

uint8_t offset = CHARGE_AREA_START_X;
for (uint8_t i = 0; i < bars; i++)
{
display.drawBox(offset, CHARGE_AREA_START_Y, 27, CHARGE_AREA_HEIGHT);
offset += 28;
}
}

display.sendBuffer();
}

float accuspanning = 0.0;
int accuvol = 135; //(volle accu 13,5V)
int acculeeg = 110; //(lege accu 11,0V)
int percentage;

void setup()
{
// Initialize the display object
display.begin();
pinMode(A0, INPUT); //neem ingang A0
}

void loop()
{
// Some test code to scan all the battery levels
// *3 is de spanningsdeler van de weerstanden
// *10 omdat de map niet met kommagetallen werkt. 13,5V => 135
accuspanning = ((analogRead(A0) * 5.0) / 1024.0 ) *3 *10;

percentage = map(accuspanning, accuvol, acculeeg, 100, 0);
if (percentage < 0) {  percentage = 0;}
if (percentage > 100) { percentage = 100;}
showBatteryLevel(percentage);
delay(200);
}
ik hou van werken ..., ik kan er uren naar kijken

Capri,

Error mesage;

Arduino:1.8.6 (Windows 10), Board:"Arduino Nano, ATmega328P (Old Bootloader)"

C:\Users\Toon\Documents\Arduino\sketch_nov21a\sketch_nov21a.ino: In function 'void showBatteryLevel(uint8_t)':

sketch_nov21a:35:33: error: 'battery_bitmap' was not declared in this scope

display.drawXBMP(0, 0, 128, 64, battery_bitmap);

^

sketch_nov21a:40:17: error: 'CHARGE_AREA_START_X' was not declared in this scope

display.drawBox(CHARGE_AREA_START_X, CHARGE_AREA_START_Y, width, CHARGE_AREA_HEIGHT);

^

sketch_nov21a:61:18: error: 'CHARGE_AREA_START_X' was not declared in this scope

uint8_t offset = CHARGE_AREA_START_X;

^

C:\Users\Toon\Documents\Arduino\sketch_nov21a\sketch_nov21a.ino: At global scope:

sketch_nov21a:72:7: error: redefinition of 'float accuspanning'

float accuspanning = 0.0;

^

C:\Users\Toon\Documents\Arduino\sketch_nov21a\sketch_nov21a.ino:22:7: note: 'float accuspanning' previously defined here

float accuspanning = 0.0;

^

exit status 1
'battery_bitmap' was not declared in this scope

Dit rapport zou meer informatie bevatten met
"Uitgebreide uitvoer weergeven tijden compilatie"
optie aan in Bestand -> Voorkeuren.

hmmm, er is een stuk verdwenen, idd

code:


#include <U8g2lib.h>
 #include <U8x8lib.h>

 // This is the display object. You will change this line if you are using pins
 // other that 12, 11, 9 and 10.
 U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI display(U8G2_R0, 12, 11, U8X8_PIN_NONE, 9, 10);

 // This is the battery bitmap// This is the area inside the battery bitmap, in pixels
 static const PROGMEM unsigned char battery_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00,
0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
 #define CHARGE_AREA_START_X 20
 #define CHARGE_AREA_START_Y 18
 #define CHARGE_AREA_WIDTH 83
 #define CHARGE_AREA_HEIGHT 28

 // This is the battery fill mode
 // BATTERY_MODE_SOLID = 1 means the battery bitmap will be filled with
 // a solid rectangle according to the battery charge.
 // BATTERY_MODE_SOLID = 0 means the battery will be filled with a
 // rectangle subdivided in 3. If the battery level is 66% or more, it will
 // draw 3 rectangles. If it's 33% or more, it will draw 2 rectangles. It will
 // draw 1 rectagle if the battery is less than 33%.

 #define BATTERY_MODE_SOLID 1

 // This is the main function, and the one you will want to transplant to your
 // code. Pass the battery charge percent and it will draw the battery with
 // the corresponding charge level.
 void showBatteryLevel(uint8_t percent)
 {
uint8_t width;

if (percent > 100)
percent = 100;

display.clearBuffer();
display.drawXBMP(0, 0, 128, 64, battery_bitmap);

if (BATTERY_MODE_SOLID)
{
width = (percent * CHARGE_AREA_WIDTH) / 100;
display.drawBox(CHARGE_AREA_START_X, CHARGE_AREA_START_Y, width, CHARGE_AREA_HEIGHT);
} else {
uint8_t bars;

if (percent >= 66)
{
// Show three bars
bars = 3;
} else if (percent >= 33)
{
// Show two bars
bars = 2;
} else if (percent > 0)
{
// Show one bar
bars = 1;
} else {
// Show nothing
bars = 0;
}

uint8_t offset = CHARGE_AREA_START_X;
for (uint8_t i = 0; i < bars; i++)
{
display.drawBox(offset, CHARGE_AREA_START_Y, 27, CHARGE_AREA_HEIGHT);
offset += 28;
}
}

display.sendBuffer();
 }
float accuspanning = 0.0;
int accuvol = 135; //(volle accu 13,5V)
int acculeeg = 110; //(lege accu 11,0V)
int percentage;
 
void setup()
{
// Initialize the display object
display.begin();
pinMode(A0, INPUT); //neem ingang A0
}
 
void loop()
{
// Some test code to scan all the battery levels
// *3 is de spanningsdeler van de weerstanden
// *10 omdat de map niet met kommagetallen werkt. 13,5V => 135
accuspanning = ((analogRead(A0) * 5.0) / 1024.0 ) *3 *10;
 
percentage = map(accuspanning, accuvol, acculeeg, 100, 0);
if (percentage < 0) {  percentage = 0;}
if (percentage > 100) { percentage = 100;}
showBatteryLevel(percentage);
delay(200);
} 

heel raar, als ik die code in C zet, dan wordt heel die grote blok in het begin verwijderd ! probleem met de website hier dus.
en dat had jij in je eerste topic ook al. je allereerste keer dat je de code hier had gezet, was die grote blok met
"0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00"
ook verdwenen. vandaar dat er dus niks werkte

ik hou van werken ..., ik kan er uren naar kijken

capri

upload voltooid

geen accu geeft aan aangesloten; vol/leeg afwisselend

volle accu geeft aan; vol/leeg afwisselend 13.55v

lege accu geeft aan; vol/leeg afwisselend 0.88v

code:


#include <U8g2lib.h>
 #include <U8x8lib.h>

 // This is the display object. You will change this line if you are using pins
 // other that 12, 11, 9 and 10.
 U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI display(U8G2_R0, 12, 11, U8X8_PIN_NONE, 9, 10);

 // This is the battery bitmap// This is the area inside the battery bitmap, in pixels
 static const PROGMEM unsigned char battery_bitmap[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00,
0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
 #define CHARGE_AREA_START_X 20
 #define CHARGE_AREA_START_Y 18
 #define CHARGE_AREA_WIDTH 83
 #define CHARGE_AREA_HEIGHT 28

 // This is the battery fill mode
 // BATTERY_MODE_SOLID = 1 means the battery bitmap will be filled with
 // a solid rectangle according to the battery charge.
 // BATTERY_MODE_SOLID = 0 means the battery will be filled with a
 // rectangle subdivided in 3. If the battery level is 66% or more, it will
 // draw 3 rectangles. If it's 33% or more, it will draw 2 rectangles. It will
 // draw 1 rectagle if the battery is less than 33%.

 #define BATTERY_MODE_SOLID 1

 // This is the main function, and the one you will want to transplant to your
 // code. Pass the battery charge percent and it will draw the battery with
 // the corresponding charge level.
 void showBatteryLevel(uint8_t percent)
 {
uint8_t width;

if (percent > 100)
percent = 100;

display.clearBuffer();
display.drawXBMP(0, 0, 128, 64, battery_bitmap);

if (BATTERY_MODE_SOLID)
{
width = (percent * CHARGE_AREA_WIDTH) / 100;
display.drawBox(CHARGE_AREA_START_X, CHARGE_AREA_START_Y, width, CHARGE_AREA_HEIGHT);
} else {
uint8_t bars;

if (percent >= 66)
{
// Show three bars
bars = 3;
} else if (percent >= 33)
{
// Show two bars
bars = 2;
} else if (percent > 0)
{
// Show one bar
bars = 1;
} else {
// Show nothing
bars = 0;
}

uint8_t offset = CHARGE_AREA_START_X;
for (uint8_t i = 0; i < bars; i++)
{
display.drawBox(offset, CHARGE_AREA_START_Y, 27, CHARGE_AREA_HEIGHT);
offset += 28;
}
}

display.sendBuffer();
 }
float accuspanning = 0.0;
int accuvol = 135; //(volle accu 13,5V)
int acculeeg = 110; //(lege accu 11,0V)
int percentage;
 
void setup()
{
// Initialize the display object
display.begin();
Serial.begin(9600);
pinMode(A0, INPUT); //neem ingang A0
}
 
void loop()
{
// Some test code to scan all the battery levels
// *3 is de spanningsdeler van de weerstanden
// *10 omdat de map niet met kommagetallen werkt. 13,5V => 135
accuspanning = ((analogRead(A0) * 5.0) / 1024.0 ) *3 *10;
 
percentage = map(accuspanning, accuvol, acculeeg, 100, 0);
if (percentage < 0) {  percentage = 0;}
if (percentage > 100) { percentage = 100;}
showBatteryLevel(percentage);

Serial.print("*****************");
 Serial.print("analogread: ");
 Serial.println(analogRead(A0));
 Serial.print("accuspanning: ");
 Serial.println(accuspanning);
 Serial.print("percentage: ");
 Serial.println(percentage);
delay(1000);
} 

steek deze erin, ga dan bij tools, en iets van serial monitor (of CTRL+SHIFT+M eens de arduino draait).
dan zou je een kader op de pc moeten krijgen die een heleboel regels geeft.
je kan dan zien wat die meet

ik hou van werken ..., ik kan er uren naar kijken

capri

heb ik gedaan

accuspanning 149.85
percentage 1oo
analoogread 820

of
accuspanning 0.00
percentage 0
analoogread 562

dit wisseld steeds ook met andere waardes

capri
wanneer geen accu aangesloten

komen dezelfde waarden afwisselend

en wat meet je met een multimeter op die A0 pin als dit gebeurt?
probeer anders eens A1 ofzo en veranderd in de code de A0 naar A1.

maak misschien eens een foto van je arduino met aansluiting

[Bericht gewijzigd door fcapri op woensdag 21 november 2018 11:31:52 (20%)

ik hou van werken ..., ik kan er uren naar kijken

Als analogread onbetrouwbaare resultaten geeft, kan je fcapri z'n suggestie volgen en met de hand eens meten of er iets elektrisch aan de hand is of dat je misschien in de code iets raars hebt.

Maar als dat nog geen duidelijkheid heeft zou ik een 5k potmeter tussen 5V en 0V zetten en even zelf een slinger geven en kijken of de gemeten waarde met de multimeter overeenkomt met wat je analogRead zegt.

four NANDS do make a NOR . Kijk ook eens in onze shop: http://www.bitwizard.nl/shop/

Dan zou je nominaal zo'n "2" uit de ADC moeten krijgen. Met wat ruis iets tussen de 0 en de 5.

Als je iets in de 500 krijgt, dan
* staat de ADC verkeerd ingesteld
* ben je op een andere pen aan het meten.
* is je chip kapot.

1) Met arduino software is het makkelijk om het goed te doen. Ik zou denken van niet.
2) zou kunnen.
3) Is onwaarschijnlijk.

four NANDS do make a NOR . Kijk ook eens in onze shop: http://www.bitwizard.nl/shop/

goedemorgen capri,

gemeten op A0 met volle accu 12V 0.03V
gemeten op A0 met lege accu 2.4V 1.09V

lijkt voor mij nu goed te functioneren, na beter controle was er toch 'n massa verbinding die geen goed contact maakte

Nogmaals bedankt voor alle moeite

zie foto's

goed dat het nu werkt, al zie ik een typefout in je laatste reply. met 12V eraan meet je 0,03V???

en nu belangrijk, wat komt erop als je accu 50% is, en effectief leeg?
11 en 10V bv

[Bericht gewijzigd door fcapri op zaterdag 24 november 2018 17:35:13 (31%)

ik hou van werken ..., ik kan er uren naar kijken

capri

nu gemeten 5.62V volle accu

zal mijn accu nu ontladen en dan opnieuw meten

gr

accu bijna volledig ontladen 12,47 V unverseel meting onbelast

lampje 12v brand nog maar net

meetwaarde Ao -GND nog steeds 5.62 V

indicatie vol

te vroeg gejuicht

wat kan volgens u de oorzaak zijn

sketch niet gewijzigd

monitor uitslag

analoogread 1023
accuspanning 149.85
percentage 100

probleem is dat je van in het begin te extreme stappen hebt genomen

gemeten op A0 met volle accu 12V 0.03V
gemeten op A0 met lege accu 2.4V 1.09V

jouw accu met leeg zal NOOIT 2,4V zijn, dan is ze kapot.
je had betere waardes moeten nemen.
bv accu vol = 13,5V en accu leeg = 11V (wat zijn trouwens uw waardes voor VOL en LEEG???)

ook moet je je afvragen: meet de arduino correct tov de volle accu?
dwz: als de accu 12,5V is, moet die in serialmonitor 125 weergeven.
als deze echter 110 aangeeft bij een 12,5V accu, moet je de formule nog iets aanpassen.
dit heeft namelijk 2 redenen:
1) de 5V usb spanning is niet precies 5V. dit kan 4,95zijn, maar evengoed 5,05. in de formule werkt je met 5.0 en dit geeft al een meetfout
2) jouw weerstanden hebben een tolerantie. een 10K kan evengoed 9K of 11K zijn. dit zal je spanningsdeling ook beinvloeden.
beste dat je kan doen is uitrekenen wat de afwijking is, en dat nog in de formule aanpassen.
BV als de arduino 115 aangeeft bij 12V, dan maak je de formule:
accuspanning = ((analogRead(A0) * 5.0) / 1024.0 ) *3 *10 * 1,04
(hoop dat die een kommagetal aanvaard bij een integer).

of je vervangt de 20K weerstand door een potmeter van bv 50K en je regelt die bij tot de accuspanning correct op je pc scherm komt (handigere methode dat ik ook gebruik

stap2: er staan 2 regels in de code
volle accu:...
lege accu:...
je kan deze getallen ook aanpassen
stel dat je accu vol 15V is, maar de arduino geeft 143 aan. dan kan je er ook voor kiezen om stap 1 NIET te doen, maar de waarde int accuvol = 143; instellen.
hetzelfde doe je dan voor acculeeg (bv lege accu van 11V wordt in arduino gegeven als 108
int acculeeg = 108; //(lege accu 11,0V)

dit is nu het onderdeeltje 'calibreren'.

ik hou van werken ..., ik kan er uren naar kijken

die meting van 2 accu cellen was (2.4 v) leeg 1.09

dat was niet de 12V accu

zie beide foto's

1 met 12v accu, 1 met lege cellen

Moet nu eerst mijn 12V accu weer opladen

maar wat probeer je nu eigenlijk te meten?
je zit eerst met 12V cellen bezig (vol)
en daarna met 2 cellen (2,4V) leeg.
en dan ben je verwonderd dat je lege 12V accu ook nog steeds vol aanduidt.

die arduino werkt met 2 stappen.
13,5V als zijnde vol (100%)
en 11.0V als zijnde leeg (0%).

als jij er iets van 2V aan hangt, is dat leeg. hang je er 6V aan, is dat leeg. hang je er 10V aan, dan blijft dat display altijd leeg aangeven want het is minder dan 11V.

jij moet nu de correcte waardes ingeven bij accu_vol en accu_leeg zodat die met jouw 12V een correcte weergave doet. en ook rekening houden met de meetfout veroorzaakt door jouw weerstanden.
je hebt een spanningsdeler van 20K/10K.
bij 10% tolerantie mag die 20K varieren van 18 tot 22K.
en die 10K tussen 9 en 11K.
theoretisch: als jij exact 12.00V aanlegt, en je weerstanden zijn precies 20K en 10K, dan krijgt de arduino 4.00V aan zijn ingang.

Zijn je weerstanden 22K en 9K (uitersten), dan krijgt de arduino maar 3,48V en zal die dat vertalen naar een accu van 10,44V (zijnde LEEG)
Zijn je weerstanden 18 en 11K, dan krijgt je arduino 4,55V en zal die dat vertalen naar 13,65V (zijnde VOL) terwijl je nogthans 2keer dezelfde accuspanning hebt.
in praktijk ga je daar ergens tussenin zitten. je kan ook een weerstand vervangen door een potmeter en daaraan draaien zodat die de precieze accu meet.

bv: je hebt een accu met 12,47V en je arduino zegt 11,8V. dan moet je aan de potmeter draaien tot de arduino 12,47 op het display geeft

[Bericht gewijzigd door fcapri op dinsdag 27 november 2018 11:07:08 (11%)

ik hou van werken ..., ik kan er uren naar kijken