Skocz do zawartości

Podpowiedzcie co napisałem źle w programie - tester ogniw 18650


SebaSaper

Pomocna odpowiedź

jestem poczatkujacy z Arduino ostatnio zrobilem tester na jedno ogniwo 18650 .

Próboje go przerobić na więcej sztuk ( na 2 sztuki w przyszlości 10-15 ) lecz wywala mi błąd program pisze sam .

podpowiedzcie co jest żle bo nie wiem już sam siedzę od kilkunastu godzin ale nie potrafię tego ogarnąć .

daję caly kod oraz link to testera którym się inspirowalem

na koniec male pytanko  do wykonania używam arduino pro mini  na schemacie w linku jedno ogniw wykorzystuje 2 porty ADC czy moŻna to jakiś obejŚĆ aby wykozystywaŁo 1 port bo jeŚli tak to bym przerobił nie na 2 sztuki a na 4

https://arduinowpraktyce.blogspot.com/2018/02/tester-pojemnosci-i-rezystancji.html

#define gatePin1 12

#define highPin1 A1

#define lowPin1 A0


#define gatePin2 13

#define highPin2 A2

#define lowPin2 A3

#include <Wire.h>

#include <TimerOne.h>

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

boolean finished1 = false;

boolean finished2 = false;

int printStart = 0;
int interval = 5000;

float shuntRes = 8.2;
float voltRef = 5.00;

float mAh1 = 0;
int poj1 = 0;
float current1 = 0.0;
float battStart1 = 0.0;
float battVolt1 = 0.0;
float shuntVolt1 = 0.0;
float battLow1 = 2.7;
float rezwew1 = 0;
float roznica1 = 0;
float suma1 = 0;

float mAh2 = 0;
int poj2 = 0;
float current2 = 0.0;
float battStart2 = 0.0;
float battVolt2 = 0.0;
float shuntVolt2 = 0.0;
float battLow2 = 2.7;
float rezwew2 = 0;
float roznica2 = 0;
float suma2 = 0;

int pomiar1 = 0;
int pomiar2 = 0;

  float Time0=0;
  float Time1=0;
  
unsigned long previousMillis = 0;
unsigned long millisPassed = 0;

void setup() {

lcd.init();
lcd.init();
lcd.backlight();  
pinMode(gatePin1, OUTPUT);
digitalWrite(gatePin1, LOW);
lcd.home();
lcd.print("Test ogniwa");
lcd.setCursor(0,1);
lcd.print("Prosze czekac");
delay(3000);
battStart1 = analogRead(highPin1) * voltRef / 1024.0;


lcd.init();
lcd.init();
lcd.backlight();  
pinMode(gatePin2, OUTPUT);
digitalWrite(gatePin2, LOW);
lcd.home();
lcd.print("Test ogniwa");
lcd.setCursor(0,1);
lcd.print("Prosze czekac");
delay(2000);
battStart2 = analogRead(highPin2) * voltRef / 1024.0;
delay(3000);

void loop()
 
  
battVolt1 = analogRead(highPin1) * voltRef / 1024.0;
shuntVolt1 = analogRead(lowPin1) * voltRef / 1024.0;
if(battVolt1 >= battLow1 && finished1 == false);

}

