I have tried to solve my problem with help from difrent forums and in many ways. But now i am oute of options and need som help from you.
I using a OLED 1,3" SH1106. It works fine but the library <Adafruit_SH1106.h> is so damn large. Im only displaying a temperatur from a ds18b20 and it uses 56% storage space and 79% of dynamic memory.
One option is ofcourse buying a MEGA but i need to fit the build in a smal space so UNO or NANO is needed.
I have understand thats its posible to remove some of the library if Im only going to display text
Is it anyone out there that can help me how that is made?
Or ofcourse any other way of using that OLED whil useing less memmory (othe library etc)?
My code i run now is this:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int pushButton = 2;
void setup(void)
{
// Start serial communication for debugging purposes
Serial.begin(9600); // initialize the Serial Monitor at a baud rate of 9600
// Start up the library
sensors.begin(); // initialize the DS18B20 temperature sensor:
display.begin(SH1106_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
}
void loop(void) {
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.println(sensors.getTempCByIndex(0)); // get and print the temperature in degree Celsius
float T = sensors.getTempCByIndex(0); // let T be temperature in degC from sensor
// floating-point number, with a decimal point
String sT = String(T, 1);
delay(100);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Vatten: "); // display temperature in deg Celsius
display.setCursor(0, 20);
display.setTextSize(4);
display.print(sT);
display.println("C");
display.display(); // for the changes to make effect
}
Sketch uses 7538 bytes (23%) of program storage space. Maximum is 32256 bytes.
Global variables use 579 bytes (28%) of dynamic memory, leaving 1469 bytes for local variables. Maximum is 2048 bytes.
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 20/12/19
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - This program is a simple test program for the SSD1306 and SH1106 OLEDs. The program
prints a short message on each line, pauses, clears the screen, and starts again.
OLED address is defined as 0x3C.
Screen write on 8Mhz Atmel 170mS.
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#include <U8x8lib.h> //get library here > https://github.com/olikraus/u8g2
//U8X8_SSD1306_128X64_NONAME_HW_I2C disp(U8X8_PIN_NONE); //use this line for standard 0.96" SSD1306
U8X8_SH1106_128X64_NONAME_HW_I2C disp(U8X8_PIN_NONE); //use this line for 1.3" OLED often sold as 1.3" SSD1306
#define OLED_Address 0x3C
uint16_t writecount;
uint32_t startwritemS, endwritemS, timemS;
void loop()
{
writecount++;
Serial.print(writecount);
Serial.print(F(" Writing to display"));
disp.setI2CAddress(OLED_Address << 1); //I2C address multiplied by 2, the lowest bit must be zero
disp.setFont(u8x8_font_chroma48medium8_r);
startwritemS = millis();
disp.clear();
screen1();
endwritemS = millis();
timemS = endwritemS - startwritemS;
disp.setCursor(8, 4);
disp.print(timemS);
disp.print(F("mS"));
Serial.print(F(" - done"));
Serial.print(timemS);
Serial.println(F("mS"));
delay(2000);
Serial.println(F("PowerSave display"));
disp.setPowerSave(1); //power save display, turns off
delay(2000);
disp.setPowerSave(0); //display back to normal
}
void screen1()
{
disp.setCursor(0, 0);
disp.print(F("Hello World !"));
disp.setCursor(0, 1);
disp.print(F("Line 1"));
disp.setCursor(0, 2);
disp.print(F("Line 2"));
disp.setCursor(0, 3);
disp.print(F("Line 3"));
disp.setCursor(0, 4);
disp.print(F("Line 4"));
disp.setCursor(0, 5);
disp.print(F("Line 5"));
disp.setCursor(0, 6);
disp.print(F("Line 6"));
disp.setCursor(0, 7);
disp.print(F("0123456789012345")); //display is 8 lines x 16 charaters when using the
//u8x8_font_chroma48medium8_r font
}
void setup()
{
Serial.begin(9600);
Serial.println(F("31_SSD1306_OLED_Checker starting"));
disp.begin();
}