Help with U8glib text formatation

Hello, would I be asking to much by requesting a code piece to print the variables I have in the way they are in the picture? When I tried to use u8g.drawStr along with u8g.print to print the variables I wanted in the screen it just didn’t work. The variables are: 2 digit temperature, 2 pairs of 2 digit hour and minutes and days months and year (like the static example in the picture).

This code is a modified hello world to test the layout.

#include "U8glib.h"
U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE);

void draw(void) {
  // graphic commands to redraw the complete screen should be placed here
  u8g.setFont(u8g_font_7x13B);
  //u8g.setFont(u8g_font_osb21);
  u8g.drawStr( 0, 14, "Al: 88:88Z T:15C°");
  u8g.drawStr( 0, 30, "88:88Z 88/88/8888");
}

void setup(void) {
  // flip screen, if required
  // u8g.setRot180();

  // set SPI backup if required
  //u8g.setHardwareBackup(u8g_backup_avr_spi);

  // assign default color value
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255, 255, 255);
  }
  pinMode(12, OUTPUT);
  digitalWrite(12, 1);
  pinMode(8, OUTPUT);

}

void loop(void) {
  // picture loop
  u8g.firstPage();
  do {
    draw();
  } while ( u8g.nextPage() );

  // rebuild the picture after some delay
  //delay(50);
}

And this one is the one I plan to use the display with.

//Caio Poit's wake up light 2018/02/14.
//https://github.com/JChristensen/DS3232RTC
/*


*/

#include <Wire.h>
#include <TimeLib.h>
#include <DS3232RTC.h>
#include "U8glib.h"
U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE);  // OLED Lib stuff...
#define LightLevelPin 9
#define LightOffPin 3
#define ButtonH 10
#define ButtonM 11
#define AlarmPin 2
#define IndicatorLED 13
#define optionOne_ms  50
#define optionTwo_ms  200
double LightLevel = 0;
double Base = 0.0039215;
unsigned int pressLengthH_ms = 0;
unsigned int pressLengthM_ms = 0;
unsigned long LastPressH = 0;
unsigned long LastPressM = 0;
unsigned int 4temp;
unsigned int temp;
byte AlarmH = 6;
byte AlarmM = 30;     // Set 30 minutes before wake time
volatile boolean WakeBoss = false;
volatile boolean ButPrsd = false;

void wakeshining();
void buttonH();
void buttonM();
void draw();

void setup() {
  pinMode(12, OUTPUT);
  digitalWrite(12, HIGH);
  pinMode(LightLevelPin, OUTPUT);
  pinMode(IndicatorLED, OUTPUT);
  pinMode(AlarmPin, INPUT_PULLUP);
  pinMode(LightOffPin, INPUT_PULLUP);
  pinMode(ButtonH, INPUT_PULLUP);
  pinMode(ButtonM, INPUT_PULLUP);
  RTC.setAlarm(ALM2_MATCH_DATE, 0, 0, 0, 1);
  RTC.alarm(ALARM_2);
  RTC.alarmInterrupt(ALARM_1, false);
  RTC.alarmInterrupt(ALARM_2, false);
  RTC.squareWave(SQWAVE_NONE);
  RTC.setAlarm(ALM2_MATCH_HOURS, 0, AlarmM, AlarmH, 0);
  RTC.alarm(ALARM_2);
  RTC.squareWave(SQWAVE_NONE);
  RTC.alarmInterrupt(ALARM_2, true);
  attachInterrupt(digitalPinToInterrupt(AlarmPin), waketheboss, FALLING);
  cli();      //disable interrupts when attaching
  attachInterrupt(digitalPinToInterrupt(LightOffPin), buttonpressed, FALLING); //INT1 pin 3
  EIFR |= (1 << INTF1);       //clear interrupt flag by writing bit
  sei();      //reenable interrupts
  setPwmFrequency(LightLevelPin, 1);
  ( u8g.getMode() == U8G_MODE_R3G3B2 ) ;
  //  u8g.setColorIndex(255);
  4temp = RTC.temperature();
  temp = 4temp / 4;

}


