Hi all, i found this project over at instructables https://www.instructables.com/id/Simple-DIY-Dual-Pulse-Spot-Welder-With-Arduino-Con/
but i dont have a 16x2 i2c lcd but i do have a ssd1306 oled display i would like to use.
im not very proficient when it comes to arduino code so im hoping someone can help me.
i have the adafruit ssd1306 and adafruit gfx libraries loaded, just not sure what i need to change in the code for it to work.
#include <Wire.h> // standard I2C library included with the Arduino IDE
#include <math.h> // standard library used for temperature calculations
#include <LiquidCrystal_I2C.h> // for I2C, you need the new library installed (the link is just below)
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // I learned how to set up this screen here: http://arduino-info.wikispaces.com/LCD-Blue-I2C
int menupin = 4; // D4 - This pin connects to the button that controls the menu
int switchpin = 3; // D3 - This pin connects to the solid state switch (relay) on the positive terminal
int weldbuttonpin = 2; // D2 - This pin connects to the button that activates the switch, initiating the weld
int thermpin = 0; // A0 - This pin connects to the thermistor which makes up our temperature sensor
int preweld = 50; // This is the time in milliseconds that the spot welder uses to pre-weld (the first pulse in a dual pulse weld)
int postprepause = 500; // This is the time in milliseconds that the spot welder waits before initiating the second pulse in a dual pulse
int weldtimeincrement = 50; // This is the time in milliseconds that the menu will increase the weld time by whenever you press the menu button
int maxweldpulse = 450; // This is the highest auto setting in milliseconds. Make this the highest pulse width you want available in the menu
// Using this in conjuction with "weldtimeincrement" (just above) gives us a range of 50-450ms in 50ms increments.
int debouncepause = 200; // This is just to prevent accidental double activations due to physical imperfections in buttons
bool manualweld = false; // This is used for alternate actions when in manual mode as opposed to dual pulse automatic
int weldtime = 0; // This init value becomes the base increment value. This is just a declaration and doesn't need to be changed.
int cutofftemp = 80; // This is the cut off temperature for the welder in Celsius. I use 80 for safety but you can use 30 for testing the system
int resumetemp = 40; // This is the temp in Celsius at which the system becomes available again. I use 40 for safety and 28 for testing
void setup()
{
pinMode(switchpin, OUTPUT); // setting up our pins
pinMode(weldbuttonpin, INPUT);
pinMode(menupin, INPUT);
pinMode(thermpin, INPUT);
maxweldpulse = (maxweldpulse - weldtimeincrement); // this does some simple math for our menu range
weldtime = weldtimeincrement; // This sets our minimum weld time
lcd.begin(16,2); // Turn on the lcd. My LCD is 16 characters long and 2 lines tall
lcd.backlight(); // Turn on the backlight.
menudisplay(); // display the initial menu screen
}
void loop()
{
if (int(Thermistor(analogRead(thermpin))) >= cutofftemp){ // This prevents any activations if the temperature is too high
cooldown();
}
if (digitalRead(menupin)==HIGH){ // This changes the menu if the menu button is pressed
delay(debouncepause);
menuchange();
}
if (digitalRead(weldbuttonpin)==HIGH) { // This begins a weld when the weld button is pressed
delay(debouncepause);
weld();
}
}
void menuchange(){ // This function changes the menu to the next time or manual mode depending on your ranges
manualweld=false;
if (weldtime<=maxweldpulse){
weldtime = (weldtime + weldtimeincrement);
}
else{
weldtime = 0;
manualweld=true;
}
menudisplay();
}
void menudisplay(){ // This function displays all the information and menu on the LCD
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Weld Time | Temp");
lcd.setCursor(0,1);
if (manualweld == true){
lcd.print("Manual");
lcd.setCursor(10,1);
lcd.print("| ");
lcd.print(int(Thermistor(analogRead(thermpin))));
lcd.print("C");
}
else{
lcd.print(weldtime);
lcd.print(" ms");
lcd.setCursor(10,1);
lcd.print("| ");
lcd.print(int(Thermistor(analogRead(thermpin))));
lcd.print("C");
}
}
void weld(){ // This function activates the solid state relay based on your menu selection
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Welding...");
if(manualweld == true){
while(digitalRead(weldbuttonpin)==HIGH && int(Thermistor(analogRead(thermpin)) < cutofftemp)){ // No welding if the temperature is out of range (double check). Activate a manual weld.
digitalWrite(switchpin, HIGH);
}
digitalWrite(switchpin, LOW);
}
else{ // Activate an automatic dual pulse based on the menu selection and your range definitions
digitalWrite(switchpin, HIGH);
delay(preweld);
digitalWrite(switchpin, LOW);
delay(postprepause);
digitalWrite(switchpin, HIGH);
delay(weldtime);
digitalWrite(switchpin, LOW);
}
menudisplay();
}
void cooldown(){ // This is the cooldown mode for when/if the temperature reaches dangerous levels
while (int(Thermistor(analogRead(thermpin))) > resumetemp){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Cooling...| Temp");
lcd.setCursor(10,1);
lcd.print("| ");
lcd.print(int(Thermistor(analogRead(thermpin))));
lcd.print("C");
delay(1000); // Refresh the temperature every second while in cooldown mode. Normally it is only refreshed after a button press. (otherwise things get messy imo)
}
menudisplay();
}
// This function (and its original call) borrowed from http://playground.arduino.cc/ComponentLib/Thermistor2. It does the math for the temp.
double Thermistor(int RawADC) {
double Temp;
Temp = log(10000.0*((1024.0/RawADC-1)));
// =log(10000.0/(1024.0/RawADC-1)) // for pull-up configuration
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
// Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
return Temp;
}