Hi, I am following the rtc and oled project which is documented on this site. I have all the bits needed and am using a nano. I have copied the code from this site, pasted it into the IDE and I get a message Compilation error: stray '#' in program. As I am a newbie I dont know how to remedy this. Does anyone have any ideas? Ty in advance.
The project is the one on this site called - Tutorial on how to use DS3231 RTC Module
Build a cool looking clock using RTC3231 and DS1306 OLED display
Jan 30, 2021
Remove the stray # in the code you didn't post.
I'm fairly sure the compiler told you where
Hi,
Can you please post your code?
Can you please post the error message?
The message should have information in it to where the error is.
Thanks.. Tom..
It is listing the #include ones, and also many other errors of all sorts.
OK.
Good luck.
Imagine walking into a car dealership and announcing "My car doesn't start, so I left it at home"
Working on all arduino boards
1//Marios Ideas
2//DS3231 Tutorial
3//Using DS3232.h library
4//Formating date and time with custom functions
5
6#include <Wire.h>
7#include <DS3231.h>
8#include <Adafruit_GFX.h>
9#include <Adafruit_SSD1306.h>
10
11int pause=1000;
12
13DS3231 clock;
14RTCDateTime dt;
15
16#define SCREEN_WIDTH 128 // OLED display width, in pixels
17#define SCREEN_HEIGHT 64 // OLED display height, in pixels
18
19
20#define OLED_RESET -1// Reset pin # (or -1 if sharing Arduino reset pin)
21Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
22
23void setup() {
24Serial.begin(9600);
25 clock.begin();
26 // Set sketch compiling time
27 clock.setDateTime(__DATE__, __TIME__);
28
29 // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
30 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
31 Serial.println(F("SSD1306 allocation failed"));
32 for(;;); // Don't proceed, loop forever
33 }
34 display.display(); //display initial Adafruit logo
35 delay(2000);
36
37 // Clear the buffer
38 display.clearDisplay();
39 display.display();
40
41}
42
43String DayOfTheWeek(uint8_t Day){
44 String DayText;
45 if (Day==1) DayText="Monday";
46 if (Day==2) DayText="Tuesday";
47 if (Day==3) DayText="Wednesday";
48 if (Day==4) DayText="Thursday";
49 if (Day==5) DayText="Friday";
50 if (Day==6) DayText="Saturday";
51 if (Day==7) DayText="Sunday";
52 return DayText;
53}
54
55
56
57String DayMonthYear(uint8_t Day,uint8_t Month,uint16_t Year){
58 String DayMonthYearText;
59 if (Month==1) DayMonthYearText="JAN ";
60 if (Month==2) DayMonthYearText="FEB ";
61 if (Month==3) DayMonthYearText="MAR ";
62 if (Month==4) DayMonthYearText="APR ";
63 if (Month==5) DayMonthYearText="MAY ";
64 if (Month==6) DayMonthYearText="JUN ";
65 if (Month==7) DayMonthYearText="JUL ";
66 if (Month==8) DayMonthYearText="AUG ";
67 if (Month==9) DayMonthYearText="SEP ";
68 if (Month==10) DayMonthYearText="OCT ";
69 if (Month==11) DayMonthYearText="NOV ";
70 if (Month==12) DayMonthYearText="DEC ";
71
72 DayMonthYearText=DayMonthYearText+Day;
73 if (Day==1)DayMonthYearText=DayMonthYearText+"st ";
74 if (Day==2)DayMonthYearText=DayMonthYearText+"nd ";
75 if (Day>2)DayMonthYearText=DayMonthYearText+"th ";
76
77 DayMonthYearText=DayMonthYearText+Year;
78
79 return DayMonthYearText;
80}
81
82String AddLeadingZero(uint8_t x){
83 String AddLeadingZeroText;
84 if(x<10) AddLeadingZeroText="0";
85 else AddLeadingZeroText="";
86 AddLeadingZeroText=AddLeadingZeroText+x;
87 return AddLeadingZeroText;
88}
89
90String CurrentTime(uint8_t H, uint8_t I ){
91 String CurrentTimeText="";
92 CurrentTimeText=CurrentTimeText + AddLeadingZero(H) +":"+AddLeadingZero(I);
93 return CurrentTimeText;
94}
95
96void loop() {
97 dt = clock.getDateTime();
98
99 display.fillRect(0,0,128,16,SSD1306_WHITE);
100 display.fillRect(0,17,128,16,SSD1306_BLACK);
101 display.fillRect(0,31,128,33,SSD1306_WHITE);
102
103 display.setCursor(1,1);
104 display.setTextSize(2);
105 display.setTextColor(SSD1306_BLACK);
106 display.println(DayOfTheWeek(dt.dayOfWeek));
107
108 display.setCursor(1,18);
109 display.setTextSize(1);
110 display.setTextColor(SSD1306_WHITE);
111 display.println(DayMonthYear(dt.day,dt.month,dt.year));
112
113 display.setCursor(3,35);
114 display.setTextSize(3);
115 display.setTextColor(SSD1306_BLACK);
116 display.println(CurrentTime(dt.hour,dt.minute));
117
118 display.setCursor(100,35);
119 display.setTextSize(2);
120 display.setTextColor(SSD1306_BLACK);
121 display.println(AddLeadingZero(dt.second));
122
123 clock.forceConversion();
124 display.setCursor(85,18);
125 display.setTextSize(1);
126display.setTextColor(SSD1306_WHITE);
127display.print(clock.readTemperature());
128display.setCursor(117,16);
129display.print("o");
130
131
132 display.display();
133 delay(1000);
134}
link doesn't work
please post code using <code>
icon
Remove every # in the program, one by one. If, after removing the first #, it still doesn't compile, put the # back in and try removing the next # and so on.
There are quicker ways, of course, but based on what you have told us so far...
You copied the line numbers along with the program text, go back to the website and use the download link.
The code is one from this website in the projects section. It is there for people to use. The code on this site says it is working on all arduino models.
The code is one from this website in the projects section. It is there for people to use. The code on this site says it is working on all arduino models..
What’s the error exactly? Copy everything so we can see
Aaah ty. ty so much.
But it is quite naïve code.
That has cleared all thos errore. ty. It is now asking for the <Adafruit_GFX.h> to be included. I am wondering which exact librarty will satisfy that.
Oh, I am a newbie, so I cant judge it. I am using it because its listed on this site as a project. It says it works.
David 2018 has sorted it. ty.
I have a nano connected to a ds3231 and an oled screen as per the project, via a breadboard on an i2c circuit. Everything looks good but I now need to program the nano with his code.
Okay, it sounds like your initial problem is resolved, but you're not asking a new question, are you? Like, how do I download, or something?
You'll find that clear communication is essential to progress on this technical forum.