RESOLVED - Smart Watch Arduino OLED Display u8glib library problem.

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi! 

I'm trying to create a simple Smart Watch. For testing, I'm using my Arduino UNO board.

The clock is quite simple: I connect the clock via Bluetooth with a simple application that I developed in MIT App Inventor 2.

  When you press a push button, characters are sent to this app. Each character sends a smartphone information to the Arduino back.

 

Example: I pressed the push button and the "h" character was sent. The application sends the time and date to the Arduino. If I press the push button again, this time, the "c" character is sent. The application sends information about the weather. And so it goes.

 

If the phone receives an SMS or a missed call, the warning is automatically made.

 

 

   Using Serial.println(), I can see that the data is being sent correctly by the Android application to the Arduino. But my OLED Display doesn't show the incoming information. The "Welcome" screen doesn't change.

 

What's wrong with my code?

 


#include "U8glib.h"
#include "pitches.h" 

#define LINE_MAX 30 

#define ROW_MAX 12

uint8_t screen[ROW_MAX][LINE_MAX];

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);

String recebido ="";
String recebido2 ="";

int buttonState;  

int pwm = 11;

int button = A1;

int buttonpress = 0;

int melodyMario[]={NOTE_DS6, NOTE_DS6, NOTE_DS6, NOTE_B5, NOTE_DS6, NOTE_FS6};
int melodyFF[]={NOTE_D6, NOTE_D6, NOTE_D6, NOTE_D6, NOTE_AS5, NOTE_C6, NOTE_D6, NOTE_C6, NOTE_D6};
int melodyPRangers[]={NOTE_CS6, NOTE_CS6, NOTE_B5, NOTE_CS6, NOTE_E6, NOTE_CS6};
int melodySSantos[]={NOTE_A6, NOTE_A6, NOTE_GS6, NOTE_GS6, NOTE_FS6,NOTE_FS6,NOTE_CS6,NOTE_FS6,NOTE_E6,NOTE_E6,NOTE_D6,NOTE_D6};
int melodyClock[]={NOTE_E5, NOTE_E5, NOTE_CS5,NOTE_CS5, NOTE_D5, NOTE_D5,NOTE_B4,NOTE_B4,NOTE_D5,NOTE_D5,NOTE_B4,NOTE_B4,NOTE_E5, NOTE_E5, NOTE_CS5,NOTE_CS5,};
int melodySamsung[]={NOTE_B5, NOTE_DS6, NOTE_B6,NOTE_AS6, NOTE_FS6};
int melodyAloAlo[]={NOTE_B4, NOTE_B4, NOTE_C5,NOTE_D5, 0, NOTE_B6, NOTE_A6, NOTE_G6 };

int noteDurations1[]={8, 4, 4, 8, 4, 2};
int noteDurations2[]={8, 8, 8, 4,4, 4,  8, 8, 2};
int noteDurations3[]={4, 4, 8, 4, 4, 4};
int noteDurations4[]={4, 4, 4, 4, 8, 4,8,8,8,4,8,4};
int noteDurations5[]={8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 4};
int noteDurations6[]={8, 8, 8, 4, 4};
int noteDurations7[]={8, 8, 8, 4, 4, 4, 4, 4};

void setup(void) {

  Serial.begin(9600);

pinMode(button, INPUT_PULLUP);      

   pinMode (pwm, OUTPUT);
  digitalWrite (pwm, LOW);

  u8g.firstPage();
  do {
    drawWelcome();

  } while( u8g.nextPage() );

}//end SETUP here

void drawWelcome(){

 u8g.setFont(u8g_font_fixed_v0);

   u8g.drawStr( 0, 10, "Hi, Marco!");
    u8g.drawStr( 0, 40, "Welcome!");

}

void loop(void) {

if(Serial.available()>0){

recebido = Serial.readStringUntil('#');
     recebido2 = Serial.readString();
}

buttonState = digitalRead(button);

if(buttonState == LOW){

    buttonpress ++;

switch(buttonpress){

case 1:
Moraes();

 delay(500);

do {
Serial.print("h");// to call info about time and date
draw();
  } while( u8g.nextPage() );

break;  

case 2:
FF();

do {
Serial.print("c"); // to call info about weather
draw(); 

  } while( u8g.nextPage() );

break;  

case 3:
Mario();

do {
Serial.print("l"); // to call info about local address
draw();

  } while( u8g.nextPage() );

break;  

case 4:
PowerRangers();

do {
Serial.print("b"); // to call info about battery
draw();

  } while( u8g.nextPage() );

  buttonpress = 0;

break;

}//END SWITCH  

  if(recebido.equals("SMS from:")) {

   digitalWrite (pwm, HIGH);
   Msg();
     delay (2000);
     digitalWrite (pwm, LOW);

do {
draw();

  } while( u8g.nextPage() );

    delay (3000);

buttonpress = 0;

    }

if(recebido.equals("Marco, phonecall from: ")){

         digitalWrite (pwm, HIGH);
         Phone();
     delay (2000);
     digitalWrite (pwm, LOW);

do {
draw();

  } while( u8g.nextPage() );

     delay (3000);
buttonpress=0;

     }

}//END IF BUTTON STATE   

}//END LOOP