void loop() {

  if (WakeBoss == true) {
    digitalWrite(IndicatorLED, HIGH);
    wakeshining();
  }
  if (ButPrsd == true) {
    digitalWrite(LightLevelPin, LOW);
    digitalWrite(IndicatorLED, LOW);
    RTC.setAlarm(ALM2_MATCH_DATE, 0, 0, 0, 1);
    RTC.alarm(ALARM_1);
    RTC.alarm(ALARM_2);
    RTC.alarmInterrupt(ALARM_1, false);
    RTC.alarmInterrupt(ALARM_2, false);
    RTC.setAlarm(ALM2_MATCH_HOURS, 0, AlarmM, AlarmH, 0);
    digitalWrite(IndicatorLED, LOW);
    ButPrsd = false;
  }
  buttonH();
  buttonM();
}

void waketheboss() {
  WakeBoss = true;
}

void wakeshining() {

  while (LightLevel < 255) {  // 1020 increments up to 255, 1,764 seconds X 1020 = 30 mins.
    for (float f = 0; f < 83000; f++) {}       // About 1 sec of delay per line
    for (float f = 0; f < 63470; f++) {}       // About 0,764 sec of delay per line
    analogWrite(LightLevelPin, LightLevel);
    LightLevel = pow(Base, 4) + 1 ;            //y=x^4...
    Base = Base + 0.0039215;

    if (ButPrsd == true) {
      digitalWrite(LightLevelPin, LOW);
      digitalWrite(IndicatorLED, LOW);
      RTC.setAlarm(ALM2_MATCH_DATE, 0, 0, 0, 1);
      RTC.alarm(ALARM_1);
      RTC.alarm(ALARM_2);
      RTC.alarmInterrupt(ALARM_1, false);
      RTC.alarmInterrupt(ALARM_2, false);
      RTC.setAlarm(ALM2_MATCH_HOURS, 0, AlarmM, AlarmH, 0);
      digitalWrite(IndicatorLED, LOW);
      ButPrsd = false;
      break;
    }
  }

  WakeBoss = false;
  digitalWrite(IndicatorLED, LOW);
}

void buttonH() {

  while (digitalRead(ButtonH) == LOW ) {
    pressLengthH_ms = millis() - LastPressH;
    // Serial.print("ms = ");
    // Serial.println(pressLengthH_ms);
  }//close while

  if (pressLengthH_ms >= optionTwo_ms) {

  }

  if (pressLengthH_ms >= optionOne_ms && pressLengthH_ms < 200 ) {

  }

  if (pressLengthH_ms >= 500) {

  }

  LastPressH = millis();
  pressLengthH_ms = 0;
}
void buttonM() {
  while (digitalRead(ButtonM) == LOW ) {
    pressLengthM_ms = millis() - LastPressM;
    // Serial.print("ms = ");
    // Serial.println(pressLengthM_ms);
  }//close while

  if (pressLengthM_ms >= optionTwo_ms) {

  }

  if (pressLengthM_ms >= optionOne_ms && pressLengthM_ms < 200 ) {

  }

  if (pressLengthM_ms >= 500) {

  }

  LastPressM = millis();
  pressLengthM_ms = 0;

}


















void buttonpressed() {
  ButPrsd = true;
}

void setPwmFrequency(int pin, int divisor) {
  byte mode;
  if (pin == 5 || pin == 6 || pin == 9 || pin == 10) {
    switch (divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 64: mode = 0x03; break;
      case 256: mode = 0x04; break;
      case 1024: mode = 0x05; break;
      default: return;
    }
    if (pin == 5 || pin == 6) {
      TCCR0B = TCCR0B & 0b11111000 | mode;
    } else {
      TCCR1B = TCCR1B & 0b11111000 | mode;
    }
  } else if (pin == 3 || pin == 11) {
    switch (divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 32: mode = 0x03; break;
      case 64: mode = 0x04; break;
      case 128: mode = 0x05; break;
      case 256: mode = 0x06; break;
      case 1024: mode = 0x07; break;
      default: return;
    }
    TCCR2B = TCCR2B & 0b11111000 | mode;
  }
}

oled example.jpg

it just didn't work.

Bummer. Since you did not define what the code did, or how that differs from what you want, sympathy is all we can offer, and I'm fresh out.

I lost the code that didn’t work...

