mirror of
https://github.com/arwidcool/Solder-Plate.git
synced 2024-11-28 08:20:52 +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:
|
||||
float systemVoltage; // Reference voltage in volts
|
||||
|
||||
boolean systemVolatgeBelow4_5V = false;
|
||||
uint8_t voltageRefPin = 27;
|
||||
|
||||
uint8_t voltageInPin = 28;
|
||||
|
||||
public:
|
||||
float sysVoltage;
|
||||
float sysMultiplyer;
|
||||
float outputVoltage;
|
||||
float outputVoltageMultiplyer;
|
||||
float differenceMultiplyer;
|
||||
float inputVoltage;
|
||||
|
||||
//Set what the system voltage SHOULD be
|
||||
AnalogRef(float systemVoltage)
|
||||
{
|
||||
this->systemVoltage = systemVoltage;
|
||||
}
|
||||
|
||||
|
||||
//Calculate the system voltage
|
||||
float calculateSystemVoltage()
|
||||
{
|
||||
const uint8_t sampleCount = 1;
|
||||
|
||||
const uint8_t SAMPLE_COUNT = 1;
|
||||
const float VOLTAGE_REF = 1023.0;
|
||||
uint16_t rawValue = 0;
|
||||
|
||||
for (size_t i = 0; i < sampleCount; ++i)
|
||||
for (size_t i = 0; i < SAMPLE_COUNT; ++i)
|
||||
{
|
||||
rawValue += analogRead(voltageRefPin);
|
||||
}
|
||||
|
||||
const float voltageRef = 1023.0;
|
||||
const float systemVoltage = 5.0;
|
||||
const float systemVoltageOut = rawValue / sampleCount * systemVoltage / voltageRef;
|
||||
const float voltage5V = 2.5 / systemVoltageOut * systemVoltage;
|
||||
|
||||
systemVolatgeBelow4_5V = voltage5V < 4.5;
|
||||
float meanRawValue = (float)rawValue / SAMPLE_COUNT;
|
||||
float outputVoltage = meanRawValue / VOLTAGE_REF * systemVoltage;
|
||||
float voltage5V = 2.5 / outputVoltage * systemVoltage;
|
||||
|
||||
return voltage5V;
|
||||
}
|
||||
|
||||
//Used for external voltage readings not powered by the 5V system
|
||||
float calculateSystemVoltageMultyplyer()
|
||||
{
|
||||
|
||||
@ -58,6 +55,8 @@ public:
|
||||
return voltage_5V_multiplyer;
|
||||
}
|
||||
|
||||
|
||||
//Calculate the input voltage of the power supply
|
||||
float calculateInputVoltage()
|
||||
{
|
||||
|
||||
@ -80,12 +79,7 @@ public:
|
||||
return vOut * 5.8;
|
||||
}
|
||||
|
||||
void calculate()
|
||||
{
|
||||
|
||||
sysVoltage = calculateSystemVoltage();
|
||||
sysMultiplyer = 5 / sysVoltage;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // ANALOGREF_H
|
||||
|
@ -72,9 +72,7 @@ void Thermistor::calculateCoefficents(float resistance, TempCalibration calibrat
|
||||
float Thermistor::getResistance()
|
||||
{
|
||||
|
||||
analogRef.calculate();
|
||||
|
||||
float systemVoltage = analogRef.sysVoltage;
|
||||
float systemVoltage = analogRef.calculateSystemVoltage();
|
||||
|
||||
int raw = analogRead(thermistorPin);
|
||||
|
||||
@ -84,9 +82,7 @@ float Thermistor::getResistance()
|
||||
// Serial.println(vOut);
|
||||
buffer = (systemVoltage / vOut) - 1;
|
||||
|
||||
// Serial.println(R2);
|
||||
// return the resistence
|
||||
|
||||
sensorResistance = setRes * buffer;
|
||||
|
||||
return sensorResistance;
|
||||
|
79
src/main.cpp
79
src/main.cpp
@ -20,7 +20,6 @@ TempCalibration calibration_100K_3950 = {25, 100000, 86, 10000, 170, 1000};
|
||||
#define TFT_DC 14
|
||||
#define MOSI 4 // MOSI
|
||||
#define SCK 6 // SCK
|
||||
|
||||
// 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);
|
||||
|
||||
@ -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
|
||||
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();
|
||||
|
||||
@ -40,18 +44,15 @@ bool yellowLedON = false;
|
||||
Button *__buttons[4] = {nullptr};
|
||||
ArduPID PID;
|
||||
|
||||
void i2cScanner();
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
|
||||
{
|
||||
Serial.println(F("SSD1306 allocation failed"));
|
||||
for (;;)
|
||||
; // Don't proceed further, loop forever
|
||||
}
|
||||
Serial.begin(9600);
|
||||
|
||||
Serial.println("Starting OLED");
|
||||
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
|
||||
|
||||
//Set PWM frequency to 64 kHz
|
||||
analogWriteFrequency(64);
|
||||
|
||||
display.setRotation(3);
|
||||
@ -59,8 +60,6 @@ void setup()
|
||||
pinMode(greenLED, OUTPUT);
|
||||
pinMode(redLED, OUTPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
Serial.println("Starting LCD");
|
||||
|
||||
// tft.init(240, 320); // The dimensions (width and height) of your display
|
||||
@ -98,19 +97,15 @@ void loop()
|
||||
// Handle the buttons outside the main loop, only put functions in here for sanity and flow purposes
|
||||
buttons.handleButtonLeds();
|
||||
|
||||
|
||||
|
||||
/*
|
||||
analogRef.calculate();
|
||||
|
||||
float sysVoltage = analogRef.sysVoltage;
|
||||
float sysVoltage = analogRef.calculateSystemVoltage();
|
||||
float inputVoltage = analogRef.calculateInputVoltage();
|
||||
int thermistor1Temp = thermistor1.getTemperature();
|
||||
|
||||
// Print the system voltage on the tft
|
||||
|
||||
display.clearDisplay();
|
||||
Serial.print("Thermistor 1: ");
|
||||
Serial.println(thermistor1.getTemperature());
|
||||
Serial.println(thermistor1Temp);
|
||||
char *text = "Sys V: ";
|
||||
display.setTextSize(2);
|
||||
display.setTextColor(SSD1306_WHITE);
|
||||
@ -131,8 +126,7 @@ void loop()
|
||||
display.setCursor(0, 100);
|
||||
display.println(text3);
|
||||
display.setCursor(25, 100);
|
||||
display.println(thermistor1.getTemperature());
|
||||
|
||||
display.println(thermistor1Temp);
|
||||
display.display();
|
||||
|
||||
// Serial.println("System voltage: ");
|
||||
@ -142,49 +136,4 @@ void loop()
|
||||
|
||||
// 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…
Reference in New Issue
Block a user