[last update: 2021-03-04]
go to: XIAO main page
go to: XIAO Expansion Board
-----
- The expansion board uses a 128 x 64 OLED
- Starting from code copied from
(link to:) Seeed wiki:
- The code contains:
#include <Arduino.h>
#include <U8x8lib.h>
- Instructions in wiki say to download and install the "u8g2" library.
- github manual for u8g2 library says that it includes the u8x8 library. The u8x8 library does direct-write to the display, while the u8g2 library uses memory buffer.
- Initial sketch: XIAO-ExpBd-OLED-02.ino
Works to display "Hello World"
Change font face and size by ...
If you enter more characters, that exceed a single line, then the extra characters overwrite the start of the existing line,
that is, they don't do a LF to start a new line.
Warning from (great site) (link to:) best-microcontroller-projects.com
The u8x8 and u8g2 do not do line wrap - they just start again on the same line - manually insert \n into a string to goto to the next line or write a small algorithm similar to:
char *msg="Now is the time for all good men to come to the aid the party.";
// Code snippet : wrap a string to display
byte i,y;
// u8x8 does not wrap lines.
y = 0;
for (i=0;i
if ((i % 16)==0 && i!=0) y++;
u8x8.setCursor(i % 16,y);
u8x8.print(msg[i]);
}
- The config (constructor) code used in the wiki code has: HW_I2C
- The github docs say this is:
Hardware I2C/TWI (based on the Arduino Wire lib), clock and data pins are optional and can be used for pin remapping of the hardware I2C pins (only supported by some boards)
Olikraus says elsewhere that in practice, since remapping is mostly not supported, the HW_i2c constructor should be assumed to only specify a reset pin.
However if 3 pins are specified, they are listed in order: reset, clock, data
- It further specifies this format:
U8X8_SSD1306_128X64_NONAME_HW_I2C([reset [, clock, data]])
The hardware I2C allows pin remapping for some controller types.
The optional pin numbers are listed after the reset pin:
..._HW_I2C([reset [, clock, data]]).
Use U8X8_PIN_NONE if the reset input of the display is not connected.
- Actual config line in the code from wiki is:
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);
So in this expansion board implementation, the reset pin is not connected,
and the clock and data lines are not specified, leaving them at whatever default values.
- From Olikraus (lib author) in forum:
There are possible data transfer methods to the display. This method is appended to the display name. In your case this is "HW_I2C", which denotes that data should be sent according to the I2C protocol using the uC HW I2C subsystem.
Another method is "SW_I2C" which will use the same protocol, but u8g2 will not use the uC I2C subsystem to transfer the data, insted the protocol is emulated via software gpio only.
One advantage of the the SW I2C is this: You can choose any pins.
Coming back to the HW I2C: There are two types of uC: Systems where the I2C pins are fixed (like the AVR systems) and systems where the HW I2C pins can be remapped to any pin (like ESP-uC).
So there are basically three cases:
HW I2C with fixed pins: U8X8_SH1106_128X64_NONAME_HW_I2C oled(U8X8_PIN_NONE);
HW I2C with pin remapping: U8X8_SH1106_128X64_NONAME_HW_I2C oled(U8X8_PIN_NONE, 14, 15);
Note: On AVR (Arduino Uno) the two numbers are ignored, because pin remapping is not possible (pins are fixed)
SW I2C, which will be slower, but any pin on any system can be used: U8X8_SH1106_128X64_NONAME_SW_I2C oled(14, 15, U8X8_PIN_NONE);
Note: pin order is different! With the SW constructor, pin order is: clock, data, reset
- u8g2 Issue Forum:
(link to:) github
- Fonts:
(link to: wiki ref
For example:
u8x8.setFont(u8x8_font_courB24_3x4_f); ... displays a max of 5 characters in a line
- alt code to write to display:
u8x8.drawString(0,0,"Hello World!");