Well, I wrote it again and it worked.

Here it is if someone needs it or part of it.

//Caio Poit's wake up light 2018/02/14.

#include <Wire.h>
#include <TimeLib.h>
#include <DS3232RTC.h>
#include "U8glib.h"
U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE);  // OLED Lib stuff...
#define LightLevelPin 9
#define LightOffPin 3
#define ButtonH 10
#define ButtonM 11
#define AlarmPin 2
#define IndicatorLED 13
double LightLevel = 0;
double Base = 0.0039215;
unsigned int pressLengthH_ms = 0;
unsigned int pressLengthM_ms = 0;
unsigned long LastPressH = 0;
unsigned long LastPressM = 0;
unsigned int ttttemp;
unsigned int temp;
byte AlarmH = 6;
byte AlarmM = 52;     // Set 30 minutes before wake time
volatile boolean WakeBoss = false;
volatile boolean ButPrsd = false;

void wakeshining();
void buttonH();
void buttonM();
void draw();

void setup() {
  pinMode(12, OUTPUT);
  digitalWrite(12, HIGH);
  pinMode(LightLevelPin, OUTPUT);
  pinMode(IndicatorLED, OUTPUT);
  pinMode(AlarmPin, INPUT_PULLUP);
  pinMode(LightOffPin, INPUT_PULLUP);
  pinMode(ButtonH, INPUT_PULLUP);
  pinMode(ButtonM, INPUT_PULLUP);
  RTC.setAlarm(ALM2_MATCH_DATE, 0, 0, 0, 1);
  RTC.alarm(ALARM_2);
  RTC.alarmInterrupt(ALARM_1, false);
  RTC.alarmInterrupt(ALARM_2, false);
  RTC.squareWave(SQWAVE_NONE);
  RTC.setAlarm(ALM2_MATCH_HOURS, 0, AlarmM, AlarmH, 0);
  RTC.alarm(ALARM_2);
  RTC.alarmInterrupt(ALARM_2, true);
  attachInterrupt(digitalPinToInterrupt(AlarmPin), waketheboss, FALLING);
  cli();      //disable interrupts when attaching
  attachInterrupt(digitalPinToInterrupt(LightOffPin), buttonpressed, FALLING); //INT1 pin 3
  EIFR |= (1 << INTF1);       //clear interrupt flag by writing bit
  sei();      //reenable interrupts
  setPwmFrequency(LightLevelPin, 1);
  ( u8g.getMode() == U8G_MODE_R3G3B2 ) ;
  //  u8g.setColorIndex(255);
  ttttemp = RTC.temperature();
  temp = ttttemp / 4;

}


void loop() {

  if (WakeBoss == true) {
    digitalWrite(IndicatorLED, HIGH);
    wakeshining();
  }
  if (ButPrsd == true) {
    cli();
    EIFR |= (1 << INTF1);
    sei();
    digitalWrite(LightLevelPin, LOW);
    digitalWrite(IndicatorLED, LOW);
    RTC.alarm(ALARM_2);
    RTC.alarmInterrupt(ALARM_1, false);
    RTC.alarmInterrupt(ALARM_2, false);
    RTC.setAlarm(ALM2_MATCH_HOURS, 0, AlarmM, AlarmH, 0);
    ButPrsd = false;
    digitalWrite(IndicatorLED, HIGH);
    delay(100);
    digitalWrite(IndicatorLED, LOW);
    delay(100);
    digitalWrite(IndicatorLED, HIGH);
    delay(100);
    digitalWrite(IndicatorLED, LOW);
    delay(100);
  }
  buttonH();
  buttonM();

  ttttemp = RTC.temperature();
  temp = ttttemp / 4;

  u8g.firstPage();
  do {
    draw();
  } while ( u8g.nextPage() );


}