{
 digitalWrite(gatePin1, HIGH);
 millisPassed = millis() - previousMillis;
 current1 = (battVolt1 - shuntVolt1) / shuntRes;
 mAh1 = mAh1 + (current1 * 1000.0) * (millisPassed / 3600000.0);

 previousMillis = millis();
 if(pomiar1 > 0 && pomiar1 < 5)
{
(suma1=suma1+battVolt1); 
}
if(pomiar1  == 6)
{
suma1=suma1/4;
roznica1 = battStart1/suma1;
rezwew1 = (roznica1 - 1)*4.9; // Oblicza rez. wew.
}

battVolt2 = analogRead(highPin2) * voltRef / 1024.0;
shuntVolt2 = analogRead(lowPin2) * voltRef / 1024.0;
if(battVolt2 >= battLow2 && finished2 == false);
{
digitalWrite(gatePin2, HIGH);
millisPassed = millis() - previousMillis;
current2 = (battVolt2 - shuntVolt2) / shuntRes;
mAh2 = mAh2 + (current2 * 1000.0) * (millisPassed / 3600000.0);

previousMillis = millis();
if(pomiar2 > 0 && pomiar2 < 5)
{
(suma2=suma2+battVolt2); 
}
if(pomiar2  == 6)
{
suma2=suma2/4;
roznica2 = battStart2/suma2;
rezwew2 = (roznica2 - 1)*4.9; // Oblicza rez. wew.
}


lcd.clear();
lcd.home();
lcd.print("U:");
lcd.print(battVolt1);
lcd.print("V");
lcd.setCursor(9,0);
lcd.print("I:");
lcd.print(current1);
lcd.print("A");
lcd.setCursor(0,1);
poj1=mAh1;
lcd.print(poj1);
lcd.print("mAh");
if(pomiar1 > 6)
{
lcd.setCursor(9,1);
lcd.print("Rw:");
lcd.print(rezwew1);
}
pomiar1++;
delay(interval);
}
if(battVolt1 < battLow1) // Rozłącza obciążenie i wyświetla wyniki
{
digitalWrite(gatePin1, LOW);

finished1 = true;

lcd.clear();
lcd.home();
lcd.print("Koniec1");
lcd.setCursor(0,1);
poj1=mAh1;
lcd.print(poj1);
lcd.print("mAh ");
lcd.setCursor(9,1);
lcd.print("Rw:");
lcd.print(rezwew1);

delay(interval * 2);




lcd.clear();
lcd.home();
lcd.print("U:");
lcd.print(battVolt2);
lcd.print("V");
lcd.setCursor(9,0);
lcd.print("I:");
lcd.print(current2);
lcd.print("A");
lcd.setCursor(0,1);
poj2=mAh2;
lcd.print(poj2);
lcd.print("mAh");
if(pomiar2 > 6)
{
lcd.setCursor(9,1);
lcd.print("Rw:");
lcd.print(rezwew2);
}
pomiar2++;
delay(interval);
}
if(battVolt2 < battLow2) // Rozłącza obciążenie i wyświetla wyniki
{
digitalWrite(gatePin2, LOW);

finished2 = true;

lcd.clear();
lcd.home();
lcd.print("Koniec2");
lcd.setCursor(0,1);
poj2=mAh2;
lcd.print(poj2);
lcd.print("mAh ");
lcd.setCursor(9,1);
lcd.print("Rw:");
lcd.print(rezwew2);

delay(interval * 2);



}

}




}

}

 

Link do komentarza
Share on other sites

@SebaSaper popracuj trochę nad estetyką programu - wcięcia i odpowiednie formatowanie to podstawa, bo to Cie w tej chwili gubi. Zobacz przykładowo na poniższy fragment:

void loop()
 
  
battVolt1 = analogRead(highPin1) * voltRef / 1024.0;
shuntVolt1 = analogRead(lowPin1) * voltRef / 1024.0;
if(battVolt1 >= battLow1 && finished1 == false);

}

