Compare commits
No commits in common. "9987a1693de3f550b703e394b872450f0b8ff9ee" and "7e02287892f884356570d588dbd4e3e86c93d4bd" have entirely different histories.
9987a1693d
...
7e02287892
|
@ -4,10 +4,6 @@
|
|||
unsigned long loopmillis;
|
||||
unsigned long last_loopmillis;
|
||||
|
||||
|
||||
#include <TimeLib.h> //for teensy rtc
|
||||
time_t getTeensy3Time();
|
||||
|
||||
#include <OneButton.h>
|
||||
|
||||
#include <SPI.h>
|
||||
|
@ -192,7 +188,6 @@ uint8_t controlmode=0;
|
|||
#include <SD.h> //Format sd cart with FAT or FAT16
|
||||
#define SDCHIPSELECT 16
|
||||
boolean datalogging=true;
|
||||
String datalogging_filename="UNKNOWN.txt";
|
||||
|
||||
|
||||
void updateInputs(unsigned long loopmillis);
|
||||
|
@ -201,60 +196,20 @@ void display_show_stats();
|
|||
void display_show_stats2();
|
||||
void display_show_stats3();
|
||||
void display_show_menu();
|
||||
time_t getTeensy3Time();
|
||||
String addLeadingZero(int number);
|
||||
String getCurrentDatestring();
|
||||
|
||||
void setup() {
|
||||
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();
|
||||
|
||||
|
||||
display.print(F("Init. SD.. ")); display.display();
|
||||
|
||||
Serial.print("Initializing SD card...");
|
||||
// see if the card is present and can be initialized:
|
||||
if (!SD.begin(SDCHIPSELECT)) {
|
||||
Serial.println("Card failed, or not present");
|
||||
display.print(F("Fail!")); display.display();
|
||||
datalogging=false; //disable logging
|
||||
delay(1000);
|
||||
}else{
|
||||
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);
|
||||
|
@ -278,29 +233,29 @@ void setup() {
|
|||
});
|
||||
|
||||
|
||||
|
||||
display.print(F("Init. RTC.. ")); display.display();
|
||||
|
||||
setSyncProvider(getTeensy3Time); //See https://www.pjrc.com/teensy/td_libs_Time.html#teensy3
|
||||
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();
|
||||
|
||||
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(10, 0);
|
||||
display.println(F("Radio Init"));
|
||||
display.display(); // Show initial text
|
||||
|
||||
display.println(F("Init. NRF24")); display.display();
|
||||
radio.begin();
|
||||
|
||||
|
||||
Serial.println("RF24 set rate");
|
||||
if (!radio.setDataRate( RF24_250KBPS )){ //set to slow data rate. default was 1MBPS
|
||||
display.println(F(" Fail Data Rate!")); display.display();
|
||||
}
|
||||
radio.setDataRate( RF24_250KBPS ); //set to slow data rate. default was 1MBPS
|
||||
//radio.setDataRate( RF24_1MBPS );
|
||||
//Serial.println("set channel");
|
||||
|
||||
|
@ -317,13 +272,14 @@ void setup() {
|
|||
Serial.println("start listening");
|
||||
radio.startListening();
|
||||
|
||||
|
||||
|
||||
display.println(F("Finished"));
|
||||
display.clearDisplay();
|
||||
display.setTextSize(2); // Draw 2X-scale text
|
||||
display.setTextColor(SSD1306_WHITE);
|
||||
display.setCursor(10, 0);
|
||||
display.println(F("Started"));
|
||||
display.display(); // Show initial text
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -594,36 +550,15 @@ void loop() {
|
|||
|
||||
|
||||
static unsigned long last_datalogging_write=0;
|
||||
static boolean logging_headerWritten=false;
|
||||
if (datalogging) {
|
||||
#define LOGGINGINTERVAL 100
|
||||
if (loopmillis-last_datalogging_write>LOGGINGINTERVAL)
|
||||
{
|
||||
last_datalogging_write=loopmillis;
|
||||
|
||||
File dataFile = SD.open(datalogging_filename, FILE_WRITE);
|
||||
File dataFile = SD.open("datalog.txt", FILE_WRITE);
|
||||
|
||||
if (dataFile) { // if the file is available, write to it
|
||||
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.println("TEST asdf");
|
||||
dataFile.close();
|
||||
}
|
||||
}
|
||||
|
@ -818,13 +753,6 @@ 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("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
|
||||
|
@ -910,21 +838,3 @@ void display_show_menu() {
|
|||
|
||||
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