Go Down

Topic: Using SSD1306 OLED (Read 43 times) previous topic - next topic

ArtificerJon

I have successfully written a test sketch to drive an SSD1306 OLED display using the Adafruit library on a NANO.  However when I merged the test code with the rest of my main code (to run on an UNO) and then verfied I get an error message which appears to relate to the library call, the error message is :

'Adafruit_SSD1306 display' redeclared as different kind of symbol

My code (as yet incomplete as the "display" function needs parameters and is not yet being called from the main loop) is :

int TimerPin = 4;
int PumpPin = 5;
int HeaterPin = 6;
int PwrLedPin = 7;
int StatLedPin = 8;
int PumpLedPin = 9;
int HeatLedPin = 10;
int h2oTempPin = A0;
int h2oTempSP = A1;
int h2oTemp = 0;
int h2oSP = 0;
int DeadBand = 2;

Adafruit_SSD1306 display(OLED_RESET);

void setup()
{
  pinMode(WallStatPin, INPUT); // Wall thermostat with 1K pull down.
  pinMode(TimerPin, INPUT); // Indicates if timer-clock requires heating control.
  pinMode(PumpPin, OUTPUT); // Turn punp on.
  pinMode(HeaterPin, OUTPUT); // Turn heater on.
  pinMode(PwrLedPin, OUTPUT); // Indicates if unit is powered up.
  pinMode(StatLedPin, OUTPUT); // Indicates if Wall Stat' is demanding heat.
  pinMode(PumpLedPin, OUTPUT); // Indicates if pump shuld be running.
  pinMode(HeatLedPin, OUTPUT); // Indicates if heater should be on.
  pinMode(h2oTempPin, INPUT); //Analogue signal of water temperature
  pinMode(h2oTempSP, INPUT); //Analogue signal of temperature set point
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
 
  Serial.begin(9600); //todo - remove on final version
}

void loop() {
  /*
 The raw value of h2oVal will be between about 501 & 610 when
 the sensor is the botton component of a voltage divider with a
 1K resistor as the top component.  The resistance of the sensor
 varies between 960ohms and 1400ohms when the temperatures
 varies between 17 and 80 degrees. The voltage at the junction
 at about 17 degrees will be 2.45V and at 80 degrees it will be
 about 2.95V.
 */
// Read analogue inputs :
  int h2oVal = analogRead(h2oTempPin); //Read current value of sensor
  int spVal =  analogRead(h2oTempSP); //Read value of temp' set point

// The raw values are converted to degrees C with the Map function
  h2oTemp = map(h2oVal, 501, 610, 17, 80); // Convert to degrees
  h2oSP = map(spVal, 0, 1023, 20, 80); // Convert to degrees

// Main decision loop :

// Should the heater be on ?
if (h2oTemp <= (h2oSP - (DeadBand/2)) && (PumpPin == HIGH))
    {
      HeaterPin = HIGH; // If YES.
    }
else if (h2oTemp >= (h2oSP + (DeadBand/2)) || (PumpPin == LOW))
    {
      HeaterPin = LOW; // If NO.
    }

// Should the pump run ? NOTE : Contact senses are inverted
if ((WallStatPin == LOW) && (TimerPin == LOW))
    {
      PumpPin = HIGH; // If YES.
    }
else
    {
      PumpPin = LOW; // If NO.
    }

  Serial.print(h2oVal); //todo - remove on final version
  Serial.println(h2oTemp); //todo - remove on final version
  delay(1000); //todo - remove on final version
}

void display()
{
display.clearDisplay();
 
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(41,0);
  display.print("Heater :");

  display.setCursor(95,0);
  display.print("OFF");
 
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(53,14);
  display.print("Pump : ");

  display.setCursor(95,14);
  display.print("ON");
 
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(18,28);
  display.print("Water Temp :");

  display.setCursor(95,28);
  display.print("SAT");
 
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(24,42);
  display.print("Room Temp :");

  int roomTemp = digitalRead(WallStatPin); //Note WallStatPin=HIGH when Temp=LOW

  if (roomTemp != LOW)
  {
  display.setCursor(95,42);
  display.print("LOW");
  }
  else
  {
  display.setCursor(95,42);
  display.print("SAT");
  }
 
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(18,56);
  display.print("Time Clock :");
 
  display.setCursor(95,56);
  display.print("ON");
 
  display.display();
  delay(1000);

  Serial.println(roomTemp);
}

Any ideas ?

PaulS

Code: [Select]
if (h2oTemp <= (h2oSP - (DeadBand/2)) && (PumpPin == HIGH))
You have defined PumpPin to be 5. 5 is NOT HIGH.

You have an object named display. You have a function named display. Names MUST be unique.

Code: [Select]
      HeaterPin = HIGH; // If YES.
Changing the VALUE in HeaterPin will NOT change the STATE of any pin.
The art of getting good answers lies in asking good questions.

Go Up