Working i2c code for 128x64 Crius OLED Modul v1.0. Controller SSD1306. The OLED module must be modified for sending correct ACK signal.

Dependencies:   mbed

Discussion here: http://developer.mbed.org/forum/libdev/topic/5402/

/media/uploads/michaelruck/p1000961.jpg

Committer:
michaelruck
Date:
Thu Mar 13 18:46:54 2014 +0000
Revision:
0:38a126729865
Crius OLED SSD1306 i2c

Who changed what in which revision?

UserRevisionLine numberNew contents of line
michaelruck 0:38a126729865 1 /* ============================================
michaelruck 0:38a126729865 2 Modified Code from Crius
michaelruck 0:38a126729865 3 The CriusOLED Hardware MUST be modified for correct function of ACK
michaelruck 0:38a126729865 4 Copyright (c) 2014 Michael Ruck michael@ruck.com
michaelruck 0:38a126729865 5
michaelruck 0:38a126729865 6 Permission is hereby granted, free of charge, to any person obtaining a copy
michaelruck 0:38a126729865 7 of this software and associated documentation files (the "Software"), to deal
michaelruck 0:38a126729865 8 in the Software without restriction, including without limitation the rights
michaelruck 0:38a126729865 9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
michaelruck 0:38a126729865 10 copies of the Software, and to permit persons to whom the Software is
michaelruck 0:38a126729865 11 furnished to do so, subject to the following conditions:
michaelruck 0:38a126729865 12
michaelruck 0:38a126729865 13 The above copyright notice and this permission notice shall be included in
michaelruck 0:38a126729865 14 all copies or substantial portions of the Software.
michaelruck 0:38a126729865 15
michaelruck 0:38a126729865 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
michaelruck 0:38a126729865 17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
michaelruck 0:38a126729865 18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
michaelruck 0:38a126729865 19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
michaelruck 0:38a126729865 20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
michaelruck 0:38a126729865 21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
michaelruck 0:38a126729865 22 THE SOFTWARE.
michaelruck 0:38a126729865 23 ===============================================
michaelruck 0:38a126729865 24 */
michaelruck 0:38a126729865 25
michaelruck 0:38a126729865 26 #include "mbed.h"
michaelruck 0:38a126729865 27 #include <time.h>
michaelruck 0:38a126729865 28 #include "CriusOLED.h"
michaelruck 0:38a126729865 29
michaelruck 0:38a126729865 30
michaelruck 0:38a126729865 31 //DigitalOut myled(D2);
michaelruck 0:38a126729865 32
michaelruck 0:38a126729865 33 Serial pc(SERIAL_TX, SERIAL_RX);
michaelruck 0:38a126729865 34
michaelruck 0:38a126729865 35 int main()
michaelruck 0:38a126729865 36 {
michaelruck 0:38a126729865 37 time_t rawtime;
michaelruck 0:38a126729865 38 struct tm timeinfo;
michaelruck 0:38a126729865 39 struct tm * timeinfo2;
michaelruck 0:38a126729865 40 char buffer [6];
michaelruck 0:38a126729865 41 char buffer2[60];
michaelruck 0:38a126729865 42
michaelruck 0:38a126729865 43
michaelruck 0:38a126729865 44 // Initialize I2C and OLED Display
michaelruck 0:38a126729865 45 i2c.frequency(400000);
michaelruck 0:38a126729865 46 init_OLED();
michaelruck 0:38a126729865 47 displayOn();
michaelruck 0:38a126729865 48 reset_display();
michaelruck 0:38a126729865 49
michaelruck 0:38a126729865 50
michaelruck 0:38a126729865 51 timeinfo.tm_year = 2014-1900;
michaelruck 0:38a126729865 52 timeinfo.tm_mon = 3-1;
michaelruck 0:38a126729865 53 timeinfo.tm_mday = 13;
michaelruck 0:38a126729865 54
michaelruck 0:38a126729865 55 timeinfo.tm_hour=0;
michaelruck 0:38a126729865 56 timeinfo.tm_min=0;
michaelruck 0:38a126729865 57 timeinfo.tm_sec=0;
michaelruck 0:38a126729865 58 //timeinfo->tm_isds=0; // not implemented in mbed
michaelruck 0:38a126729865 59
michaelruck 0:38a126729865 60 set_time(mktime(&timeinfo));
michaelruck 0:38a126729865 61 pc.printf("%d\n\n", mktime(&timeinfo));
michaelruck 0:38a126729865 62
michaelruck 0:38a126729865 63 while(1) {
michaelruck 0:38a126729865 64 //myled != myled;
michaelruck 0:38a126729865 65 clear_display();
michaelruck 0:38a126729865 66 sendImage();
michaelruck 0:38a126729865 67 wait(1.0);
michaelruck 0:38a126729865 68 clear_display();
michaelruck 0:38a126729865 69 sendStrXY("Code by M. Ruck",4,0);
michaelruck 0:38a126729865 70 wait(1.0);
michaelruck 0:38a126729865 71 //reset_display();
michaelruck 0:38a126729865 72 clear_display();
michaelruck 0:38a126729865 73
michaelruck 0:38a126729865 74 rawtime = time(NULL);
michaelruck 0:38a126729865 75 timeinfo2 = localtime (&rawtime);
michaelruck 0:38a126729865 76 strftime (buffer2, 60, "%d.%m.%Y %H:%M:%S", timeinfo2);
michaelruck 0:38a126729865 77 pc.printf("%s\n",buffer2);
michaelruck 0:38a126729865 78 strftime (buffer,6,"%M:%S",timeinfo2);
michaelruck 0:38a126729865 79 printBigTime(buffer);
michaelruck 0:38a126729865 80 wait(4.0);
michaelruck 0:38a126729865 81
michaelruck 0:38a126729865 82 }
michaelruck 0:38a126729865 83 }