void draw(void){
if(recebido.length()>0){
    u8g.setFont(u8g_font_fixed_v0);

u8g.drawStr(0, 10, recebido.c_str());
u8g.drawStr(0, 40, recebido2.c_str());
}
}

void clear_screen(void)  {
 uint8_t i, j;
  for( i = 0; i < ROW_MAX; i++ )
 for( j = 0; j < LINE_MAX; j++ )
     screen[i][j] = 0;
 }

void FF(){

for (int thisNote=0; thisNote <9; thisNote++){

      //to calculate the note duration, take one second. Divided by the note type
      int noteDuration2 = 1000 / noteDurations2 [thisNote];
      tone(7, melodyFF [thisNote], noteDuration2);

      //to distinguish the notes, set a minimum time between them
      //the note's duration +30% seems to work well
      int pauseBetweenNotes = noteDuration2 * 1.30;
      delay(pauseBetweenNotes);

      //stop the tone playing
      noTone(7);
    }

}

void Mario(){

for (int thisNote=0; thisNote <6; thisNote++){

      //to calculate the note duration, take one second. Divided by the note type
      int noteDuration1 = 1000 / noteDurations1 [thisNote];
      tone(7, melodyMario [thisNote], noteDuration1);

      //to distinguish the notes, set a minimum time between them
      //the note's duration +30% seems to work well
      int pauseBetweenNotes = noteDuration1 * 1.30;
      delay(pauseBetweenNotes);

      //stop the tone playing
      noTone(7);
}

}

void PowerRangers(){

    //iterate over the notes of the melody
    for (int thisNote=0; thisNote <6; thisNote++){

      //to calculate the note duration, take one second. Divided by the note type
      int noteDuration = 800 / noteDurations3 [thisNote];
      tone(7, melodyPRangers [thisNote], noteDuration);

      //to distinguish the notes, set a minimum time between them
      //the note's duration +30% seems to work well
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);

      //stop the tone playing
      noTone(7);
    }

}

void Silvio(){

//iterate over the notes of the melody
    for (int thisNote=0; thisNote <12; thisNote++){

      //to calculate the note duration, take one second. Divided by the note type
      int noteDuration = 1000 / noteDurations4 [thisNote];
      tone(7, melodySSantos [thisNote], noteDuration);

      //to distinguish the notes, set a minimum time between them
      //the note's duration +30% seems to work well
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);

      //stop the tone playing
      noTone(7);
    }

}

void Moraes(){
 for (int thisNote=0; thisNote <16; thisNote++){

      //to calculate the note duration, take one second. Divided by the note type
      int noteDuration = 1300 / noteDurations5 [thisNote];
      tone(7, melodyClock [thisNote], noteDuration);

      //to distinguish the notes, set a minimum time between them
      //the note's duration +30% seems to work well
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);

      //stop the tone playing
      noTone(7);
    }

}

void Msg(){
  for (int thisNote=0; thisNote <5; thisNote++){

      //to calculate the note duration, take one second. Divided by the note type
      int noteDuration = 1000 / noteDurations6 [thisNote];
      tone(7, melodySamsung [thisNote], noteDuration);

      //to distinguish the notes, set a minimum time between them
      //the note's duration +30% seems to work well
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);

      //stop the tone playing
      noTone(7);
    }
}

void Phone(){
for (int thisNote=0; thisNote <8; thisNote++){

      //to calculate the note duration, take one second. Divided by the note type
      int noteDuration = 1200 / noteDurations7 [thisNote];
      tone(7, melodyAloAlo [thisNote], noteDuration);

      //to distinguish the notes, set a minimum time between them
      //the note's duration +30% seems to work well
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);

      //stop the tone playing
      noTone(7);
    }

}

 

 

Thank you.

"Wise people talk little and listen a lot."

Last Edited: Sun. Feb 10, 2019 - 07:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I fixed the sketche by changing parameters of the Serial.available (). In addition, I modified procedures for some functions. It is working, although as for getting information from the internet, it generates a lag and information doesn't always appear. However, it is working now. Problem solved. Thanks.

"Wise people talk little and listen a lot."