Difference between revisions of "Expansion-Board XIAO-SAMD21 Grove-OLED"

From
Jump to: navigation, search
Line 13: Line 13:
  
  
=== images ===
+
=== code ===
 +
 
 +
<b>RTC clock display</b><br>
 +
uses RTC to display the clock on the OLED<br>
 +
 
 +
u8g2 library<br>
 +
https://github.com/olikraus/U8g2_Arduino<br>
 +
 
 +
PCF8563 library<br>
 +
https://github.com/Bill2462/PCF8563-Arduino-Library<br>
 +
 
 +
 
 +
<pre>
 +
#include <Arduino.h>
 +
#include <U8x8lib.h>
 +
#include <PCF8563.h>
 +
PCF8563 pcf;
 +
#include <Wire.h>
 +
 
 +
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);  // OLEDs without Reset of the Display
 +
 
 +
void setup() {
 +
  Serial.begin(115200);
 +
  u8x8.begin();
 +
  u8x8.setFlipMode(1);
 +
  Wire.begin();
 +
  pcf.init();//initialize the clock
 +
  pcf.stopClock();//stop the clock
 +
  pcf.setYear(20);//set year
 +
  pcf.setMonth(10);//set month
 +
  pcf.setDay(23);//set dat
 +
  pcf.setHour(17);//set hour
 +
  pcf.setMinut(33);//set minut
 +
  pcf.setSecond(0);//set second
 +
  pcf.startClock();//start the clock
 +
}
 +
 
 +
void loop() {
 +
  Time nowTime = pcf.getTime();//get current time
 +
  u8x8.setFont(u8x8_font_chroma48medium8_r);  // choose a suitable font
 +
 
 +
  u8x8.setCursor(0, 0);
 +
  u8x8.print(nowTime.day);
 +
  u8x8.print("/");
 +
  u8x8.print(nowTime.month);
 +
  u8x8.print("/");
 +
  u8x8.print("20");
 +
  u8x8.print(nowTime.year);
 +
  u8x8.setCursor(0, 1);
 +
  u8x8.print(nowTime.hour);
 +
  u8x8.print(":");
 +
  u8x8.print(nowTime.minute);
 +
  u8x8.print(":");
 +
  u8x8.println(nowTime.second);
 +
  delay(1000);
 +
}
 +
</pre>

Revision as of 17:39, 13 October 2024

Expansion Board Base

images

Liens

Installation

code

RTC clock display
uses RTC to display the clock on the OLED

u8g2 library
https://github.com/olikraus/U8g2_Arduino

PCF8563 library
https://github.com/Bill2462/PCF8563-Arduino-Library


#include <Arduino.h>
#include <U8x8lib.h>
#include <PCF8563.h>
PCF8563 pcf;
#include <Wire.h>

U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // OLEDs without Reset of the Display

void setup() {
  Serial.begin(115200);
  u8x8.begin();
  u8x8.setFlipMode(1);
  Wire.begin();
  pcf.init();//initialize the clock
  pcf.stopClock();//stop the clock
  pcf.setYear(20);//set year
  pcf.setMonth(10);//set month
  pcf.setDay(23);//set dat
  pcf.setHour(17);//set hour
  pcf.setMinut(33);//set minut
  pcf.setSecond(0);//set second
  pcf.startClock();//start the clock
}

void loop() {
  Time nowTime = pcf.getTime();//get current time
  u8x8.setFont(u8x8_font_chroma48medium8_r);   // choose a suitable font

  u8x8.setCursor(0, 0);
  u8x8.print(nowTime.day);
  u8x8.print("/");
  u8x8.print(nowTime.month);
  u8x8.print("/");
  u8x8.print("20");
  u8x8.print(nowTime.year);
  u8x8.setCursor(0, 1);
  u8x8.print(nowTime.hour);
  u8x8.print(":");
  u8x8.print(nowTime.minute);
  u8x8.print(":");
  u8x8.println(nowTime.second);
  delay(1000);
}