{

Coś tu na pewno jest źle z tymi nawiasami, do tego 3 linijki wstrzeliłeś w kompletnie złe miejsce (miedzy nazwę funkcji, a przed nawias otwierający blok kodu). Po drugie, czy na pewno ten if miał się kończyć średnikiem? Gdybyś pilnował formatowania to takich błędów by nie było 😉

  • Pomogłeś! 1
Link do komentarza
Share on other sites

Zarejestruj się lub zaloguj, aby ukryć tę reklamę.
Zarejestruj się lub zaloguj, aby ukryć tę reklamę.

jlcpcb.jpg

jlcpcb.jpg

Produkcja i montaż PCB - wybierz sprawdzone PCBWay!
   • Darmowe płytki dla studentów i projektów non-profit
   • Tylko 5$ za 10 prototypów PCB w 24 godziny
   • Usługa projektowania PCB na zlecenie
   • Montaż PCB od 30$ + bezpłatna dostawa i szablony
   • Darmowe narzędzie do podglądu plików Gerber
Zobacz również » Film z fabryki PCBWay

Arduino:1.8.3 (Windows XP), Płytka:"Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"

D:\Arduino\arduino-builder -dump-prefs -logger=machine -hardware D:\Arduino\hardware -tools D:\Arduino\tools-builder -tools D:\Arduino\hardware\tools\avr -built-in-libraries D:\Arduino\libraries -libraries C:\Documents and Settings\User\Moje dokumenty\libraries -fqbn=arduino:avr:pro:cpu=16MHzatmega328 -vid-pid=0X2341_0X0043 -ide-version=10803 -build-path C:\DOCUME~1\User\USTAWI~1\Temp\arduino_build_807027 -warnings=none -build-cache C:\DOCUME~1\User\USTAWI~1\Temp\arduino_cache_674854 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=D:\Arduino\hardware\tools\avr -verbose C:\Documents and Settings\User\Moje dokumenty\TESTER_18650\TESTER_18650.ino
D:\Arduino\arduino-builder -compile -logger=machine -hardware D:\Arduino\hardware -tools D:\Arduino\tools-builder -tools D:\Arduino\hardware\tools\avr -built-in-libraries D:\Arduino\libraries -libraries C:\Documents and Settings\User\Moje dokumenty\libraries -fqbn=arduino:avr:pro:cpu=16MHzatmega328 -vid-pid=0X2341_0X0043 -ide-version=10803 -build-path C:\DOCUME~1\User\USTAWI~1\Temp\arduino_build_807027 -warnings=none -build-cache C:\DOCUME~1\User\USTAWI~1\Temp\arduino_cache_674854 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=D:\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=D:\Arduino\hardware\tools\avr -verbose C:\Documents and Settings\User\Moje dokumenty\TESTER_18650\TESTER_18650.ino
Using board 'pro' from platform in folder: D:\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: D:\Arduino\hardware\arduino\avr
Detecting libraries used...
"D:\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR   "-ID:\Arduino\hardware\arduino\avr\cores\arduino" "-ID:\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "C:\DOCUME~1\User\USTAWI~1\Temp\arduino_build_807027\sketch\TESTER_18650.ino.cpp" -o "nul"
"D:\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR   "-ID:\Arduino\hardware\arduino\avr\cores\arduino" "-ID:\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-ID:\Arduino\hardware\arduino\avr\libraries\Wire\src" "C:\DOCUME~1\User\USTAWI~1\Temp\arduino_build_807027\sketch\TESTER_18650.ino.cpp" -o "nul"
"D:\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR   "-ID:\Arduino\hardware\arduino\avr\cores\arduino" "-ID:\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-ID:\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\TimerOne" "C:\DOCUME~1\User\USTAWI~1\Temp\arduino_build_807027\sketch\TESTER_18650.ino.cpp" -o "nul"
"D:\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR   "-ID:\Arduino\hardware\arduino\avr\cores\arduino" "-ID:\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-ID:\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\TimerOne" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\LiquidCrystal_I2C-1.1.2" "C:\DOCUME~1\User\USTAWI~1\Temp\arduino_build_807027\sketch\TESTER_18650.ino.cpp" -o "nul"
"D:\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR   "-ID:\Arduino\hardware\arduino\avr\cores\arduino" "-ID:\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-ID:\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\TimerOne" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\LiquidCrystal_I2C-1.1.2" "D:\Arduino\hardware\arduino\avr\libraries\Wire\src\Wire.cpp" -o "nul"
"D:\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR   "-ID:\Arduino\hardware\arduino\avr\cores\arduino" "-ID:\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-ID:\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\TimerOne" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\LiquidCrystal_I2C-1.1.2" "D:\Arduino\hardware\arduino\avr\libraries\Wire\src\utility\twi.c" -o "nul"
"D:\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR   "-ID:\Arduino\hardware\arduino\avr\cores\arduino" "-ID:\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-ID:\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\TimerOne" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\LiquidCrystal_I2C-1.1.2" "C:\Documents and Settings\User\Moje dokumenty\libraries\TimerOne\TimerOne.cpp" -o "nul"
"D:\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR   "-ID:\Arduino\hardware\arduino\avr\cores\arduino" "-ID:\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-ID:\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\TimerOne" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\LiquidCrystal_I2C-1.1.2" "C:\Documents and Settings\User\Moje dokumenty\libraries\LiquidCrystal_I2C-1.1.2\LiquidCrystal_I2C.cpp" -o "nul"
Generating function prototypes...
"D:\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR   "-ID:\Arduino\hardware\arduino\avr\cores\arduino" "-ID:\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-ID:\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\TimerOne" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\LiquidCrystal_I2C-1.1.2" "C:\DOCUME~1\User\USTAWI~1\Temp\arduino_build_807027\sketch\TESTER_18650.ino.cpp" -o "C:\DOCUME~1\User\USTAWI~1\Temp\arduino_build_807027\preproc\ctags_target_for_gcc_minus_e.cpp"
"D:\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\DOCUME~1\User\USTAWI~1\Temp\arduino_build_807027\preproc\ctags_target_for_gcc_minus_e.cpp"
Kompilowanie szkicu...
"D:\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10803 -DARDUINO_AVR_PRO -DARDUINO_ARCH_AVR   "-ID:\Arduino\hardware\arduino\avr\cores\arduino" "-ID:\Arduino\hardware\arduino\avr\variants\eightanaloginputs" "-ID:\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\TimerOne" "-IC:\Documents and Settings\User\Moje dokumenty\libraries\LiquidCrystal_I2C-1.1.2" "C:\DOCUME~1\User\USTAWI~1\Temp\arduino_build_807027\sketch\TESTER_18650.ino.cpp" -o "C:\DOCUME~1\User\USTAWI~1\Temp\arduino_build_807027\sketch\TESTER_18650.ino.cpp.o"
C:\Documents and Settings\User\Moje dokumenty\TESTER_18650\TESTER_18650.ino: In function 'void setup()':

TESTER_18650:93: error: expected initializer before 'battVolt1'

 battVolt1 = analogRead(highPin1) * voltRef / 1024.0;

 ^

C:\Documents and Settings\User\Moje dokumenty\TESTER_18650\TESTER_18650.ino: At global scope:

TESTER_18650:99: error: expected unqualified-id before '{' token

 {

 ^

Użycie biblioteki Wire w wersji 1.0 z folderu: D:\Arduino\hardware\arduino\avr\libraries\Wire 
Użycie biblioteki TimerOne w wersji 1.1 z folderu: C:\Documents and Settings\User\Moje dokumenty\libraries\TimerOne 
Użycie biblioteki LiquidCrystal_I2C-1.1.2 w wersji 1.1.2 z folderu: C:\Documents and Settings\User\Moje dokumenty\libraries\LiquidCrystal_I2C-1.1.2 
exit status 1
expected initializer before 'battVolt1'

Dorzuczm opis błędu

Dziękuje za podpowiedż.

mam jeszcze tylko male pytanko można jakoś obejsc to że arduino zużywa 2 piny ADC na jedno ogniwo aby na ogniwo był tylko 1 pin czy nie można tak , przepraszam za pytanie ale jeszcze nie ogarniam wszystkiego.

Link do komentarza
Share on other sites

Dołącz do dyskusji, napisz odpowiedź!

Jeśli masz już konto to zaloguj się teraz, aby opublikować wiadomość jako Ty. Możesz też napisać teraz i zarejestrować się później.
Uwaga: wgrywanie zdjęć i załączników dostępne jest po zalogowaniu!

Anonim
Dołącz do dyskusji! Kliknij i zacznij pisać...

×   Wklejony jako tekst z formatowaniem.   Przywróć formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Twój link będzie automatycznie osadzony.   Wyświetlać jako link

×   Twoja poprzednia zawartość została przywrócona.   Wyczyść edytor

×   Nie możesz wkleić zdjęć bezpośrednio. Prześlij lub wstaw obrazy z adresu URL.

×
×
  • Utwórz nowe...

Ważne informacje

Ta strona używa ciasteczek (cookies), dzięki którym może działać lepiej. Więcej na ten temat znajdziesz w Polityce Prywatności.