Battery indicator

fcapri

sorry, had inderdaad ook met 'n andere accu gemeten

maar zoals u nu uitlegt gaat dat niet en zijn de instellingen alleen voor mijn 12V accu

de gebruikt weerstanden zijn;

21.4k
en
9.8k

je kan de arduino maar instellen voor 1 accu.
je zou eventueel wel een 2de accu op een andere ingang kunnen steken, en daar een 2de meting mee doen. met een schakelaar zou je kan kunnen kiezen welke accu op het display komt (of het display aanpassen zodat die 2 accu's weer geeft).

2de optie is gewoon je weerstanden aanpassen.
dat je bv 22 en 10K gebruikt op 12V en lagere weerstanden voor kleinere accu's.

stel dat je een 12V accu wil kunnen meten (11-13.5V) en een 2,4V accu (2.0 -> 2.7V).
dan kan je u arduino op de interne referentie laten werken (1.1V ipv 5V) en maak je een spanningsdeler van 1/3 (10K en 20K) voor de 2.4V accu. de arduino zal dan 0.666 tot 0.9V meten van leeg tot vol.

als je dan een weerstandsdeler maakt van 1/15 (10K en 140K), dan zal je 12V accu van 0.7333 tot 0.9V werken en kan je beide accu's meten met dezelfde arduino en hoef je enkel een andere weerstand aan te sluiten (schakelaartje met 2 schakelaars bv)

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

fcapri

dat is niet nodig ik gebruik alleen de 12v accu

Omdat ik dacht dat ik dat meerdere accu's kon gebruiken tijdens het testen, zodat ik de 12v niet hoefde te ontladen

'n vraag als de 12v accu leeg is werkt dan het display nog ?
Zo niet an zou ik toch nog 'n tweede spanningsbron nodig hebben Bv 3 knoopcellen

Het display/arduino krijgen de voeding nu uit dezelfde accu 12V

die arduino zal nog werken tot ongeveer 4V. als de 12V accu zo leeg is dat ze onder de 4V komt, mag je ze weggooien, dan is ze kapot

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

fcapri

toch weer even tijd

test opstelling meting

21.4k
weerstanden
9.8k

usb spanning 4.60V
accuspanning 12.5V

monitor

geeft aan;

analoog read wisseld tussen 854 ↔ 860
percentage 60%
display indicatie ± 60%
spanning Ao - gnd 3.84V

hoe pas ik dan die formule aan; *5.0) / 1024.0)*3 *10 * 1.04

na 'n tijdje pm 5min

geeft het display ± 15% aan en dan weer 60%

blijft nu wisselen tussen ± 50% en 60%

ben een beetje ziek nu, dus nadenken over code lukt niet.
het lijkt me dat de metingen een beetje instabiel zijn en daardoor wat variatie veroorzaken.
beste kan je misschien 10metingen doen, en daar dan een gemiddelde uit trekken zodat het stabieler is

je moet iets maken met:
accuspanning = ((analogRead(A0) * 5.0) / 1024.0 ) *3 *10;
for (int i = 0, i< 10, i++){
accuspanning = accuspanning + ((analogRead(A0) * 5.0) / 1024.0 ) *3 *10;
delay(100);
}
accuspanning = accuspanning / 10;

in de eerste regel ga je de spanning meten.
daarna ga je nog 9keer die spanning bij de volgende meting optellen.
na de for lus, ga je de spanning delen door 10.

dus als je 4.6V meet, daarna 4.5, daarna 4.6, daarna 4.8, daarna 4.6, daarna 4.7, daarna 4.6, daarna 4.5, daarna 4.6, daarna 4.6.
en je deelt op het einde door 10, ga je iets van 4,61V over houden en het zal een stuk stabieler worden

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

fcapri
ik wens u beterschap

probeer uit u uitleg te komen

want ik begrijp het nog niet echt

Gr

Een aardige manier om te filteren van signalen waar wat "ruis" op zit is om voor zeg 90% het "lopende gemiddelde" en voor 10% de nieuwe waarde mee te nemen. Je neemt dan niet letterlijk het gemiddelde over de laatste tien metingen maar wel ongeveer. De laatste meting telt voor 10% mee, die daarvoor voor 10% * 0.91, die daarvoor voor 10% * 0.92 enz.

De code is:

code:

  huidigewaarde = 0.9 * huidigewaarde + 0.1 * nieuwemeting; 

Als je dan die 0.9 in een variabele zet, krijg je:

code:

  bewaarfactor = 0.9; 
  huidigewaarde = bewaarfactor * huidigewaarde + (1-bewaarfactor) * nieuwemeting; 

Dan kan je de bewaarfactor makkelijk wijzigen om te zien wat verschillende waardes doen.

