From fb8bb3256eddc0c152f0c72fb15c47b6a2117825 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 27 Aug 2018 08:26:37 -0500 Subject: [PATCH 1/2] esp32 support, mosty commenting stuff out ### todo removes flashstorage to be abstracted into methods and add ifdef wraps esp32 flash storage support for read and write methods esp32 tone buzzer esp32 relay pwm use sigmandelta or ledc abstract to start and wriite methods --- Code/Reflow_Master/ReflowMasterProfile.h | 3 + Code/Reflow_Master/Reflow_Master.ino | 147 ++++++++++++++++++----- 2 files changed, 123 insertions(+), 27 deletions(-) diff --git a/Code/Reflow_Master/ReflowMasterProfile.h b/Code/Reflow_Master/ReflowMasterProfile.h index ba4b052..cab7b63 100644 --- a/Code/Reflow_Master/ReflowMasterProfile.h +++ b/Code/Reflow_Master/ReflowMasterProfile.h @@ -44,6 +44,8 @@ This is the profile structure used by the Reflow Master toaster oven controller float reflowGraphX[10]; float reflowGraphY[10]; float wantedCurve[350]; + float tangents[10]; + int len = -1; int fanTime = -1; int offTime = -1; @@ -70,6 +72,7 @@ This is the profile structure used by the Reflow Master toaster oven controller { reflowGraphX[i] = flowX[i]; reflowGraphY[i] = flowY[i]; + tangents[i] = 0; } for ( int i = 0; i < ELEMENTS(wantedCurve); i++ ) diff --git a/Code/Reflow_Master/Reflow_Master.ino b/Code/Reflow_Master/Reflow_Master.ino index 182d5e6..d51a4be 100644 --- a/Code/Reflow_Master/Reflow_Master.ino +++ b/Code/Reflow_Master/Reflow_Master.ino @@ -28,6 +28,33 @@ HISTORY: * NOTE: This is a work in progress... */ + +/** + * START custom temperature sensor, ADS1x + */ +#include +#include + +// Adafruit_ADS1115 ads; /* Use this for the 16-bit version */ +Adafruit_ADS1015 ads; /* Use thi for the 12-bit version */ + +#include +TypeK TC_K; +float Tsense; // variable to store the measured temperature +float Tcjc = 25.3; // cold junction compensation temperature +float mV = 41.276; // thermocouple mV reading + +int16_t results; +/* Be sure to update this value based on the IC and the gain settings! */ +// float multiplier = 3.0F; /* ADS1015 @ +/- 6.144V gain (12-bit results) */ +float multiplier = 0.125; /* ADS1015 @ +/- 6.144V gain (12-bit results) */ +//float multiplier = 0.1875F; /* ADS1115 @ +/- 6.144V gain (16-bit results) */ +#define _SDA SDA +#define _SCL SCL +/** + * END + */ + #include #include // http://github.com/kerinin/arduino-splines #include "Adafruit_GFX.h" // Library Manager @@ -35,7 +62,7 @@ HISTORY: #include "MAX31855.h" // by Rob Tillaart Library Manager #include "OneButton.h" // Library Manager #include "ReflowMasterProfile.h" -#include // Library Manager +// #include // Library Manager // used to obtain the size of an array of any type #define ELEMENTS(x) (sizeof(x) / sizeof(x[0])) @@ -44,8 +71,8 @@ HISTORY: #define DEBUG // TFT SPI pins -#define TFT_DC 0 -#define TFT_CS 3 +#define TFT_DC 16 +#define TFT_CS 17 #define TFT_RESET 1 // MAX 31855 Pins @@ -53,14 +80,14 @@ HISTORY: #define MAXCS 10 #define MAXCLK 12 -#define BUTTON0 A0 // menu buttons -#define BUTTON1 A1 // menu buttons -#define BUTTON2 A2 // menu buttons -#define BUTTON3 A3 // menu buttons +#define BUTTON0 36 // menu buttons +#define BUTTON1 39 // menu buttons +#define BUTTON2 34 // menu buttons +#define BUTTON3 35 // menu buttons -#define BUZZER A4 // buzzer -#define RELAY 5 // relay control -#define FAN A5 // fan control +#define BUZZER 32 // buzzer +#define RELAY 33 // relay control +#define FAN 25 // fan control // Just a bunch of re-defined colours #define BLUE 0x001F @@ -88,6 +115,12 @@ HISTORY: #define DKPURPLE 0x4010 #define DKGREY 0x4A49 +// @note adding some color defines for customization, add all +#define GRAPHA DKGREY +#define GRAPHB GREY +#define GRAPHC WHITE +#define GRAPHD BLACK + // Save data struct typedef struct { boolean valid = false; @@ -164,7 +197,7 @@ OneButton button3(BUTTON3, false); // Initiliase a reference for the settings file that we store in flash storage Settings set; // Initialise flash storage -FlashStorage(flash_store, Settings); +// FlashStorage(flash_store, Settings); // @todo ifdef // This is where we initialise each of the profiles that will get loaded into the Reflkow Master void LoadPaste() @@ -233,19 +266,26 @@ void SetCurrentGraph( int index ) Serial.print("Setting Paste: "); Serial.println( CurrentGraph().n ); Serial.println( CurrentGraph().t ); + Serial.println( CurrentGraph().len ); #endif // Initialise the spline for the profile to allow for smooth graph display on UI timeX = 0; - baseCurve.setPoints(CurrentGraph().reflowGraphX, CurrentGraph().reflowGraphY, CurrentGraph().len); + // baseCurve.setPoints(CurrentGraph().reflowGraphX, CurrentGraph().reflowGraphY, CurrentGraph().len); + baseCurve.setPoints(CurrentGraph().reflowGraphX, CurrentGraph().reflowGraphY, CurrentGraph().tangents, CurrentGraph().len); baseCurve.setDegree( Hermite ); // Re-interpolate data based on spline for( int ii = 0; ii <= graphRangeMax_X; ii+= 1 ) { + Serial.println(ii); + Serial.println(baseCurve.value(ii)); solderPaste[ currentGraphIndex ].wantedCurve[ii] = baseCurve.value(ii); + // solderPaste[ currentGraphIndex ].wantedCurve[ii] = random(200); + delay(0); } + Serial.print("DONE "); // calculate the biggest graph movement delta float lastWanted = -1; for ( int i = 0; i < solderPaste[ currentGraphIndex ].offTime; i++ ) @@ -260,14 +300,33 @@ void SetCurrentGraph( int index ) solderPaste[ currentGraphIndex ].maxWantedDelta = wantedDiff; } lastWanted = wantedTemp; + delay(0); } } +// @todo abstract pwm relay control, esp32 use sigmadelta or ledc +void setupRelay(){ + sigmaDeltaSetup(0, 312500); + //attach pin 18 to channel 0 + sigmaDeltaAttachPin(RELAY,0); + //initialize channel 0 to off + sigmaDeltaWrite(0, 0); +} + +void writeRelay(int value){ + sigmaDeltaWrite(0,value); +} + void setup() { + + initTemp(); + // Setup all GPIO pinMode( BUZZER, OUTPUT ); - pinMode( RELAY, OUTPUT ); + + // pinMode( RELAY, OUTPUT ); + setupRelay(); pinMode( FAN, OUTPUT ); pinMode( BUTTON0, INPUT ); @@ -286,14 +345,14 @@ void setup() delay(500); // load settings from FLASH - set = flash_store.read(); + // set = flash_store.read(); // @todo abstract // If no settings were loaded, initialise data and save if ( !set.valid ) { SetDefaults(); newSettings = true; - flash_store.write(set); + // flash_store.write(set); // @todo abstract } // Attatch button IO for OneButton @@ -330,8 +389,21 @@ void setup() // Show the main menu ShowMenu(); + delay(1000); + StartReflow(); } +// @note modified for dev testing +// @todo refactor to allow dev simulations +void _loop(){ + delay(1000); + currentTemp = 28; + lastTemp = currentTemp; + StartWarmup(); + delay(1000); + state = 2; + StartReflow(); +} void loop() { @@ -340,7 +412,6 @@ void loop() button1.tick(); button2.tick(); button3.tick(); - // Current activity state machine if ( state == 0 ) // BOOT { @@ -351,10 +422,9 @@ void loop() if ( nextTempRead < millis() ) // we only read the probe every second { nextTempRead = millis() + 1000; - + ReadCurrentTemp(); MatchTemp(); - if ( currentTemp >= GetGraphValue(0) ) { // We have reached the starting temp for the profile, so lets start baking our boards! @@ -556,7 +626,8 @@ void SetRelayFrequency( int duty ) currentDuty = ((float)duty * set.power ); // Write the clamped duty cycle to the RELAY GPIO - analogWrite( RELAY, constrain( round( currentDuty ), 0, 255) ); + // analogWrite( RELAY, constrain( round( currentDuty ), 0, 255) ); + sigmaDeltaWrite(0,constrain( round( currentDuty ), 0, 255)); // @todo abstract, NOT TESTED #ifdef DEBUG Serial.print("RELAY Duty Cycle: "); @@ -627,9 +698,10 @@ void MatchCalibrationTemp() // Read the temp probe void ReadCurrentTemp() { - int status = tc.read(); - float internal = tc.getInternal(); - currentTemp = tc.getTemperature() + set.tempOffset; + // int status = tc.read(); + // float internal = tc.getInternal(); + // currentTemp = tc.getTemperature() + set.tempOffset; + updateTemp(); // @note replacing with tests and adc testing (not reliant on max 31855) } // This is where the magic happens for temperature matching @@ -785,7 +857,7 @@ void DrawHeading( String lbl, unsigned int acolor, unsigned int bcolor ) // buzz he buzzer void Buzzer( int hertz, int len ) { - tone( BUZZER, hertz, len); + // tone( BUZZER, hertz, len); // @todo esp32 no pwn or tone } @@ -830,7 +902,7 @@ void ShowMenu() state = 10; SetRelayFrequency( 0 ); - set = flash_store.read(); + // set = flash_store.read(); // @todo abstract tft.fillScreen(BLACK); @@ -1160,7 +1232,7 @@ void StartReflow() ShowMenuOptions( true ); timeX = 0; - SetupGraph(tft, 0, 0, 30, 220, 270, 180, graphRangeMin_X, graphRangeMax_X, graphRangeStep_X, graphRangeMin_Y, graphRangeMax_Y, graphRangeStep_Y, "Reflow Temp", " Time [s]", "deg [C]", DKBLUE, BLUE, WHITE, BLACK ); + SetupGraph(tft, 0, 0, 30, 220, 270, 180, graphRangeMin_X, graphRangeMax_X, graphRangeStep_X, graphRangeMin_Y, graphRangeMax_Y, graphRangeStep_Y, "Reflow Temp", " Time [s]", "deg [C]", GRAPHA,GRAPHB,GRAPHC,GRAPHD ); DrawHeading( "READY", WHITE, BLACK ); DrawBaseGraph(); @@ -1217,7 +1289,7 @@ void ResetSettingsToDefault() { // set default values again and save SetDefaults(); - flash_store.write(set); + // flash_store.write(set); // @todo abstract // load the default paste SetCurrentGraph( set.paste ); @@ -1440,6 +1512,9 @@ long nextButtonPress = 0; void button0Press() { + // @todo use state machine instead, use flags for start reflow, remove from button callback scope + // so that these are all in global scope and can be refactored,methodized and unit tested + // maybe add enums for states for clarity if ( nextButtonPress < millis() ) { nextButtonPress = millis() + 20; @@ -1540,7 +1615,7 @@ void button1Press() else if ( state == 11 ) // leaving settings so save { // save data in flash - flash_store.write(set); + // flash_store.write(set); // @todo abstract ShowMenu(); } else if ( state == 12 || state == 13 ) @@ -1738,4 +1813,22 @@ void println_Right( Adafruit_ILI9341 &d, String heading, int centerX, int center } +void tester(){ + currentTemp = 28; + // state = 2; // start + // if(state != 2) StartWarmup(); +} +void updateTemp(){ + results = ads.readADC_Differential_0_1(); + mV = results * multiplier; + Tsense = TC_K.Temp_C(mV, Tcjc); // C compensated + currentTemp = round(Tsense + set.tempOffset); + Serial.println(currentTemp); +} + +void initTemp(){ + ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV + ads.begin(); + Wire.begin(_SDA,_SCL); +} From 97bb6fb627ec9b8964b65d82881b2614ee457422 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 27 Aug 2018 09:06:34 -0500 Subject: [PATCH 2/2] restored samd pins --- Code/Reflow_Master/Reflow_Master.ino | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Code/Reflow_Master/Reflow_Master.ino b/Code/Reflow_Master/Reflow_Master.ino index ffdce7c..5859321 100644 --- a/Code/Reflow_Master/Reflow_Master.ino +++ b/Code/Reflow_Master/Reflow_Master.ino @@ -71,6 +71,7 @@ float multiplier = 0.125; /* ADS1015 @ +/- 6.144V gain (12-bit results) */ // used to show or hide serial debug output //#define DEBUG +#ifdef ESP32 // TFT SPI pins #define TFT_DC 16 #define TFT_CS 17 @@ -89,6 +90,26 @@ float multiplier = 0.125; /* ADS1015 @ +/- 6.144V gain (12-bit results) */ #define BUZZER 32 // buzzer #define RELAY 33 // relay control #define FAN 25 // fan control +#else +// TFT SPI pins +#define TFT_DC 0 +#define TFT_CS 3 +#define TFT_RESET 1 + +// MAX 31855 Pins +#define MAXDO 11 +#define MAXCS 10 +#define MAXCLK 12 + +#define BUTTON0 A0 // menu buttons +#define BUTTON1 A1 // menu buttons +#define BUTTON2 A2 // menu buttons +#define BUTTON3 A3 // menu buttons + +#define BUZZER A4 // buzzer +#define RELAY 5 // relay control +#define FAN A5 // fan control +#endif // Just a bunch of re-defined colours #define BLUE 0x001F