mirror of
https://github.com/arwidcool/Solder-Plate.git
synced 2025-02-16 10:42:33 +01:00
Added all 6 thermistors and cleaned up the AnalogRef file
This commit is contained in:
parent
f6f2c7ff52
commit
8979e3aa2a
@ -9,43 +9,40 @@ class AnalogRef
|
|||||||
private:
|
private:
|
||||||
float systemVoltage; // Reference voltage in volts
|
float systemVoltage; // Reference voltage in volts
|
||||||
|
|
||||||
boolean systemVolatgeBelow4_5V = false;
|
|
||||||
uint8_t voltageRefPin = 27;
|
uint8_t voltageRefPin = 27;
|
||||||
|
|
||||||
uint8_t voltageInPin = 28;
|
uint8_t voltageInPin = 28;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
float sysVoltage;
|
float sysVoltage;
|
||||||
float sysMultiplyer;
|
float sysMultiplyer;
|
||||||
float outputVoltage;
|
float inputVoltage;
|
||||||
float outputVoltageMultiplyer;
|
|
||||||
float differenceMultiplyer;
|
//Set what the system voltage SHOULD be
|
||||||
AnalogRef(float systemVoltage)
|
AnalogRef(float systemVoltage)
|
||||||
{
|
{
|
||||||
this->systemVoltage = systemVoltage;
|
this->systemVoltage = systemVoltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Calculate the system voltage
|
||||||
float calculateSystemVoltage()
|
float calculateSystemVoltage()
|
||||||
{
|
{
|
||||||
const uint8_t sampleCount = 1;
|
const uint8_t SAMPLE_COUNT = 1;
|
||||||
|
const float VOLTAGE_REF = 1023.0;
|
||||||
uint16_t rawValue = 0;
|
uint16_t rawValue = 0;
|
||||||
|
for (size_t i = 0; i < SAMPLE_COUNT; ++i)
|
||||||
for (size_t i = 0; i < sampleCount; ++i)
|
|
||||||
{
|
{
|
||||||
rawValue += analogRead(voltageRefPin);
|
rawValue += analogRead(voltageRefPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
const float voltageRef = 1023.0;
|
float meanRawValue = (float)rawValue / SAMPLE_COUNT;
|
||||||
const float systemVoltage = 5.0;
|
float outputVoltage = meanRawValue / VOLTAGE_REF * systemVoltage;
|
||||||
const float systemVoltageOut = rawValue / sampleCount * systemVoltage / voltageRef;
|
float voltage5V = 2.5 / outputVoltage * systemVoltage;
|
||||||
const float voltage5V = 2.5 / systemVoltageOut * systemVoltage;
|
|
||||||
|
|
||||||
systemVolatgeBelow4_5V = voltage5V < 4.5;
|
|
||||||
|
|
||||||
return voltage5V;
|
return voltage5V;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Used for external voltage readings not powered by the 5V system
|
||||||
float calculateSystemVoltageMultyplyer()
|
float calculateSystemVoltageMultyplyer()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -58,6 +55,8 @@ public:
|
|||||||
return voltage_5V_multiplyer;
|
return voltage_5V_multiplyer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Calculate the input voltage of the power supply
|
||||||
float calculateInputVoltage()
|
float calculateInputVoltage()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -80,12 +79,7 @@ public:
|
|||||||
return vOut * 5.8;
|
return vOut * 5.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
void calculate()
|
|
||||||
{
|
|
||||||
|
|
||||||
sysVoltage = calculateSystemVoltage();
|
|
||||||
sysMultiplyer = 5 / sysVoltage;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ANALOGREF_H
|
#endif // ANALOGREF_H
|
||||||
|
@ -72,9 +72,7 @@ void Thermistor::calculateCoefficents(float resistance, TempCalibration calibrat
|
|||||||
float Thermistor::getResistance()
|
float Thermistor::getResistance()
|
||||||
{
|
{
|
||||||
|
|
||||||
analogRef.calculate();
|
float systemVoltage = analogRef.calculateSystemVoltage();
|
||||||
|
|
||||||
float systemVoltage = analogRef.sysVoltage;
|
|
||||||
|
|
||||||
int raw = analogRead(thermistorPin);
|
int raw = analogRead(thermistorPin);
|
||||||
|
|
||||||
@ -84,9 +82,7 @@ float Thermistor::getResistance()
|
|||||||
// Serial.println(vOut);
|
// Serial.println(vOut);
|
||||||
buffer = (systemVoltage / vOut) - 1;
|
buffer = (systemVoltage / vOut) - 1;
|
||||||
|
|
||||||
// Serial.println(R2);
|
|
||||||
// return the resistence
|
// return the resistence
|
||||||
|
|
||||||
sensorResistance = setRes * buffer;
|
sensorResistance = setRes * buffer;
|
||||||
|
|
||||||
return sensorResistance;
|
return sensorResistance;
|
||||||
|
143
src/main.cpp
143
src/main.cpp
@ -20,7 +20,6 @@ TempCalibration calibration_100K_3950 = {25, 100000, 86, 10000, 170, 1000};
|
|||||||
#define TFT_DC 14
|
#define TFT_DC 14
|
||||||
#define MOSI 4 // MOSI
|
#define MOSI 4 // MOSI
|
||||||
#define SCK 6 // SCK
|
#define SCK 6 // SCK
|
||||||
|
|
||||||
// Create an instance of the Adafruit ST7789 class using the custom SPI pins
|
// Create an instance of the Adafruit ST7789 class using the custom SPI pins
|
||||||
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST);
|
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST);
|
||||||
|
|
||||||
@ -32,6 +31,11 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
|||||||
|
|
||||||
// Initalize a 3950 100K thermistor with 2.5k reference resistor using the default calibration data for 100K thermistor
|
// Initalize a 3950 100K thermistor with 2.5k reference resistor using the default calibration data for 100K thermistor
|
||||||
Thermistor thermistor1(THERMISTOR1_PIN, 2500);
|
Thermistor thermistor1(THERMISTOR1_PIN, 2500);
|
||||||
|
Thermistor thermistor2(THERMISTOR2_PIN, 2500);
|
||||||
|
Thermistor thermistor3(THERMISTOR3_PIN, 2500);
|
||||||
|
Thermistor thermistor4(THERMISTOR4_PIN, 2500);
|
||||||
|
Thermistor thermistor5(THERMISTOR5_PIN, 2500);
|
||||||
|
Thermistor thermistor6(THERMISTOR6_PIN, 9000);
|
||||||
|
|
||||||
Buttons buttons = Buttons();
|
Buttons buttons = Buttons();
|
||||||
|
|
||||||
@ -40,18 +44,15 @@ bool yellowLedON = false;
|
|||||||
Button *__buttons[4] = {nullptr};
|
Button *__buttons[4] = {nullptr};
|
||||||
ArduPID PID;
|
ArduPID PID;
|
||||||
|
|
||||||
void i2cScanner();
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
|
Serial.begin(9600);
|
||||||
{
|
|
||||||
Serial.println(F("SSD1306 allocation failed"));
|
|
||||||
for (;;)
|
|
||||||
; // Don't proceed further, loop forever
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Serial.println("Starting OLED");
|
||||||
|
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
|
||||||
|
|
||||||
|
//Set PWM frequency to 64 kHz
|
||||||
analogWriteFrequency(64);
|
analogWriteFrequency(64);
|
||||||
|
|
||||||
display.setRotation(3);
|
display.setRotation(3);
|
||||||
@ -59,8 +60,6 @@ void setup()
|
|||||||
pinMode(greenLED, OUTPUT);
|
pinMode(greenLED, OUTPUT);
|
||||||
pinMode(redLED, OUTPUT);
|
pinMode(redLED, OUTPUT);
|
||||||
|
|
||||||
Serial.begin(9600);
|
|
||||||
|
|
||||||
Serial.println("Starting LCD");
|
Serial.println("Starting LCD");
|
||||||
|
|
||||||
// tft.init(240, 320); // The dimensions (width and height) of your display
|
// tft.init(240, 320); // The dimensions (width and height) of your display
|
||||||
@ -92,99 +91,49 @@ void setup()
|
|||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
|
||||||
//Return the button that was pressed
|
// Return the button that was pressed
|
||||||
ButtonKind k = buttons.handleButtons();
|
ButtonKind k = buttons.handleButtons();
|
||||||
|
|
||||||
//Handle the buttons outside the main loop, only put functions in here for sanity and flow purposes
|
// Handle the buttons outside the main loop, only put functions in here for sanity and flow purposes
|
||||||
buttons.handleButtonLeds();
|
buttons.handleButtonLeds();
|
||||||
|
|
||||||
|
float sysVoltage = analogRef.calculateSystemVoltage();
|
||||||
|
float inputVoltage = analogRef.calculateInputVoltage();
|
||||||
|
int thermistor1Temp = thermistor1.getTemperature();
|
||||||
|
|
||||||
|
// Print the system voltage on the tft
|
||||||
|
|
||||||
/*
|
display.clearDisplay();
|
||||||
analogRef.calculate();
|
Serial.print("Thermistor 1: ");
|
||||||
|
Serial.println(thermistor1Temp);
|
||||||
|
char *text = "Sys V: ";
|
||||||
|
display.setTextSize(2);
|
||||||
|
display.setTextColor(SSD1306_WHITE);
|
||||||
|
display.setCursor(0, 20);
|
||||||
|
display.println(text);
|
||||||
|
display.setCursor(0, 40);
|
||||||
|
display.println(sysVoltage);
|
||||||
|
char *text2 = "In V: ";
|
||||||
|
display.setTextSize(2);
|
||||||
|
display.setTextColor(SSD1306_WHITE);
|
||||||
|
display.setCursor(0, 60);
|
||||||
|
display.println(text2);
|
||||||
|
display.setCursor(0, 80);
|
||||||
|
display.println(inputVoltage);
|
||||||
|
char *text3 = "C:";
|
||||||
|
display.setTextSize(2);
|
||||||
|
display.setTextColor(SSD1306_WHITE);
|
||||||
|
display.setCursor(0, 100);
|
||||||
|
display.println(text3);
|
||||||
|
display.setCursor(25, 100);
|
||||||
|
display.println(thermistor1Temp);
|
||||||
|
display.display();
|
||||||
|
|
||||||
float sysVoltage = analogRef.sysVoltage;
|
// Serial.println("System voltage: ");
|
||||||
float inputVoltage = analogRef.calculateInputVoltage();
|
|
||||||
|
|
||||||
// Print the system voltage on the tft
|
// Serial.print("Output voltage: ");
|
||||||
|
// Serial.println(sysVoltage);
|
||||||
|
|
||||||
display.clearDisplay();
|
// Serial.print("Input voltage: ");
|
||||||
Serial.print("Thermistor 1: ");
|
// Serial.println(analogRef.calculateInputVoltage());
|
||||||
Serial.println(thermistor1.getTemperature());
|
|
||||||
char *text = "Sys V: ";
|
|
||||||
display.setTextSize(2);
|
|
||||||
display.setTextColor(SSD1306_WHITE);
|
|
||||||
display.setCursor(0, 20);
|
|
||||||
display.println(text);
|
|
||||||
display.setCursor(0, 40);
|
|
||||||
display.println(sysVoltage);
|
|
||||||
char *text2 = "In V: ";
|
|
||||||
display.setTextSize(2);
|
|
||||||
display.setTextColor(SSD1306_WHITE);
|
|
||||||
display.setCursor(0, 60);
|
|
||||||
display.println(text2);
|
|
||||||
display.setCursor(0, 80);
|
|
||||||
display.println(inputVoltage);
|
|
||||||
char *text3 = "C:";
|
|
||||||
display.setTextSize(2);
|
|
||||||
display.setTextColor(SSD1306_WHITE);
|
|
||||||
display.setCursor(0, 100);
|
|
||||||
display.println(text3);
|
|
||||||
display.setCursor(25, 100);
|
|
||||||
display.println(thermistor1.getTemperature());
|
|
||||||
|
|
||||||
display.display();
|
|
||||||
|
|
||||||
// Serial.println("System voltage: ");
|
|
||||||
|
|
||||||
// Serial.print("Output voltage: ");
|
|
||||||
// Serial.println(sysVoltage);
|
|
||||||
|
|
||||||
// Serial.print("Input voltage: ");
|
|
||||||
// Serial.println(analogRef.calculateInputVoltage());
|
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void i2cScanner()
|
|
||||||
{
|
|
||||||
|
|
||||||
byte error, address;
|
|
||||||
int nDevices;
|
|
||||||
|
|
||||||
Serial.println("Scanning...");
|
|
||||||
|
|
||||||
nDevices = 0;
|
|
||||||
for (address = 1; address < 127; address++)
|
|
||||||
{
|
|
||||||
// The i2c_scanner uses the return value of
|
|
||||||
// the Write.endTransmisstion to see if
|
|
||||||
// a device did acknowledge to the address.
|
|
||||||
Wire.beginTransmission(address);
|
|
||||||
error = Wire.endTransmission();
|
|
||||||
|
|
||||||
if (error == 0)
|
|
||||||
{
|
|
||||||
Serial.print("I2C device found at address 0x");
|
|
||||||
if (address < 16)
|
|
||||||
Serial.print("0");
|
|
||||||
Serial.print(address, HEX);
|
|
||||||
Serial.println(" !");
|
|
||||||
|
|
||||||
nDevices++;
|
|
||||||
}
|
|
||||||
else if (error == 4)
|
|
||||||
{
|
|
||||||
Serial.print("Unknown error at address 0x");
|
|
||||||
if (address < 16)
|
|
||||||
Serial.print("0");
|
|
||||||
Serial.println(address, HEX);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (nDevices == 0)
|
|
||||||
Serial.println("No I2C devices found\n");
|
|
||||||
else
|
|
||||||
Serial.println("done\n");
|
|
||||||
|
|
||||||
delay(5000); // wait 5 seconds for next scan
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user