Volgens mij probeert fcapri zoiets te doen. fcapri doet iets anders: Hij telt gewoon echt 10 11 metingen bij mekaar op en deelt door tien.

Ik zou het anders schrijven. Deels omdat het efficienter is, maar vooral omdat het m.i. makkelijker te lezen is.

code:

for (i=0, analogtot=0;i<numsamples;i++) {
  analogtot += analogRead (A0);
}
accuspanning = ((float)analogtot / numsamples) / 1024 * 5.0 .... ;

Bij de .... heeft fcapri *3*10 staan. Die snap ik niet. Ik zou een * 11 verwachten als je een 11:1 spanningsdeler gebruikt (ik weet het uit m'n hoofd even niet).

In fcrapri z'n code duurt een meting 1s. Ik zie meer nut in zeg 1000 keer meten en delen door duizend dan totaal 1000 ms wachten.

fcapri z'n code bevat volgens mij een bug: Hij telt 11 metingen bij mekaar op en deelt door tien.

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

????? rew

kunt u dat duidelijker omschrijven voor 'n 77 jarige
en eventueel samen met fcapri 'n programma maken dat voor 99 procent goed werkt

exacte waarde is voor mij niet zo belangrijk wel wanneer moet ik mijn accu laden

alvast bedankt

Gr

idd, foutje, had i=1 moeten doen ipv i=0. altijd verwarrend als 0 ook al als loop telt.

die *3*10 heeft een andere betekenis
de *3 is van de spanningsdeler (20K/10K) en de *10 is om geen kommagetal te hebben. blijkbaar kan de map functie enkel overweg met integers, daarom dat ik de low en high waardes van de accu op 110 en 135 heb gezet (11,0 en 13,5V)

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

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

sketch_nov21c:179:1: error: 'percentage' does not name a type

percentage = map(accuspanning, accuvol, acculeeg, 100, 0);

^

sketch_nov21c:180:1: error: expected unqualified-id before 'if'

if (percentage < 0) { percentage = 0;}

^

sketch_nov21c:181:1: error: expected unqualified-id before 'if'

if (percentage > 100) { percentage = 100;}

^

sketch_nov21c:182:17: error: expected constructor, destructor, or type conversion before '(' token

showBatteryLevel(percentage);

^

sketch_nov21c:184:1: error: 'Serial' does not name a type

Serial.print("*****************");

^

sketch_nov21c:185:2: error: 'Serial' does not name a type

Serial.print("analogread: ");

^

sketch_nov21c:186:2: error: 'Serial' does not name a type

Serial.println(analogRead(A0));

^

sketch_nov21c:187:2: error: 'Serial' does not name a type

Serial.print("accuspanning: ");

^

sketch_nov21c:188:2: error: 'Serial' does not name a type

Serial.println(accuspanning);

^

sketch_nov21c:189:2: error: 'Serial' does not name a type

Serial.print("percentage: ");

^

sketch_nov21c:190:2: error: 'Serial' does not name a type

Serial.println(percentage);

^

sketch_nov21c:191:6: error: expected constructor, destructor, or type conversion before '(' token

delay(1000);

^

sketch_nov21c:192:1: error: expected declaration before '}' token

}

^

exit status 1
'percentage' does not name a type

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

Krijg na vervangen van i=0 naar i=1 error

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 = 1; 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);
}

Nogmaals de complete scetch

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);
}

deze doorstreepte } sluit je loop af, dus alles wat volgde zit buiten je programma

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

heb er vermoedelijk fouten in gemaakt

sketch functioneerd weer

in het display wisseld nog steeds van 50% naar 60%

accuspanning nu 12.04V
A0 - GND nu 3,79V (stabiel)

wanneer ik er 'n externe voeding opzet 5V

A0 -GND 3.79V stabiel

display weergave 10% a 15% (stabiel)

monitor

accuspanning 122.46
percentage 48
analogread 836

heb geprobeerd 1000 te veranderen in

eerst 10000
daarna 100000

meer stabiel display ( wisseling 40sec )

is dat 'n probleem?

[Bericht gewijzigd door a.j nieuwlaat op zondag 9 december 2018 14:24:02 (19%)

fcapri,
al een beetje beter?

ik denk dat de sketch nu naar behoren functioneert

bedankt voor alle moeite

Gr

Goedemorgen fcapri,

sorry dat ik u weer moet lastig vallen

Met de sketch voor die Batterij indicator heb ik toch weer 'n probleem

Hoop dat u mij wil/kan helpen

#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
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 };

// This is the area inside the battery bitmap, in pixels
#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();
}

void setup()
{
// Initialize the display object
display.begin();
}

// A variable to test our code.
uint8_t percent = 100;

void loop()
{
// Some test code to scan all the battery levels
showBatteryLevel(percent);

#include "U8glib.h" // U8glib library for the OLED

int analogInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K)
float R2 = 10000.0; // resistance of R2 (10K)
int value = 0;

