Compare commits
2 Commits
7e02287892
...
9987a1693d
Author | SHA1 | Date |
---|---|---|
interfisch | 9987a1693d | |
interfisch | 3301a3eaed |
|
@ -4,6 +4,10 @@
|
||||||
unsigned long loopmillis;
|
unsigned long loopmillis;
|
||||||
unsigned long last_loopmillis;
|
unsigned long last_loopmillis;
|
||||||
|
|
||||||
|
|
||||||
|
#include <TimeLib.h> //for teensy rtc
|
||||||
|
time_t getTeensy3Time();
|
||||||
|
|
||||||
#include <OneButton.h>
|
#include <OneButton.h>
|
||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
@ -188,6 +192,7 @@ uint8_t controlmode=0;
|
||||||
#include <SD.h> //Format sd cart with FAT or FAT16
|
#include <SD.h> //Format sd cart with FAT or FAT16
|
||||||
#define SDCHIPSELECT 16
|
#define SDCHIPSELECT 16
|
||||||
boolean datalogging=true;
|
boolean datalogging=true;
|
||||||
|
String datalogging_filename="UNKNOWN.txt";
|
||||||
|
|
||||||
|
|
||||||
void updateInputs(unsigned long loopmillis);
|
void updateInputs(unsigned long loopmillis);
|
||||||
|
@ -196,20 +201,60 @@ void display_show_stats();
|
||||||
void display_show_stats2();
|
void display_show_stats2();
|
||||||
void display_show_stats3();
|
void display_show_stats3();
|
||||||
void display_show_menu();
|
void display_show_menu();
|
||||||
|
time_t getTeensy3Time();
|
||||||
|
String addLeadingZero(int number);
|
||||||
|
String getCurrentDatestring();
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(SERIAL_BAUD); //Debug and Program
|
Serial.begin(SERIAL_BAUD); //Debug and Program
|
||||||
|
|
||||||
|
Wire.begin();
|
||||||
|
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
|
||||||
|
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
||||||
|
Serial.println(F("SSD1306 allocation failed"));
|
||||||
|
for(;;); // Don't proceed, loop forever
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show initial display buffer contents on the screen --
|
||||||
|
// the library initializes this with an Adafruit splash screen.
|
||||||
|
display.display();
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setTextColor(SSD1306_WHITE);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println(F("Init. ESC"));
|
||||||
|
display.display(); // Show initial text
|
||||||
|
|
||||||
esc.init();
|
esc.init();
|
||||||
|
|
||||||
|
|
||||||
|
display.print(F("Init. SD.. ")); display.display();
|
||||||
|
|
||||||
Serial.print("Initializing SD card...");
|
Serial.print("Initializing SD card...");
|
||||||
// see if the card is present and can be initialized:
|
// see if the card is present and can be initialized:
|
||||||
if (!SD.begin(SDCHIPSELECT)) {
|
if (!SD.begin(SDCHIPSELECT)) {
|
||||||
Serial.println("Card failed, or not present");
|
Serial.println("Card failed, or not present");
|
||||||
|
display.print(F("Fail!")); display.display();
|
||||||
datalogging=false; //disable logging
|
datalogging=false; //disable logging
|
||||||
|
delay(1000);
|
||||||
}else{
|
}else{
|
||||||
Serial.println("Card initialized.");
|
Serial.println("Card initialized.");
|
||||||
|
display.print(F("OK")); display.display();
|
||||||
|
if (datalogging){
|
||||||
|
int filenumber=0;
|
||||||
|
char buffer[6];
|
||||||
|
sprintf(buffer, "%04d", filenumber);
|
||||||
|
datalogging_filename="LOG_"+String(buffer)+".TXT";
|
||||||
|
while(SD.exists(datalogging_filename) && filenumber<10000) {
|
||||||
|
Serial.print(datalogging_filename); Serial.println(" exists");
|
||||||
|
filenumber++;
|
||||||
|
sprintf(buffer, "%04d", filenumber);
|
||||||
|
datalogging_filename="LOG_"+String(buffer)+".TXT";
|
||||||
|
|
||||||
|
}
|
||||||
|
Serial.print(datalogging_filename); Serial.println(" is free");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
analogReadResolution(12);
|
analogReadResolution(12);
|
||||||
|
@ -233,29 +278,29 @@ void setup() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Wire.begin();
|
|
||||||
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
|
display.print(F("Init. RTC.. ")); display.display();
|
||||||
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
|
||||||
Serial.println(F("SSD1306 allocation failed"));
|
setSyncProvider(getTeensy3Time); //See https://www.pjrc.com/teensy/td_libs_Time.html#teensy3
|
||||||
for(;;); // Don't proceed, loop forever
|
if (timeStatus()!= timeSet) {
|
||||||
|
Serial.println("Unable to sync with the RTC");
|
||||||
|
display.println(F("Fail")); display.display();
|
||||||
|
delay(1000);
|
||||||
|
} else {
|
||||||
|
Serial.println("RTC has set the system time");
|
||||||
|
display.println(F("OK")); display.display();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show initial display buffer contents on the screen --
|
|
||||||
// the library initializes this with an Adafruit splash screen.
|
display.println(F("Init. NRF24")); display.display();
|
||||||
display.display();
|
|
||||||
|
|
||||||
display.clearDisplay();
|
|
||||||
display.setTextSize(1);
|
|
||||||
display.setTextColor(SSD1306_WHITE);
|
|
||||||
display.setCursor(10, 0);
|
|
||||||
display.println(F("Radio Init"));
|
|
||||||
display.display(); // Show initial text
|
|
||||||
|
|
||||||
radio.begin();
|
radio.begin();
|
||||||
|
|
||||||
|
|
||||||
Serial.println("RF24 set rate");
|
Serial.println("RF24 set rate");
|
||||||
radio.setDataRate( RF24_250KBPS ); //set to slow data rate. default was 1MBPS
|
if (!radio.setDataRate( RF24_250KBPS )){ //set to slow data rate. default was 1MBPS
|
||||||
|
display.println(F(" Fail Data Rate!")); display.display();
|
||||||
|
}
|
||||||
//radio.setDataRate( RF24_1MBPS );
|
//radio.setDataRate( RF24_1MBPS );
|
||||||
//Serial.println("set channel");
|
//Serial.println("set channel");
|
||||||
|
|
||||||
|
@ -272,12 +317,11 @@ void setup() {
|
||||||
Serial.println("start listening");
|
Serial.println("start listening");
|
||||||
radio.startListening();
|
radio.startListening();
|
||||||
|
|
||||||
display.clearDisplay();
|
|
||||||
display.setTextSize(2); // Draw 2X-scale text
|
|
||||||
display.setTextColor(SSD1306_WHITE);
|
display.println(F("Finished"));
|
||||||
display.setCursor(10, 0);
|
|
||||||
display.println(F("Started"));
|
|
||||||
display.display(); // Show initial text
|
display.display(); // Show initial text
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -550,15 +594,36 @@ void loop() {
|
||||||
|
|
||||||
|
|
||||||
static unsigned long last_datalogging_write=0;
|
static unsigned long last_datalogging_write=0;
|
||||||
|
static boolean logging_headerWritten=false;
|
||||||
if (datalogging) {
|
if (datalogging) {
|
||||||
#define LOGGINGINTERVAL 100
|
#define LOGGINGINTERVAL 100
|
||||||
if (loopmillis-last_datalogging_write>LOGGINGINTERVAL)
|
if (loopmillis-last_datalogging_write>LOGGINGINTERVAL)
|
||||||
{
|
{
|
||||||
last_datalogging_write=loopmillis;
|
last_datalogging_write=loopmillis;
|
||||||
File dataFile = SD.open("datalog.txt", FILE_WRITE);
|
|
||||||
|
File dataFile = SD.open(datalogging_filename, FILE_WRITE);
|
||||||
|
|
||||||
if (dataFile) { // if the file is available, write to it
|
if (dataFile) { // if the file is available, write to it
|
||||||
dataFile.println("TEST asdf");
|
if (!logging_headerWritten) {
|
||||||
|
dataFile.print("time,cmd_L,cmd_R,");
|
||||||
|
dataFile.print("current_L,current_R,");
|
||||||
|
dataFile.print("rpm_L,rpm_R,");
|
||||||
|
dataFile.print("temp,vbat,");
|
||||||
|
dataFile.println("trip,currentConsumed");
|
||||||
|
logging_headerWritten=true;
|
||||||
|
}
|
||||||
|
dataFile.print(String(loopmillis)); dataFile.print(";");
|
||||||
|
dataFile.print(esc.getCmdL()); dataFile.print(";");
|
||||||
|
dataFile.print(esc.getCmdR()); dataFile.print(";");
|
||||||
|
dataFile.print(esc.getFiltered_curL(),3); dataFile.print(";");
|
||||||
|
dataFile.print(esc.getFiltered_curR(),3); dataFile.print(";");
|
||||||
|
dataFile.print(esc.getFeedback_speedL_meas()); dataFile.print(";");
|
||||||
|
dataFile.print(esc.getFeedback_speedR_meas()); dataFile.print(";");
|
||||||
|
dataFile.print(esc.getFeedback_boardTemp()); dataFile.print(";");
|
||||||
|
dataFile.print(esc.getFeedback_batVoltage()); dataFile.print(";");
|
||||||
|
dataFile.print(esc.getTrip()); dataFile.print(";");
|
||||||
|
dataFile.print(esc.getCurrentConsumed(),3);
|
||||||
|
dataFile.println("");
|
||||||
dataFile.close();
|
dataFile.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -744,7 +809,7 @@ void display_show_stats() {
|
||||||
static float mincurR=0;
|
static float mincurR=0;
|
||||||
mincurL=min(mincurL,esc.getFiltered_curL());
|
mincurL=min(mincurL,esc.getFiltered_curL());
|
||||||
mincurR=min(mincurR,esc.getFiltered_curR());*/
|
mincurR=min(mincurR,esc.getFiltered_curR());*/
|
||||||
|
|
||||||
|
|
||||||
display.print(F("Bat=")); display.print(esc.getFeedback_batVoltage()); display.print(F(" min=")); display.println(esc.getMinBatVoltage());
|
display.print(F("Bat=")); display.print(esc.getFeedback_batVoltage()); display.print(F(" min=")); display.println(esc.getMinBatVoltage());
|
||||||
display.print(F("Temp=")); display.print(esc.getFeedback_boardTemp()); display.print(F(" max=")); display.println(esc.getMaxBoardTemp());
|
display.print(F("Temp=")); display.print(esc.getFeedback_boardTemp()); display.print(F(" max=")); display.println(esc.getMaxBoardTemp());
|
||||||
|
@ -753,6 +818,13 @@ void display_show_stats() {
|
||||||
display.print(F("trip=")); display.print(esc.getTrip(),0); display.print(F(", ")); display.print(esc.getCurrentConsumed(),3); display.println(F("Ah"));
|
display.print(F("trip=")); display.print(esc.getTrip(),0); display.print(F(", ")); display.print(esc.getCurrentConsumed(),3); display.println(F("Ah"));
|
||||||
display.print(F("eff.=")); display.print(esc.getTrip()/esc.getCurrentConsumed(),0); display.println(F("m/Ah"));
|
display.print(F("eff.=")); display.print(esc.getTrip()/esc.getCurrentConsumed(),0); display.println(F("m/Ah"));
|
||||||
|
|
||||||
|
display.print(F("RTC=")); display.print(getCurrentDatestring()); display.println(F(""));
|
||||||
|
|
||||||
|
if (datalogging) {
|
||||||
|
display.print(datalogging_filename); display.print(F(" ")); display.print(loopmillis/1000); display.println(F("s"));
|
||||||
|
}else{
|
||||||
|
display.print("No SD"); display.println(F(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
display.display(); // Show initial text
|
display.display(); // Show initial text
|
||||||
|
@ -837,4 +909,22 @@ void display_show_menu() {
|
||||||
}
|
}
|
||||||
|
|
||||||
display.display(); // Show initial text
|
display.display(); // Show initial text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
time_t getTeensy3Time()
|
||||||
|
{
|
||||||
|
return Teensy3Clock.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
String addLeadingZero(int number) {
|
||||||
|
if (number<10) {
|
||||||
|
return "0"+String(number);
|
||||||
|
}
|
||||||
|
return String(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
String getCurrentDatestring() {
|
||||||
|
return addLeadingZero(year())+addLeadingZero(month())+addLeadingZero(day())+"-"+addLeadingZero(hour())+addLeadingZero(minute())+addLeadingZero(second());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue