DS3231 OLED Alarm Clock With 2-button Menu Setting and Temperature Display

88,916

261

93

Introduction: DS3231 OLED Alarm Clock With 2-button Menu Setting and Temperature Display

UPDATE: V1.3 of clock packages uploaded with bug fix and enhancements. See below for details,

Video at:: http://youtu.be/ikNw1iLE9vg

Alarm demo video: http://youtu.be/jlZBCuQeswA

This is an OLED alarm clock I built using an Arduino Micro, a tiny OLED 128x64 display using the SSD1306 controller and I2C interface, and a precision DS3231-based real-time clock module with rechargeable battery backup. It features a menu system for setting the RTC (no serial port or USB required)

Two versions are shown - the basic digital/analog clock and a version with "Pusheen" graphics and animation.

It uses the Adafruit graphics libraries and DS3231 library, included in the distribution.

Code for both, including needed libraries, may be downloaded directly from the link below in Step 4.

v1.3

I fixed a problem with the v1.2 code that would cause compilation errors for any non-ATmega32U4 Arduino. I had added a compact "note" function to generate a frequency on Pin 10 if the "speaker" alarm output option was selected. The function I included uses the timer structures for ATmega32U4. In v1.3, I added a non-ATmega32U4 version of the "note" function and added conditional compilation directives to automatically compile the correct version. I also compile the "note" function only if the "speaker" output is selected, saving memory if any other output option is selected. I tested the code with all board types in the IDE and received no compilation errors.


v1.2

I fixed a bug that would cause the alarm to timeout after less than the full 60 seconds if the previous alarm was silenced with a button press.

The status of alarm enable/disable is now stored in EEPROM and will survive a power failure. Previously, the alarm was always enabled after a power failure.

If the clock is left in setting mode, it will return to the normal display after 30 seconds without a button press.

I moved the alarm enable/disable indicator from the analog clock to between the time and temperature.

When the alarm sounds, the entire display now flashes in inverse/normal video at 5 Hz until the alarm is silenced. Previously, an asterisk flashed within the analog clock.

There is an optional feature to dim the display between 10 PM and 5 AM. Uncomment this line at the beginning of the program to enable this feature.

//#define dimming

The behavior of the alarm output at Pin 10 of the Arduino can be selected by uncommenting ONE of the following lines at the beginning of the code:

The first option is the default and supplies an intermittent (5 Hz) voltage on pin 10 when the alarm is triggered.

//#define beeper //Uncomment if 5 volt continuous tone beeper or buzzer is connected to pin 10 (5 Hz output)

The second option supplies an intermittent (5 Hz) 1580 Hz tone on pin 10 when the alarm is triggered. Pin 10 should be connected to the + terminal of the speaker through a 0.5 to 1.0 microfarad capacitor and possibly a 150 ohm resistor. The capacitor blocks DC voltage from the speaker to preserve the magnet in the speaker from damage. Piezo speakers may be connected directly to Pin 10. Use the resistor for low-impedance (< 150 ohm) speakers.

//#define speaker //Uncomment if speaker is connected to pin 10 through 1 microfarad capacitor and 100 ohm resistor in series (1480 Hz at 5 Hz output)

The final option provides a steady +5 volts on Pin 10 as long as the alarm is active. The voltage drops to zero when the alarm is silent.

//#define voltage //Uncomment if pin 10 is connected to alarm device requiring steady output while alarm is activated

Step 1: Connect the DS3231 Module and 128x64 OLED Module to the Arduino

  • Connect ground connection from Arduino to the DS3231 RTC module and OLED display.
  • Connect +5v from the Arduino to the +5v connections on the DS3231 RTC module and OLED display.
  • Connect the pin assigned to the SCL function on your Arduino to the SCL pins on both the DS3231 module and the OLED display.
  • Connect the pin assigned to the SDA function on your Arduino to the SDA pins on both the DS3231 module and the OLED display.
  • Connect one side of two SPST normally open push buttons to an Arduino ground connection.
  • Connect the other side of one push button to pin 8 of the Arduino. This is the time/date/alarm set mode select button.
  • Connect the other side of the other push button to pin 9 of the Arduino. This is the time/date/alarm set change button.
  • Connect the black wire on a piezo 5 volt buzzer/beeper to the Arduino ground connection. Connect the red wire from the piezo buzzer/beeper to pin 10 of the Arduino. Be sure to use a piezo beeper (NOT a piezo speaker) that generates its own tone when 5 volts is applied. If you use a piezo speaker instead of a piezo beeper, it will only click rapidly when the alarm is triggered. A unit that sounds continuously when power is applied is best, as the code generates a 5Hz interrupted voltage source to pin 10 on its own. NEW!!! Speaker and continuous alarm output now supported. See Step 1 for details on how to enable.
  • Download either the regular or "Pusheen" version of the clock code from here or the link in the introduction.
  • Install the Arduino libraries in the software distribution .zip file.
  • Compile and download the code to your Arduino. The clock and display will start to run. NEW!!! Optional night display dimming supported. See Step 1 for details on how to enable.
  • Set the clock and alarm per the instructions in the next step.

Step 2: Set Your Clock

  • Press the mode set button , then release. The cursor will flash on the day-of-week field. Press and hold the set button to advance the day-of week to the next day at a 5Hz rate, or do a short press to advance to the next setting. Note: the RTC will use whatever day-of-week you set. It will not automatically calculate the day-of-week for the date and year.
  • Press and release the mode set button to advance the cursor to the month field. Press and hold the set button to scroll through the months quickly, or do a short press to advance to the next setting.
  • Press and release the mode set button to advance the cursor to the date field. Press and hold the set button to scroll through the dates quickly, or do a short press to advance to the next setting. Note that the clock chip knows the correct number of days in each month. However, you can set an illegal date for months with less than 31 days, like "February 30". If you do, the clock will advance the date at midnight until the 31st is reached, then roll over to the first. Thereafter, the date will roll over to 1 at the correct date for the set month. Just don't set an illegal date and all will be well!
  • Press and release the mode set button to advance the cursor to the year field. Press and hold the set button to scroll through the years quickly, or do a short press to advance to the next setting. Valid ranges are 2000 to 2099. The RTC keeps track of leap years automatically. When you first power up the clock, the date will be January 1, 1900. Just advance the year to the correct value as normal.
  • Press and release the mode set button to advance the cursor to the hour field. Press and hold the set button to scroll through the hours quickly, or do a short press to advance to the next setting. The clock uses only the 12--hour mode with AM/PM indications.
  • Press and release the mode set button to advance the cursor to the minutes field. Press and hold the set button to scroll through the minutes quickly, or do a short press to advance to the next setting.
  • Press and release the mode set button to advance the cursor to the seconds field. Press the button momentarily to reset the seconds to zero, or hold the button to freeze the seconds at zero and release to synchronize with an external time source.
  • Press and release the mode set button to advance to the alarm setting screen. Press and hold the set button to scroll through the alarm hours setting quickly, or do a short press to advance to the next setting.
  • Press and release the mode set button to advance to the alarm minutes setting field.Press and hold the set button to scroll through the alarm minutes setting quickly, or do a short press to advance to the next setting.

  • Press and release the mode set button to advance to the alarm enable/disable field. Press and hold the set button to toggle repeatedly between alarm on and off settings, or do a short press to advance to the alternate setting. Note that when the alarm is on, an asterisk appears between the time and temperature. When the alarm is triggered, the entire display flashes in inverse video. The piezo buzzer will also beep at a 5 Hz rate (default option). The alarm will time out after 60 seconds if not manually silenced. A short press of the set button silences the alarm, leaving it on for the next day. In the event of a power failure, the alarm enable flag state is stored in EEPROM and restored on power-up. If an alarm has occurred during the power failure and the alarm was enabled, the alarm will sound immediately when power is restored. The alarm will sound, even if the clock is left in the setting modes.

  • Press and release the mode set button to return to normal mode. The display will automatically exit setting mode 30 seconds after the last button press.

