44
44
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
45
45
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
46
46
#define SCREEN_WIDTH 128 // OLED display width, in pixels
47
- #define SCREEN_HEIGHT 32 // OLED display height, in pixels
47
+ #define SCREEN_HEIGHT 64 // OLED display height, in pixels
48
48
const int OLED_I2C_ADDR = 0x3C ; // Address 0x3C for 128x32
49
49
50
50
SSD1306AsciiWire display;
51
51
52
- // Current and voltage sensor
52
+ // Current and voltage sensor class
53
53
Adafruit_INA219 ina219_monitor;
54
54
55
- // DS3231 RTC modul
55
+ // DS3231 RTC modul I2C address
56
56
const int RTC_I2C_addr = 0x68 ;
57
+ // RTC class
57
58
uRTCLib rtc (RTC_I2C_addr);
58
59
59
- // SD card modul
60
+ // SD card modul chip select
60
61
#define SDCARD_CHIP_SELECT 4
61
62
62
63
63
64
/* Global variables */
64
65
65
- // RTC global variables
66
+ /* RTC global variables */
66
67
uint8_t rtc_second = 0 ;
67
68
uint8_t rtc_minute = 0 ;
68
69
uint8_t rtc_hour = 0 ;
@@ -71,27 +72,26 @@ uint8_t rtc_month = 0;
71
72
uint8_t rtc_year = 0 ;
72
73
73
74
// Current sensor variables
74
- float f_BusVoltage_V;
75
- float f_ShuntCurrent_mA;
75
+ float f_BusVoltage_V; /* * Measured bus voltage */
76
+ float f_ShuntCurrent_mA; /* * Measured shunt current */
76
77
77
78
78
79
// General variables
79
- char DateStampString[] = " 2000.99.88" ;
80
- char TimeStampString[] = " 00:00:00" ;
81
- char logFileName[] = " mmddHHMM.txt" ;
82
- char VoltString[] = " 99.999 " ;
83
- char CurrentString[] = " 9999.999 " ;
84
- bool SD_log_enabled = false ;
85
-
80
+ char DateStampString[] = " 2000.99.88" ; /* * String to store date value */
81
+ char TimeStampString[] = " 00:00:00" ; /* * String to store time value */
82
+ char logFileName[] = " mmddHHMM.txt" ; /* * String to store log file name */
83
+ char VoltString[] = " 99.999 " ; /* * String to store measured voltage value */
84
+ char CurrentString[] = " 9999.999 " ; /* * String to store measured current value */
85
+ bool SD_log_enabled = false ; /* * Enabling SD logging or not */
86
+
87
+ // Datafile class
86
88
File dataFile;
87
89
88
90
89
- // Function definitions
90
- // void setup();
91
- // void loop();
92
- // bool Log_To_SD_card(const char *_logfile);
93
- bool Log_To_SD_card ();
94
- void setTimeStampString ();
91
+ /* Function definitions */
92
+
93
+ bool Log_To_SD_card (void );
94
+ void setTimeStampString (void );
95
95
96
96
97
97
// setup()
@@ -105,12 +105,23 @@ void setup()
105
105
// display.begin(SSD1306_SWITCHCAPVCC, OLED_I2C_ADDR);
106
106
Serial.print (F (" SSD1306 init..." ));
107
107
#if OLED_RESET >= 0
108
- display.begin (&Adafruit128x32, I2C_ADDRESS, RST_PIN);
108
+ #if SCREEN_HEIGHT == 32
109
+ display.begin (&Adafruit128x32, I2C_ADDRESS, RST_PIN);
110
+ #endif
111
+ #if SCREEN_HEIGHT == 64
112
+ display.begin (&Adafruit128x64, I2C_ADDRESS, RST_PIN);
113
+ #endif
109
114
#else // RST_PIN >= 0
110
- display.begin (&Adafruit128x32, OLED_I2C_ADDR);
115
+ #if SCREEN_HEIGHT == 32
116
+ display.begin (&Adafruit128x32, OLED_I2C_ADDR);
117
+ #endif
118
+ #if SCREEN_HEIGHT == 64
119
+ display.begin (&Adafruit128x64, OLED_I2C_ADDR);
120
+ #endif
111
121
#endif // RST_PIN >= 0
112
122
113
123
display.setFont (Adafruit5x7);
124
+ // display.setFont(X11fixed7x14);
114
125
115
126
Serial.println (F (" OK" ));
116
127
display.clear ();
@@ -151,11 +162,9 @@ void loop()
151
162
{
152
163
setTimeStampString ();
153
164
154
- // clear display
155
- // display.clear();
156
- // display.set1X();
157
165
display.setRow (0 );
158
166
display.setCol (0 );
167
+ display.set1X ();
159
168
160
169
// display time stamp
161
170
Serial.print (DateStampString);
@@ -172,17 +181,14 @@ void loop()
172
181
f_BusVoltage_V=ina219_monitor.getBusVoltage_V ();
173
182
174
183
// convert to text
175
- dtostrf ((f_ShuntCurrent_mA),8 , 3 ,CurrentString);
184
+ dtostrf ((f_ShuntCurrent_mA),7 , 2 ,CurrentString);
176
185
dtostrf (f_BusVoltage_V,6 ,3 ,VoltString);
177
- // CurrentString=String(f_ShuntCurrent_mA*1000, 4);
178
- // CurrentString+=F(" mA");
179
- // VoltString="";
180
- // VoltString=String(f_BusVoltage_V,4);
181
- // VoltString+=F(" V");
182
186
183
187
// display volt
184
188
Serial.print (VoltString);
185
189
Serial.print (F (" V" ));
190
+ display.set2X ();
191
+ display.print (F (" " ));
186
192
display.print (VoltString);
187
193
display.println (F (" V" ));
188
194
@@ -192,6 +198,7 @@ void loop()
192
198
display.print (CurrentString);
193
199
display.println (F (" mA" ));
194
200
201
+ display.set1X ();
195
202
if (SD_log_enabled) {
196
203
Serial.print (F (" SD log: " ));
197
204
Serial.print (logFileName);
@@ -211,7 +218,11 @@ void loop()
211
218
212
219
}
213
220
214
- void setTimeStampString ()
221
+ /* *
222
+ * @brief Query date & time and set the [Date|Time]StampStrings & logFileName accordingly.
223
+ * @param void
224
+ */
225
+ void setTimeStampString (void )
215
226
{
216
227
// get time stamp, convert to a string
217
228
rtc.refresh ();
@@ -244,12 +255,15 @@ void setTimeStampString()
244
255
logFileName[5 ] = DateStampString[6 ];
245
256
logFileName[6 ] = DateStampString[8 ];
246
257
logFileName[7 ] = DateStampString[9 ];
247
-
248
-
258
+
249
259
}
250
260
251
- // bool Log_To_SD_card(const char *_logfile)
252
- bool Log_To_SD_card ()
261
+ /* *
262
+ * @brief Log the measurements with timestamp to SD card in CSV format.
263
+ * @param void
264
+ * @return bool FileOpenSuccess
265
+ */
266
+ bool Log_To_SD_card (void )
253
267
{
254
268
bool FileOpenSuccess = false ;
255
269
@@ -275,8 +289,7 @@ bool Log_To_SD_card()
275
289
dataFile.print (CurrentString);
276
290
dataFile.print (F (" ," ));
277
291
dataFile.println (F (" mA" ));
278
- dataFile.close ();
279
- // Serial.println(F(" logfile closed"));
292
+ dataFile.close ();
280
293
}
281
294
282
295
return FileOpenSuccess;
0 commit comments