Compare commits
10 Commits
23bf8f240a
...
35678add82
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35678add82 | ||
|
|
eb918a9dcc | ||
|
|
cee719a36a | ||
|
|
f4cf5f4616 | ||
|
|
317bea64ff | ||
|
|
796e93fe60 | ||
|
|
ed783b4b23 | ||
|
|
088fa5da21 | ||
|
|
fae61b8b88 | ||
|
|
1ca988f3c9 |
BIN
Code/bat-b.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
Code/chd-b.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
Code/chg-b.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
Code/test.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
@ -7,7 +7,7 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#include "LowPower.h"
|
#include "LowPower.h"
|
||||||
#include <avr/wdt.h>
|
//#include <avr/wdt.h>
|
||||||
|
|
||||||
#define SCREEN_WIDTH 128
|
#define SCREEN_WIDTH 128
|
||||||
#define SCREEN_HEIGHT 32
|
#define SCREEN_HEIGHT 32
|
||||||
@ -26,14 +26,6 @@
|
|||||||
|
|
||||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
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 powerState = false;
|
||||||
bool screenOn = false;
|
bool screenOn = false;
|
||||||
bool charging_1 = false;
|
bool charging_1 = false;
|
||||||
@ -122,13 +114,6 @@ static const int dimmerVals[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void setup() {
|
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(VBAT, INPUT);
|
||||||
pinMode(CSTAT1, INPUT);
|
pinMode(CSTAT1, INPUT);
|
||||||
pinMode(CSTAT2, INPUT);
|
pinMode(CSTAT2, INPUT);
|
||||||
@ -137,20 +122,30 @@ void setup() {
|
|||||||
pinMode(CHGLED, OUTPUT);
|
pinMode(CHGLED, OUTPUT);
|
||||||
pinMode(PWRBTN, INPUT_PULLUP);
|
pinMode(PWRBTN, INPUT_PULLUP);
|
||||||
pinMode(CHGBTN, 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);
|
digitalWrite(FETCTRL, LOW);
|
||||||
battVoltage = GetVoltage();
|
|
||||||
resetScreen();
|
resetScreen();
|
||||||
delay(200);
|
delay(200);
|
||||||
/*
|
|
||||||
FuelGauge.begin();
|
FuelGauge.begin();
|
||||||
FuelGauge.reset(); //<== Might cause problems
|
FuelGauge.reset(); //<== Might cause problems
|
||||||
FuelGauge.quickstart();
|
FuelGauge.quickstart();
|
||||||
*/
|
digitalWrite(PWRLED, LOW);
|
||||||
|
digitalWrite(CHGLED, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
delay(100);
|
delay(100);
|
||||||
wdt_reset();
|
delay(900);
|
||||||
|
Serial.println(getVoltage());
|
||||||
|
// wdt_reset();
|
||||||
checkPresses();
|
checkPresses();
|
||||||
checkCharging();
|
checkCharging();
|
||||||
safetyCheck();
|
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(){
|
void checkPresses(){
|
||||||
if (digitalRead(PWRBTN) == 0) {
|
if (digitalRead(PWRBTN) == 0) {
|
||||||
if (powerState == true || screenState != 0) {
|
if (powerState == true || screenState != 0) {
|
||||||
@ -257,7 +217,6 @@ void checkCharging(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void turnOn() {
|
void turnOn() {
|
||||||
if(isSafe == true){
|
if(isSafe == true){
|
||||||
blinkLed(PWRLED);
|
blinkLed(PWRLED);
|
||||||
@ -275,49 +234,32 @@ void turnOff() {
|
|||||||
powerState = false;
|
powerState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void resetScreen() {
|
void resetScreen() {
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.display();
|
display.display();
|
||||||
screenOn = false;
|
screenOn = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateScreen() {
|
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(){
|
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.drawBitmap(0, 0, battery_logo, 120, 32, 1);
|
display.drawBitmap(0, 0, battery_logo, 120, 32, 1);
|
||||||
display.setTextSize(2);
|
display.setTextSize(2);
|
||||||
display.setCursor(30, 10);
|
display.setCursor(30, 10);
|
||||||
display.setTextColor(0);
|
display.setTextColor(0);
|
||||||
display.print(GetVoltage());
|
if (screenState == 1){
|
||||||
display.println(" V");
|
display.print(getPct());
|
||||||
|
display.println("%");
|
||||||
|
}
|
||||||
|
else if (screenState == 2){
|
||||||
|
display.print(getVoltage());
|
||||||
|
display.println(" V");
|
||||||
|
}
|
||||||
updateDispayHelper();
|
updateDispayHelper();
|
||||||
display.display();
|
display.display();
|
||||||
screenOn = true;
|
screenOn = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void updateDisplayChg(){
|
void updateDisplayChg(){
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
updateDispayHelper();
|
updateDispayHelper();
|
||||||
@ -326,43 +268,23 @@ void updateDisplayChg(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateDispayHelper(){
|
void updateDispayHelper(){
|
||||||
if (charging_1 == true && batteryPct != 100) {display.drawBitmap(118, 0, charge_logo, 16, 14, 1); screenOn = true;}
|
int batteryPct = getPct();
|
||||||
else if (charging_2 == true && batteryPct != 100) {display.drawBitmap(118, 16, charge_logo, 16, 14, 1); screenOn = true;}
|
if (charging_1 == true && batteryPct < 100) {display.drawBitmap(118, 0, 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;}
|
if (charging_2 == true && batteryPct < 100) {display.drawBitmap(118, 16, charge_logo, 16, 14, 1); screenOn = true;}
|
||||||
else if (charging_2 == true && batteryPct == 100) {display.drawBitmap(118, 16, charged_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(){
|
double getVoltage(){
|
||||||
int totalSamples = 0;
|
return (FuelGauge.voltage()/1000);
|
||||||
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(){
|
int getPct(){
|
||||||
return (FuelGauge.voltage());
|
return (FuelGauge.percent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void safetyCheck(){
|
void safetyCheck(){
|
||||||
double currentVoltage = 0;
|
double currentVoltage = getVoltage();
|
||||||
currentVoltage = GetVoltage();
|
|
||||||
if(currentVoltage > 3.40 ){ //|| currentVoltage < 1.00
|
if(currentVoltage > 3.40 ){ //|| currentVoltage < 1.00
|
||||||
isSafe = true;
|
isSafe = true;
|
||||||
}
|
}
|
||||||
1178
Code/v2/v2.ino.eightanaloginputs.hex
Normal file
1302
Code/v2/v2.ino.with_bootloader.eightanaloginputs.hex
Normal file
50
Code/vLogger.py
Normal 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()
|
||||||
|
Before Width: | Height: | Size: 293 KiB After Width: | Height: | Size: 293 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 42 B After Width: | Height: | Size: 42 B |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 43 B After Width: | Height: | Size: 43 B |
|
Before Width: | Height: | Size: 49 B After Width: | Height: | Size: 49 B |
|
Before Width: | Height: | Size: 49 B After Width: | Height: | Size: 49 B |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 49 B After Width: | Height: | Size: 49 B |