Step 3: Technical Details

The software enables a very accurate 1Hz PPS signal on the "SQW" pin of the DS3231 module.

The DS3231 module uses the temperature sensor to compensate for clock drift, keeping time accurate to 1 or 2 minutes/year.

The temperature is normally checked and updated by the RTC once every 64 seconds. However, the software forces a temperature reading and oscillator adjustment as often as 5 times/second. This results in better accuracy and faster updating of the temperature display.

The on-board battery is not a disposable Lithium, but a rechargeable Lithium Ion unit. When connected to power, the RTC module charges the battery. A fully charged battery will maintain the time setting for up to one year without applying additional power.

You can "freeze" the display at any point by pressing and holding the mode set button. When the button is released, updating will resume. Clock accuracy is not affected.

The clock module contains a 32K EEPROM chip that can be used for data storage. It has an independent I2C address. It is not used for this project.

The code should work with the Sparkfun Chronodot module.

Step 4:

Code and library downloads, in .zip archive.....

7 People Made This Project!

Recommendations

  • Fix It! Contest

    Fix It! Contest
  • Metalworking Contest

    Metalworking Contest
  • Water Contest

    Water Contest

93 Discussions

Arduino: 1.6.3 (Windows 7), Board: "Arduino Uno"

Build options changed, rebuilding all

Pusheen_Clock_Generic.ino: In function 'void set_alarm()':

Pusheen_Clock_Generic.ino:759:54: error: cannot convert 'boolean* {aka bool*}' to 'const uint8_t* {aka const unsigned char*}' for argument '5' to 'void DS3231_set_a1(uint8_t, uint8_t, uint8_t, uint8_t, const uint8_t*)'

Multiple libraries were found for "Adafruit_GFX.h"

Used: C:\Users\johnp51\Documents\Arduino\libraries\GFX

Not used: C:\Users\johnp51\Documents\Arduino\libraries\Adafruit-GFX-Library-master

Multiple libraries were found for "Adafruit_SSD1306.h"

Used: C:\Users\johnp51\Documents\Arduino\libraries\Adafruit_SSD1306-master

Not used: C:\Users\johnp51\Documents\Arduino\libraries\oled

Error compiling.

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences.

7 replies

I uploaded new packages with both errors fixed. It should work with old and new IDE versions.

The code for both versions is found on the last step of the Instructable. I tested just now. Both download links work fine.

Nice work! I just made one on proto board. Could you please kindly tell me where I can find the generic code with alarm and without pusheen? both codes are same on this page. I would like to incorporate it in an application with rotary encoder and data input with one hour to 24 hour alarm duration. That would be very useful in animal feed management. I have a feeder designed to feed my pigeons and dogs while I am away.

Hope to hear from you soon.

My best regards.

Felix

the code links are broken - can you provide the link for the non pusheen code?

The code for both versions is found on the last step of the Instructable. I tested just now. Both download links work fine.

It appears the latest IDEs have stricter type checking and require the changes mentioned in these board postings

http://forum.arduino.cc/index.php?topic=309872.0

http://forum.arduino.cc/index.php?topic=309119.0

Try this:

Change this line in both of the clock sketches within the set_alarm() function::

boolean flags[5] = { 0, 0, 0, 1, 1 }; //Set alarm to trigger every 24 hours on time match

...to this:

byte flags[5] = { 0, 0, 0, 1, 1 }; //Set alarm to trigger every 24 hours on time match

ALSO:

In the Adafruit_SSD1306.h header file in the Adafruit library, change:

void dim(uint8_t contrast);

to:

void dim(boolean contrast);

The clock sketches now compile and run correctly with IDE v1.6.4.

In both cases the issue is a type mismatch between "boolean" and "uint8_t". v1.06 of the IDE allowed it, but the newer IDE versions do not.

Best,

Don

that fixed it. thanks v1.6.5