void draw(void) {
  u8g.setFont(u8g_font_7x13B);
  u8g.setPrintPos(91, 14);
  u8g.print(temp);
  // u8g.drawStr( 0, 14, "Al: 88:88Z T:  C°");
  u8g.drawStr( 0, 14, "Al:   :  Z T:  C°");
  u8g.drawStr( 0, 30, "  :  Z   /  /    ");
  u8g.setPrintPos(29, 14);
  u8g.print(AlarmH);
  u8g.setPrintPos(49, 14);
  u8g.print(AlarmM);

  tmElements_t tm;
  RTC.read(tm);
  u8g.setPrintPos(0, 30);
  u8g.print(tm.Hour, DEC);
  u8g.setPrintPos(21, 30);
  u8g.print(tm.Minute, DEC);

  u8g.setPrintPos(50, 30);
  u8g.print(tm.Day, DEC);
  u8g.setPrintPos(71, 30);
  u8g.print(tm.Month, DEC);
  u8g.setPrintPos(93, 30);
  u8g.print(tm.Year + 1970, DEC);

}

void waketheboss() {
  WakeBoss = true;
}

void wakeshining() {

  while (LightLevel < 255) {  // 1020 increments up to 255, 1,764 seconds X 1020 = 30 mins.
    for (float f = 0; f < 83000; f++) {}       // About 1 sec of delay per line
    for (float f = 0; f < 63470; f++) {}       // About 0,764 sec of delay per line
    analogWrite(LightLevelPin, LightLevel);
    LightLevel = pow(Base, 4) + 1 ;            //y=x^4...
    Base = Base + 0.0039215;

    if (ButPrsd == true) {
      cli();
      EIFR |= (1 << INTF1);
      sei();
      digitalWrite(LightLevelPin, LOW);
      digitalWrite(IndicatorLED, LOW);
      RTC.setAlarm(ALM2_MATCH_DATE, 0, 0, 0, 1);
      RTC.alarm(ALARM_2);
      RTC.alarmInterrupt(ALARM_1, false);
      RTC.alarmInterrupt(ALARM_2, false);
      RTC.setAlarm(ALM2_MATCH_HOURS, 0, AlarmM, AlarmH, 0);
      digitalWrite(IndicatorLED, LOW);
      ButPrsd = false;
      break;
    }
  }

  WakeBoss = false;
  digitalWrite(IndicatorLED, LOW);
}

void buttonH() {

  while (digitalRead(ButtonH) == LOW ) {
    pressLengthH_ms = millis() - LastPressH;
    // Serial.print("ms = ");
    // Serial.println(pressLengthH_ms);
  }

  if (pressLengthH_ms > 50 && pressLengthH_ms < 500 ) {

    if (AlarmH < 23) {
      AlarmH = AlarmH + 1;
    }
    else {
      AlarmH = 0;
    }
    digitalWrite(IndicatorLED, HIGH);
  }

  if (pressLengthH_ms >= 500) {

  }

  LastPressH = millis();
  pressLengthH_ms = 0;
}
void buttonM() {
  while (digitalRead(ButtonM) == LOW ) {
    pressLengthM_ms = millis() - LastPressM;
    // Serial.print("ms = ");
    // Serial.println(pressLengthM_ms);
  }

  if (pressLengthM_ms > 50 && pressLengthM_ms < 500 ) {

    if (AlarmM < 55) {
      AlarmM = AlarmM + 5;
    }
    else {
      AlarmM = 0;
    }
    digitalWrite(IndicatorLED, HIGH);
  }

  if (pressLengthM_ms >= 500) {

  }

  LastPressM = millis();
  pressLengthM_ms = 0;

}






void buttonpressed() {
  ButPrsd = true;
}

void setPwmFrequency(int pin, int divisor) {
  byte mode;
  if (pin == 5 || pin == 6 || pin == 9 || pin == 10) {
    switch (divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 64: mode = 0x03; break;
      case 256: mode = 0x04; break;
      case 1024: mode = 0x05; break;
      default: return;
    }
    if (pin == 5 || pin == 6) {
      TCCR0B = TCCR0B & 0b11111000 | mode;
    } else {
      TCCR1B = TCCR1B & 0b11111000 | mode;
    }
  } else if (pin == 3 || pin == 11) {
    switch (divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 32: mode = 0x03; break;
      case 64: mode = 0x04; break;
      case 128: mode = 0x05; break;
      case 256: mode = 0x06; break;
      case 1024: mode = 0x07; break;
      default: return;
    }
    TCCR2B = TCCR2B & 0b11111000 | mode;
  }
}