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

From
Jump to: navigation, search
Line 15: Line 15:
 
=== code ===
 
=== code ===
  
<b>RTC clock display</b><br>
+
<b>Hello World!</b>
uses RTC to display the clock on the OLED<br>
+
 
 +
<pre>
 +
#include <Arduino.h>
 +
#include <U8x8lib.h>
 +
#include <Wire.h>
 +
 
 +
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);  // OLEDs without Reset of the Display
  
u8g2 library<br>
+
void setup(void) {
https://github.com/olikraus/U8g2_Arduino<br>
+
  u8x8.begin();
 +
  u8x8.setFlipMode(1);  // set number from 1 to 3, the screen word will rotary 180
 +
}
  
PCF8563 library<br>
+
void loop(void) {
https://github.com/Bill2462/PCF8563-Arduino-Library<br>
+
  u8x8.setFont(u8x8_font_chroma48medium8_r);
 +
  u8x8.setCursor(0, 0);
 +
  u8x8.print("Hello World!");
 +
}
 +
</pre>
  
 +
<b>RTC clock display</b><br>
 +
uses RTC to display the clock on the OLED<br>
  
 
<pre>
 
<pre>
Line 70: Line 84:
 
}
 
}
 
</pre>
 
</pre>
 +
 +
u8g2 library<br>
 +
https://github.com/olikraus/U8g2_Arduino<br>
 +
 +
PCF8563 library<br>
 +
https://github.com/Bill2462/PCF8563-Arduino-Library<br>

Revision as of 17:42, 13 October 2024

Expansion Board Base

images

Liens

Installation

code

Hello World!

#include <Arduino.h>
#include <U8x8lib.h>
#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(void) {
  u8x8.begin();
  u8x8.setFlipMode(1);   // set number from 1 to 3, the screen word will rotary 180
}

void loop(void) {
  u8x8.setFont(u8x8_font_chroma48medium8_r);
  u8x8.setCursor(0, 0);
  u8x8.print("Hello World!");
}

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

#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);
}

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

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