Hello

Concerning first power up the clock, the date will be January 1, 1900...

Is it possible to change the library for start from January 1, 2000 ? and how to make it?

Thank you

3 replies

Add the following line after line 92 in the generic clock code or line 401 in the Pusheen graphics code:

if (t.year < 2000) {t.year = 2000; set_rtc_field(t, yearset);}

That should set the year to 2000 on first powerup or if the RTC module loses battery power.

Change "2018" if you want it to start with the current year.

if (t.year < 2018) {t.year = 2018; set_rtc_field(t, yearset);}

The setting will still wrap back to 2000 when setting, so change line 301 in the generic code or line 636 in the generic code to:

if(tempset > 2099){tempset = 2018;} //Roll over after 2099 to 2018

I haven't tested the changes, but they should work fine.

Don

Hi Don

Clear. Thank you for your project !

The issue is in the hardware of the RTC, not in the library. The chip itself initializes to 1900 when backup power is removed.

Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Micro"

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::drawFastVLine(int, int, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::drawFastHLine(int, int, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::fillRect(int, int, int, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::fillScreen(unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::drawLine(int, int, int, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::drawRect(int, int, int, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::invertDisplay(bool)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::setRotation(unsigned char)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::Adafruit_GFX(int, int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::Adafruit_GFX(int, int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::drawCircle(int, int, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::drawCircleHelper(int, int, int, unsigned char, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::fillCircleHelper(int, int, int, unsigned char, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::fillCircle(int, int, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::drawRoundRect(int, int, int, int, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::fillRoundRect(int, int, int, int, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::drawTriangle(int, int, int, int, int, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::fillTriangle(int, int, int, int, int, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::drawBitmap(int, int, unsigned char const*, int, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::drawBitmap(int, int, unsigned char const*, int, int, unsigned int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::drawXBitmap(int, int, unsigned char const*, int, int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::drawChar(int, int, unsigned char, unsigned int, unsigned int, unsigned char)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::write(unsigned char)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::setCursor(int, int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::setTextSize(unsigned char)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::setTextColor(unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::setTextColor(unsigned int, unsigned int)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::setTextWrap(bool)'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::getRotation() const'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::width() const'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\Adafruit_GFX_Library\Adafruit_GFX.cpp.o (symbol from plugin): In function `Adafruit_GFX::writeLine(int, int, int, int, unsigned int)':

(.text+0x0): multiple definition of `Adafruit_GFX::height() const'

sketch\Adafruit_GFX.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Micro.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Micro"

Build options changed, rebuilding all
Pusheen_Clock_Generic:21: error: #error ("Height incorrect, please fix Adafruit_SSD1306.h!");

#error("Height incorrect, please fix Adafruit_SSD1306.h!");

^

Multiple libraries were found for "Adafruit_GFX.h"
Used: C:\Users\Tejas\Documents\Arduino\libraries\Adafruit_GFX_Library
Not used: C:\Users\Tejas\Documents\Arduino\libraries\Adafruit-GFX-Library-master
Multiple libraries were found for "Adafruit_SSD1306.h"
Used: C:\Users\Tejas\Documents\Arduino\libraries\Adafruit_SSD1306
Not used: C:\Users\Tejas\Documents\Arduino\libraries\Adafruit_SSD1306-master
exit status 1
#error ("Height incorrect, please fix Adafruit_SSD1306.h!");

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Hi there! Im making an alarm clock playing custom song, because my gf hates the digital beep beep sound (being jazz singer). It will be all luxurious encased in ebony wood... You know, when you love her...

Im using DFPlayer mini (https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299) and i've implemented additional menu functions to choose the mp3 (saved in eeprom) to wake you up and some sort of snooze function.

I have managed to turn on the DFPlayer in setup(): "mp3.begin();" But the problem is when i call the "mp3.playFolderTrack(1, tracknum);" function to play the song and actually wake my love up, the OLED goes nuts and either freezes, displays random dots or blinks the "wake_SET" inficator snowflake ("*"). I've googled the hell out of it and found nothing helpfull.

Can you help? Christmas is coming!

- The cause may be something around the OLED buffer not being cleared.
- DFPlayer uses UART serial (Software Serial in this case), may it interfere with I2C?
- I am able to call the mp3 playback in setup() and it starts playing fine, but not anywhere else
- I've tested both libraries for DFPlayer (DFRobotDFPlayerMini.h, DFMiniMp3.h) with similar "OLED goes bannanas" result
- After googling "OLED random dots" many people claim the problem is with something around the I2C bus
- Is it possible that the problem is with the alarm clock being so repetitive in operation and DFPlayer is such a one time "call the mp3 function to play" system?

My code (if alarmTrig is 0, play the song and set alarmTrig to 1, woks fine...)

SoftwareSerial secondarySerial(10, 11); // RX, TX
DFMiniMp3<SoftwareSerial, Mp3Notify> mp3(secondarySerial);

if(wake_SET && DS3231_triggered_a1()){
beepcount = beepcount + 1;
if(beepcount <= 600){
if (alarmTrig == 0) {playMp3();}
if(!flash){display.invertDisplay(1);}
}
else{beepcount = 0; DS3231_clear_a1f(); alarmTrig = 0;}
}
_____________________________________________
void playMp3(){
mp3.playFolderTrack(1, tracknum); // sd:/01/001.mp3
Serial.print("ALARM TRIGGERED");
alarmTrig = 1;
}

1 reply

The clock has an inner loop that runs every 500ms based upon the millis counter the code outside this loop rubs at full speed. The normal alarm beeper uses the alarm flag to toggle the alarm output on/off every time the inner loop executes, resulting in a 1/2 second on, 1/2 second off activation of the alarm.

I think your issue is that you are checking the alarm flag and calling the playback function every time the 500ms inner loop executes, retriggering it every half-second! You need some kind of flag that allows it to be called once when the alarm trigger occurs, and never again until the alarm is silenced manually or times out. Also, the playback function and library may be incompatible with the Adafruit graphics library.

I am pretty new to these Arduino's and OLed displays but I just wanted to say thank you for posting this great little alarm clock project. I have tried hundreds of sketches from different online sources and I cant get most of them to work but when yours worked the first time I got excited again and optimistic for future projects. I had some spare parts lying around and in about 10 minutes I had this working perfectly. I used the Arduino 1.8.1 IDE (the newest version at this time). I also tried compiling to a couple different boards, the Nano, the Pro Mini, and the Uno, and they also had no problem. I would like to change the Pusheen graphic to a silhouette of the B9 robot or of the Jupiter 2 but when I tried the LCD Assistant I get nothing is there anything else I could try. As you can see i used a two color OLed but i am considering the larger 1.33 OLed because I don't see that well without my glasses do you have any ideas on how to do that? Again thank you for this cool little alarm clock.

20170427_124114.jpg
3 replies

Thanks! It was a fun project to make.

Rescaling the code for a bigger display is a bit tricky since I hard-coded the screen coordinates of many of the elements. Bad coding practice, but I never intended to port to another display.

For LCD Assistant, the final image you import must be a monochrome bitmap and must be a multiple of 8 bits in both the x and y axis. You must check the "horizontal" box before exporting to make the data structure compatible with the Adafruit library. Of course the image size must not be larger than the OLED display pixel dimensions.

I followed your ideas for the LCD Assistant and with the use of the Paint program that came with my computer I think I have this figured out. Sorry but I have one more question, the animated Pusheen scenes on the clock, were they also done with the LCD Assistant or another program. I am a big Lost in Space fan and wanted some moving graphics of the Jupiter 2 taking off and flying and maybe some of the robot doing things. Thank you

Thank you for the tips, I now think I know what I was doing wrong. That seems like a lot of restrictions for a picture but I will try. Sorry but 1 last question, when you hit the export button can it just be exported into a general folder or must it be exported straight into the sketch?