Compare commits

...

10 Commits

Author SHA1 Message Date
Max
35678add82 Update 2020-10-04 22:35:53 +01:00
Max Hunt
eb918a9dcc Update 2020-01-17 20:21:39 +00:00
Max Hunt
cee719a36a Update 2020-01-17 20:18:02 +00:00
Max Hunt
f4cf5f4616 Update 2020-01-16 14:58:21 +00:00
Max Hunt
317bea64ff Update 2020-01-11 17:56:52 +00:00
Max Hunt
796e93fe60 Update 2020-01-11 17:55:15 +00:00
Max Hunt
ed783b4b23 Update 2020-01-04 01:12:32 +00:00
Max Hunt
088fa5da21 Update 2020-01-04 00:54:27 +00:00
Max Hunt
fae61b8b88 Update 2019-12-25 11:10:04 +00:00
Max Hunt
1ca988f3c9 Update 2019-12-22 12:19:25 +00:00
248 changed files with 2566 additions and 114 deletions

BIN
Code/bat-b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
Code/chd-b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
Code/chg-b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
Code/test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -7,7 +7,7 @@
#include "Arduino.h"
#include "LowPower.h"
#include <avr/wdt.h>
//#include <avr/wdt.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
@ -26,14 +26,6 @@
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int batteryPct = 0;
double battVoltage = 0.0;
static const double chargeModifier = -0.04;
static const double dischargeModifier = 0.04;
double voltageModifier = 0;
bool powerState = false;
bool screenOn = false;
bool charging_1 = false;
@ -122,13 +114,6 @@ static const int dimmerVals[] = {
};
void setup() {
delay(100);
wdt_enable(WDTO_8S);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(WHITE);
Wire.begin();
Serial.begin(9600);
pinMode(VBAT, INPUT);
pinMode(CSTAT1, INPUT);
pinMode(CSTAT2, INPUT);
@ -137,20 +122,30 @@ void setup() {
pinMode(CHGLED, OUTPUT);
pinMode(PWRBTN, INPUT_PULLUP);
pinMode(CHGBTN, INPUT_PULLUP);
digitalWrite(PWRLED, HIGH);
digitalWrite(CHGLED, HIGH);
delay(100);
// wdt_enable(WDTO_8S);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(WHITE);
Wire.begin();
Serial.begin(9600);
digitalWrite(FETCTRL, LOW);
battVoltage = GetVoltage();
resetScreen();
delay(200);
/*
FuelGauge.begin();
FuelGauge.reset(); //<== Might cause problems
FuelGauge.quickstart();
*/
digitalWrite(PWRLED, LOW);
digitalWrite(CHGLED, LOW);
}
void loop() {
delay(100);
wdt_reset();
delay(100);
delay(900);
Serial.println(getVoltage());
// wdt_reset();
checkPresses();
checkCharging();
safetyCheck();
@ -166,41 +161,6 @@ void loop() {
}
}
void getBatteryCharge(){
double voltage = GetVoltage();
if (voltage > 4.15){batteryPct = 100;}
else if (voltage > 4.11){batteryPct = 95;}
else if (voltage > 4.08){batteryPct = 90;}
else if (voltage > 4.02){batteryPct = 85;}
else if (voltage > 3.98){batteryPct = 80;}
else if (voltage > 3.95){batteryPct = 75;}
else if (voltage > 3.91){batteryPct = 70;}
else if (voltage > 3.87){batteryPct = 65;}
else if (voltage > 3.85){batteryPct = 60;}
else if (voltage > 3.83){batteryPct = 55;}
else if (voltage > 3.82){batteryPct = 50;}
else if (voltage > 3.80){batteryPct = 45;}
else if (voltage > 3.79){batteryPct = 40;}
else if (voltage > 3.77){batteryPct = 35;}
else if (voltage > 3.75){batteryPct = 30;}
else if (voltage > 3.73){batteryPct = 25;}
else if (voltage > 3.71){batteryPct = 20;}
else if (voltage > 3.69){batteryPct = 15;}
else if (voltage > 3.61){batteryPct = 10;}
else if (voltage > 3.40){
batteryPct = 0;
}
else if (voltage < 2){batteryPct = -1;}
}
void _getBatteryCharge(){
batteryPct = FuelGauge.percent();
}
void checkPresses(){
if (digitalRead(PWRBTN) == 0) {
if (powerState == true || screenState != 0) {
@ -257,7 +217,6 @@ void checkCharging(){
}
}
void turnOn() {
if(isSafe == true){
blinkLed(PWRLED);
@ -275,49 +234,32 @@ void turnOff() {
powerState = false;
}
void resetScreen() {
display.clearDisplay();
display.display();
screenOn = false;
}
void updateScreen() {
getBatteryCharge();
if (screenState == 1) {
updateDisplayPct();
}
else if (screenState == 2) {
updateDisplayVoltage();
}
}
void updateDisplayPct(){
display.clearDisplay();
display.drawBitmap(0, 0, battery_logo, 120, 32, 1);
display.setTextSize(2);
display.setCursor(35, 10);
display.setTextColor(0);
display.print(batteryPct);
display.println("%");
updateDispayHelper();
display.display();
screenOn = true;
}
void updateDisplayVoltage(){
void updateScreen(){
display.clearDisplay();
display.drawBitmap(0, 0, battery_logo, 120, 32, 1);
display.setTextSize(2);
display.setCursor(30, 10);
display.setTextColor(0);
display.print(GetVoltage());
display.println(" V");
if (screenState == 1){
display.print(getPct());
display.println("%");
}
else if (screenState == 2){
display.print(getVoltage());
display.println(" V");
}
updateDispayHelper();
display.display();
screenOn = true;
}
void updateDisplayChg(){
display.clearDisplay();
updateDispayHelper();
@ -326,43 +268,23 @@ void updateDisplayChg(){
}
void updateDispayHelper(){
if (charging_1 == true && batteryPct != 100) {display.drawBitmap(118, 0, charge_logo, 16, 14, 1); screenOn = true;}
else if (charging_2 == true && batteryPct != 100) {display.drawBitmap(118, 16, charge_logo, 16, 14, 1); screenOn = true;}
else if (charging_1 == true && batteryPct == 100) {display.drawBitmap(118, 0, charged_logo, 16, 14, 1); screenOn = true;}
else if (charging_2 == true && batteryPct == 100) {display.drawBitmap(118, 16, charged_logo, 16, 14, 1); screenOn = true;}
int batteryPct = getPct();
if (charging_1 == true && batteryPct < 100) {display.drawBitmap(118, 0, charge_logo, 16, 14, 1); screenOn = true;}
if (charging_2 == true && batteryPct < 100) {display.drawBitmap(118, 16, charge_logo, 16, 14, 1); screenOn = true;}
if (charging_1 == true && batteryPct > 99) {display.drawBitmap(118, 0, charged_logo, 16, 14, 1); screenOn = true;}
if (charging_2 == true && batteryPct > 99) {display.drawBitmap(118, 16, charged_logo, 16, 14, 1); screenOn = true;}
}
double GetVoltage(){
int totalSamples = 0;
double voltage = 0;
for (int q = 0; q < 10; q++) {
totalSamples = totalSamples + analogRead(VBAT);
delay(5);
}
voltage = (totalSamples / 10) * (5.00 / 1023.0);
if(charging_1 == true || charging_2 == true){voltageModifier = chargeModifier;}
else if(powerState == true){voltageModifier = dischargeModifier;}
else {voltageModifier = 0;}
voltage = voltage + voltageModifier;
if (voltage > (battVoltage-0.03) && voltage < (battVoltage+0.03)) {
return battVoltage;
}
else {
battVoltage = voltage;
return voltage;
}
double getVoltage(){
return (FuelGauge.voltage()/1000);
}
double _GetVoltage(){
return (FuelGauge.voltage());
int getPct(){
return (FuelGauge.percent());
}
void safetyCheck(){
double currentVoltage = 0;
currentVoltage = GetVoltage();
double currentVoltage = getVoltage();
if(currentVoltage > 3.40 ){ //|| currentVoltage < 1.00
isSafe = true;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

50
Code/vLogger.py Normal file
View File

@ -0,0 +1,50 @@
#!/usr/bin/python3
import serial
import syslog
from datetime import datetime
import time
import csv
import serial.tools.list_ports
while True:
myports = [tuple(p) for p in list(serial.tools.list_ports.comports())]
port1 = '/dev/ttyUSB0'
port2 = '/dev/ttyUSB1'
ports = [port1, port2]
collecting = False
for x in myports:
for port in ports:
if port in x:
try:
print("Trying port " + str(port))
ser = serial.Serial(port,9600,timeout=5)
print("Running on port: " + str(port))
collecting = True
except:
print("Failed to open " + str(port))
while collecting:
try:
ser.reset_input_buffer()
raw_msg = ser.readline()
msg = raw_msg.rstrip().decode('utf-8')
with open('test.csv', 'a+', newline='') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
if msg != "":
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
spamwriter.writerow([dt_string, msg])
if msg != "":
time.sleep(2)
except:
print("Error on port " + str(port)+ " ,terminating")
collecting = False
time.sleep(2)
print("Stopped.")
# caffeine.off()

View File

Before

Width:  |  Height:  |  Size: 293 KiB

After

Width:  |  Height:  |  Size: 293 KiB

Some files were not shown because too many files have changed in this diff Show More