U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9, 8); // D0=13, D1=11, CS=10, DC=9, Reset=8

void draw(void)
{
}
void setup(){
pinMode(analogInput, INPUT);
}
void loop(){
// read the value at analog input
value = analogRead(analogInput);
vout = (value * 5.0) / 1024.0; // see text
vin = vout / (R2/(R1+R2));
if (vin<0.09) {
vin=0.0;//statement to quash undesired reading !
}
u8g.firstPage();
do
{
draw();
}
while( u8g.nextPage() );
delay(500);
}
else
percent = 100;

delay(50);
}

geeft hierna 'n fout melding

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

In file included from C:\Users\Toon\Documents\Arduino\libraries\U8glib\src/U8glib.h:42:0,

from C:\Users\Toon\Documents\Battery_Indicator\Battery_Indicator.ino:175:

C:\Users\Toon\Documents\Arduino\libraries\U8glib\src/clib/u8g.h: In function 'void loop()':

C:\Users\Toon\Documents\Arduino\libraries\U8glib\src/clib/u8g.h:70:8: error: expected unqualified-id before string constant

extern "C" {

^

Battery_Indicator:213:1: error: expected '}' at end of input

'}'

^

exit status 1
expected '}' at end of input

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

met vriendelijke groet
A.J Nieuwlaat

Sorry fcapri

had 'n oudere versie van de sketch

bij de goede sketch word er nu aangegeven te weinig geheugen
kan die sketch ingekort worden om te uploaden naar 'n Arduino Nano

Met vriendelijke groet

A.J Nieuwlaat

Hoeveel geheugen gebruikt ie dan? Volgens mij zit er 32k in een 'nano. (in ieder geval in de mijne die ik heb).

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

fcapri,

was nu zover om de sketch in de Nano te uploaden, welke ik nu gemonteerd heb in mijn model truck,en krijg nu elke keer 'n fout melding. Vorige was op 'n bread board als test, ook met 'n Nano maar die is met pinnen en ik gebruik in mijn truck, een zonder pinnen om rechtstreeks te bedraden.

Zou u zo vriendelijk willen zijn om de sketch te controleren en eventueel in te korten omdat ik ook al 'n melding heb gekregen te weinig geheugen.

met vriendelijke groet

sorry ik kom er niet uit

#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 = 1; 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);
}

hierna foutmelding

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

In file included from C:\Users\Toon\Documents\Arduino\libraries\U8glib\src/U8glib.h:42:0,

from C:\Users\Toon\Documents\Battery_Indicator\Battery_Indicator.ino:175:

C:\Users\Toon\Documents\Arduino\libraries\U8glib\src/clib/u8g.h: In function 'void loop()':

C:\Users\Toon\Documents\Arduino\libraries\U8glib\src/clib/u8g.h:70:8: error: expected unqualified-id before string constant

extern "C" {

^

Battery_Indicator:213:1: error: expected '}' at end of input

'}'

^

exit status 1
expected '}' at end of input

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

Rew

Mag ik 'n beroep op jou doen om in de sketch Battery indicator gemaakt door Capri, ( waar ik niets mee van hoor )

wanneer ik de sketch in mijn modeltruck upload krijg ik 'n error

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

C:\Users\Toon\Documents\Arduino\Battery_indicator_07-03-2019\Battery_indicator_07-03-2019.ino: In function 'void showBatteryLevel(uint8_t)':

Battery_indicator_07-03-2019:154:1: error: expected ';' at end of input

';'

^

Battery_indicator_07-03-2019:154:1: error: expected '}' at end of input

Battery_indicator_07-03-2019:154:1: error: expected '}' at end of input

Battery_indicator_07-03-2019:154:1: error: expected '}' at end of input

exit status 1
expected ';' at end of input

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

Met vriendelijke groet

Je programma lijkt afgekapt te zijn. De compiler geeft aan dat het bestand afgelopen is terwijl ie nog op z'n minst een puntcomma en drie accolades sluiten moest krijgen.

De kans dat dit het enige is wat er mist lijkt me klein. Maar in die hoek moet je het zoeken.

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

heb in opleiding gezeten, dus geen tijd voor internet. examens pas afgelopen sinds gisteren.

dit deel is fout, ik heb die #### gezet waar je loop eindigt, dus alle code erna ... tja, daar doet de compiler gek over.
ofwel moet je daar een nieuwe functie openen
void Doiets(){ ofwel moet al die code in u loop staan:

code:


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;

}   <=##################### hier sluit je de loop AF ####################
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);
}

zonder die regel, compiled het wel bij mij

code:


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);
}

[Bericht gewijzigd door fcapri op vrijdag 17 mei 2019 10:39:44 (25%)

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