faq.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. Sections
  2. - Wiring... Interconnect, pin/label names
  3. - Displays... Display support, display problems
  4. - U8g2... Setup, compilation, usage, fonts
  5. Wiring
  6. Q: Why does my xxx_SW_I2C() device not work with my other I2C devices?
  7. A: SW_I2C emulates I2C with digitalWrite(), which will have a conflict with other
  8. I2C devices at the same pins. There are two options: (A) use xxx_HW_I2C() or
  9. (B) use different pins with xxx_SW_I2C()
  10. Q: My display has a pin labled as "A0" (or "RS"). How to connect this pin?
  11. A: There are different names for the "data/command" pin. In U8g2 only the name
  12. "dc" is used. On the display side it might be also called "A0", "RS", "CD".
  13. See also the next question.
  14. Q: My display has pins labled as "D0" and "D1". What is the interface and how
  15. to connect these pins?
  16. A: This is probably a SSD1306 OLED. The meaning of the D0 and D1 pin depends
  17. on the configuration of the SSD1306. D0 is the clock line and D1 is the data line.
  18. Q: For HW SPI no pin numbers are required in the constructor. But which are
  19. the pin numbers for wiring?
  20. A: This depends on your board. For some official boards, this is listed here:
  21. https://www.arduino.cc/en/Reference/SPI
  22. You need to connect MOSI (data) and SCK (clock) pins of your board with the
  23. corresponding pins with your display.
  24. All U8g2 software emulated SPI constructors look like this:
  25. U8G2_..._4W_SW_SPI u8g2(U8G2_R0, clock, data, cs, dc, reset);
  26. All U8g2 hardware SPI constructors look like this:
  27. U8G2_..._4W_SW_SPI u8g2(U8G2_R0, cs, dc, reset);
  28. Q: How to use HSPI for HW SPI on ESP32?
  29. A: Assign "SPI = SPIClass(HSPI);" before calling u8g2.begin() (see issue #1061)
  30. Q: For HW I2C no pin numbers are required in the constructor. But which are
  31. the pin numbers for wiring?
  32. A: See same question for SPI. For some boards, the pins are listed here:
  33. https://www.arduino.cc/en/Reference/Wire
  34. All U8g2 software emulated I2C constructors look like this:
  35. U8G2_..._SW_I2C u8g2(U8G2_R0, clock, data, reset);
  36. All U8g2 hardware I2C constructors look like this:
  37. U8G2_..._HW_I2C u8g2(U8G2_R0, reset);
  38. Note: The HW_I2C allows to more arguments for hardware pin number remapping.
  39. However, this is only supported on the ESP8266.
  40. Q: The pin names on my display do not fit to the pin names of U8g2.
  41. A: Yes, each datasheet/product/controller has different names. There
  42. is a mapping table on the wiki for this:
  43. https://github.com/olikraus/u8g2/wiki/u8g2setupcpp#wiring
  44. Q: What is wrong with connecting Reset (RES) of my display with the Reset of my
  45. Arduino Board?
  46. A:
  47. - Both are inputs. It does not make sense to connect two inputs
  48. - Both pins have completly different functions: The reset of your board will reset
  49. the Arduino board, the reset of the display will reset the display.
  50. Please connect the reset input of the display with a normal GPIO pin of your board.
  51. Q: Shell I connect CS (chip select) with the SS output of the Arduino board?
  52. A: In general this is required neither for hardware or software SPI.
  53. Q: My board has a MOSI and a SCK output. Do i need to connect this to the
  54. clock and data pins of my display?
  55. A: "Yes" if you want to use hardware SPI (u8g2 constructors ending in _HW_SPI).
  56. You can use any pins with the software emulated SPI of u8g2 (constructors ending
  57. in _SW_SPI). Howver in general it is better to use hardware SPI to get a better
  58. performance of your display.
  59. Q: How to wire ST7920 display in 8080 mode?
  60. A:
  61. - See also https://github.com/olikraus/u8g2/wiki/gallery#26-nov-2016-st7920-128x64-lcd-in-8080-parallel-mode
  62. - Connect the RW (SID) input of your ST7920 display to ground.
  63. - In the u8g2 constructor, use U8X8_PIN_NONE for "cs" signal
  64. - The "dc" pin is called "RS" in the ST7920 documentation.
  65. - See also issue #90: https://github.com/olikraus/u8g2/issues/90
  66. Displays
  67. Q: There is an x-offset on my SSD1306 128x64 OLED.
  68. A: This is not a SSD1306 OLED, instead use the SH1106 constructor.
  69. Q: A T6963 misses columns on the display/has garbled output.
  70. A: Ensure that the T6963 operates in 8x8 mode:
  71. If the display module has two font select (FSx) pins, connect both to GND
  72. If the display module has one font select (FS) pin, connect it to GND
  73. Q: My T6963 has a RD input. How shell this be connected?
  74. A: The RD input for any 8080 interface has to be connected to power supply (5V or 3.3V,
  75. depending on the display)
  76. Q: My T6963 was working with u8glib, but it does not work with U8g2
  77. A: The sequence of argument has changed from cs, a0, wr to wr, cs, a0:
  78. U8GLIB_T6963_240X128 u8g(d0, d1, d2, d3, d4, d5, d6, d7, cs, dc, wr, rd, reset);
  79. U8G2_T6963_240X128_1_8080 u8g2(U8G2_R0, d0, d1, d2, d3, d4, d5, d6, d7, wr, cs, dc, reset);
  80. Q: My controller/interface combination is not listed in the examples.
  81. A: Yes, the complete list is here:
  82. https://github.com/olikraus/u8g2/wiki/u8g2setupcpp
  83. Q: My display controller is listed, but the display dimension is not supported.
  84. A: Raise an issue in the u8g2 tracker "https://github.com/olikraus/u8g2/issues"
  85. Q: My controller is not listed, What can I do?
  86. A: First check whether this controller is compatible to one of the supported
  87. controller:
  88. Supported: ST7565, Compatible: NT7534, UC1701, SED1565, S1D15605, S6B0723, SPLC502
  89. Supported: SED1330, Compatible: SED1335, RA8835, S1D3305
  90. Supported: LC7981, Compatible: NT7086, (maybe also: HD61830)
  91. This table just reflects my current knowledge. It is not tested and may not be true at all.
  92. Raise an issue in the u8g2 issue tracker, If your controller for a monochrome display is not listed.
  93. A more detailed discussion of some controllers is listed in "controller_cmds.txt"
  94. U8g2
  95. Q: How to install u8g2 for Arduino?
  96. A: The latest stable version of U8g2 is available as Arduino Library in the
  97. "Manage Libraries..." browser. See also here: https://github.com/olikraus/u8g2/wiki/u8g2install
  98. The latest development version is available for download here:
  99. https://github.com/olikraus/U8g2_Arduino/archive/master.zip
  100. In the Arduino IDE use the Sketch>Include Library>Add .ZIP Library... menu to
  101. import the u8g2 zip library.
  102. Q: There is a compilation error with I2C/SPI library used by U8g2.
  103. A: U8g2 expects standard Arduino Wire and SPI libraries. However some
  104. none-Arduino Boards did not implement the full set of library functions.
  105. Examples are the missing setClock() or missing beginTransaction() functions.
  106. This is an issue with your board support library and not an issue of U8g2.
  107. Workaround:
  108. 1. Disable (comment) U8X8_HAVE_HW_SPI and/or U8X8_HAVE_HW_I2C in u8x8.h
  109. 2. Use SW SPI/SW I2C U8g2 constructors
  110. Q: What is the meaning of the F/1/2 in the U8g2 constructor name?
  111. A: "F" means full buffer mode. The entire display is rendered in RAM. Use
  112. "sendBuffer" to transfer this RAM buffer to the display. "1" and "2" constructors
  113. will store one or two pages of the display in RAM only.
  114. Use the firstPage/nextPage loop to create the image for the display.
  115. There are also two different sets of examples for both modes.
  116. Conclusion:
  117. "F" mode: Faster, but requires more RAM
  118. "1"/"2" modes: Use lesser RAM, but slower drawing speed.
  119. Q: Data is written only to the first 8 lines of the display. Why?
  120. A: U8g2 page mode constructor ("1" mode, see previous question) is used
  121. along with the "sendBuffer" command. This is a mistake and will not work.
  122. Solutions 1: Change the constructor to full buffer mode: Replace "_1_" by "_F_"
  123. Or solution 2: Replace "sendBuffer" with the firstPage/nextPage loop
  124. See also: https://github.com/olikraus/u8g2/wiki/u8g2setupcpp#constructor-name
  125. Q: What is the meaning of "SW"/"HW" in the U8g2 constructor name?
  126. A: "SW" means, that the protocol is emulated by software. For example
  127. the SW_I2C will not use the I2C subsystem of your board. The "HW" constructor
  128. will use the hardware subsystem on your uC. For an Arduino board, HW_I2C will
  129. call the Wire library for hardware accelerated I2C communication. "HW"
  130. constructors are much faster, but maybe debugging and setup is more
  131. easier with a "SW" constructor.
  132. Q: Why does the hardware I2C accept clock and data pins?
  133. The hardware I2C constructor looks like this:
  134. U8G2_<display>_HW_I2C(rotation, [reset [, clock, data]])
  135. This means there are three options to use this constructor:
  136. 1. U8G2_<display>_HW_I2C(rotation)
  137. 2. U8G2_<display>_HW_I2C(rotation, reset)
  138. 3. U8G2_<display>_HW_I2C(rotation, reset, clock, data)
  139. Hardware I2C usually is possible only with fixed pins. This means, the first or
  140. second form of the constructor must be used. As of today only the ESP8266
  141. support pin remapping. In such a case, also the third form can be used.
  142. Q: How to activate 16 Bit mode?
  143. A: Search for the line
  144. //#define U8G2_16BIT
  145. in "u8g2.h". Uncomment this line:
  146. #define U8G2_16BIT
  147. The file "u8g2.h" is located in "/libraries/U8g2_Arduino/src/clib" inside your default
  148. sketch folder.
  149. Q: What will change in 16 Bit mode?
  150. A: U8x8 is unaffected: U8x8 will use a "tile" coordinate system (1 tile = 8x8 pixel).
  151. As a result u8x8 can work with display dimensions of up to 2040x2040
  152. In U8g2 8 bit mode all pixel related calculations are done in 8 bit, which is faster
  153. and produces smaller code on 8 bit architectures like ATMega AVR.
  154. This will however restrict the display size to 255x255 (which is actually clipped at 240x240)
  155. In U8g2 16 bit mode the pixel related calculations are done in 16 bit. For 32 bit systems like ARM,
  156. there will be not much a difference between 16 bit mode and 8 bit mode, this is also why
  157. 16 bit mode is now default on ARMs. The maximum display dimension is then 65000x65000,
  158. however, because u8g2 just calls u8x8, the actual limit in 16 bit mode is 2040x2040 pixel.
  159. Q: U8g2 requires a lot of memory. How to reduce this?
  160. - Visit https://github.com/olikraus/u8g2/wiki/u8g2optimization
  161. - Disable U8g2 features if possible (see u8g2.h)
  162. - Limit the font size. If possible avoid "f" fonts, instead use "r" or "n" fonts
  163. - If the I2C interface is not required, then uncomment #define U8X8_HAVE_HW_I2C in U8x8lib.h
  164. (Background: Due to a problem in Wire.h, the I2C Arduino lib is always included)
  165. Q: There is no visible output output. What is can be done?
  166. - Check the wiring, see first part of this FAQ.
  167. - Check the constructor. Does it fit to your display?
  168. - Do not output a text at (0,0): The reference point for text is lower left, so
  169. u8g2_DrawStr(&u8g2, 0, 0, “Hello world!”); will not display anything. Instead use
  170. u8g2_DrawStr(&u8g2, 0, 20, “Hello world!”);
  171. Q: Only a small fraction of the display is visible. Why?
  172. A: With a "_1_" constructor, ensure to use the firstPage/nextPage loop.
  173. Q: U8g2 output is corrupted. What are possible causes?
  174. - Do not change the output inside the firstPage/nextPage loop:
  175. Do *not* call digitalRead/analogRead inside the firstPage/nextPage loop.
  176. Read any sensor values into a variable *before* firstPage() and use the
  177. variable value inside the loop.
  178. If the output includes unicode chars, use the UTF8 procedures.
  179. Q: U8g2 is slow. How to improve speed?
  180. A1: If there is sufficient RAM, use the F variant of the constructor (see the question
  181. on F/1/2 above).
  182. A2: Use hardware SPI or I2C communication. Software emulated SPI or I2C is much
  183. slower (see the question on SW and HW SPI/I2C above)
  184. A3: "firstPage/nextPage loop": Remove as much of code out of this loop. Try to
  185. precalculate as much of possible before the loop is entered.
  186. A4: "firstPage/nextPage loop": If the loop is still too slow, try to unroll the loop.
  187. See the StateBufferLoop example:
  188. https://github.com/olikraus/u8g2/blob/master/sys/arduino/u8g2_page_buffer/StateBufferLoop/StateBufferLoop.ino
  189. A5: For SW I2C and AVR architectures: Uncomment
  190. #define U8X8_USE_ARDUINO_AVR_SW_I2C_OPTIMIZATION
  191. in U8x8lib.h. This will increase speed a lot for I2C on all AVR uC. However the I2C
  192. bus is always driven by this implementation. Other I2C devices will not work on
  193. the same pins.
  194. A6: For HW I2C the default speed for some controllers is set 100KHz. However these
  195. controller often work with higher speed (200KHz or 400KHz). Suggestion is
  196. to test whether "u8g2.setBusClock(400000);" still works.
  197. Q: Umlaut chars or other chars with a unicode value greater than 127 do not
  198. appear on the displays. What is wrong?
  199. A; Check the following:
  200. Did you use drawUTF8() instead of drawStr()?
  201. Did you enable UTF8 when using print() with enableUTF8Print()?
  202. Does the font include the expected char? Fonts with a 'n' (numbers),
  203. 'u' (uppercase) or 'r' (restricted) at the end of the fontname do only
  204. include glyphs with unicode lower than 128.
  205. Q: How can I read a bitmap from SD card?
  206. A: There is an example, which includes a function "drawFile" which reads a bitmap
  207. from SD Card and writes the same to a u8g2 display:
  208. Example:
  209. https://github.com/olikraus/u8g2/blob/master/sys/arduino/u8g2_page_buffer/LoadFromSD/LoadFromSD.ino
  210. The example also includes a function which writes to the SD card, but there is also
  211. a commandline tool which converts PNG to the format which is accepted by "drawFile":
  212. https://github.com/olikraus/u8g2/tree/master/tools/png2bin
  213. Q: How can I generate my own font?
  214. A: The font must be available in .bdf file format. Then use bdfconv to generate
  215. the font data. The font data can be pasted into an existing file of your project.
  216. There is also a nice Windows Bitmap Font Editor "Fony" (http://hukka.ncn.fi/?fony)
  217. which can export .bdf files. A copy of Fony 1.4.7 is available here:
  218. https://github.com/olikraus/u8g2/tree/master/tools/font/fony
  219. Q: Where do I find bdfconv?
  220. A: A Windows executable is available here:
  221. https://github.com/olikraus/u8g2/tree/master/tools/font/bdfconv
  222. Use the Makefile in this directory to create a Linux binary.
  223. Q: How to convert .ttf to .bdf?
  224. A1: With otf2bdf: http://sofia.nmsu.edu/~mleisher/Software/otf2bdf/
  225. A2: With FontForge: https://learn.adafruit.com/custom-fonts-for-pyportal-circuitpython-display/conversion
  226. Q: Which commandline options are required for bdfconv?
  227. A: "bdfconv -f 1 -m '32-255' -n fontname -o myfont.c myfont.bdf"
  228. "-f 1" generates a u8g2 font.
  229. "-m '32-255'" selects unicode 32 to 255. On Windows, please use double quotes: -m "32-255"
  230. "-n fontname": This is the name of the font in C/C++/Ino files.
  231. "-o myfont.c": The font array will be stored in this file.
  232. "myfont.bdf": The input file with the font data (bdf format).
  233. Q: Is there any further help for the commandline options of bdfconv.exe?
  234. A: There is an online tool which helps you to derive the commandline options:
  235. https://stncrn.github.io/u8g2-unifont-helper/
  236. Many thanks to "stncrn" for making this available.
  237. Q: Are there any video-tutorials for bdfconv?
  238. A1: This is what I found on youtube: https://www.youtube.com/watch?v=Igkb7ZmO31A
  239. The above video uses the -M option (instead of -m) to provide a map file with the unicodes.
  240. A2: There is a video about fony and how to convert fonts from different sources (ttf, png) with bdfconv.exe:
  241. https://www.youtube.com/watch?v=WIAcy5FXuAA
  242. Q: Is there any simple way to create a font with some custom chars?
  243. A: This online tool might be useful: http://www.kidsgo.net/u8g2/
  244. Q: How can I use multiple SPI Displays?
  245. A: For each additional display, separate CS (Chip select) is required.
  246. There are two options for the RST (Reset) line:
  247. Also use separate lines or use the same GPIO pin.
  248. // Setup display1 and display2, both reset lines are connected to 4, execute display1.begin() first.
  249. U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI display1(U8G2_R0, /*CLK*/ 18, /*MOSI*/ 23, /*CS*/ 16,/*DC*/ 17, /*RST*/ 4);
  250. U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI display2(U8G2_R0, /*CLK*/ 18, /*MOSI*/ 23, /*CS*/ 15,/*DC*/ 17, /*RST*/ U8X8_PIN_NONE);
  251. // Setup display1 and display2, separate reset lines
  252. U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI display1(U8G2_R0, /*CLK*/ 18, /*MOSI*/ 23, /*CS*/ 16,/*DC*/ 17, /*RST*/ 4);
  253. U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI display2(U8G2_R0, /*CLK*/ 18, /*MOSI*/ 23, /*CS*/ 15,/*DC*/ 17, /*RST*/ 5);
  254. Ensure that the buffer is sent after printing with each display as follows.
  255. display1.begin();
  256. display2.begin();
  257. ...
  258. display1.setCursor(64, 32);
  259. display1.print("DISPLAY 1");
  260. display1.sendBuffer();
  261. display2.setCursor(64, 32);
  262. display2.print("DISPLAY 2");
  263. display2.sendBuffer();
  264. Q: How can I send individual/special commands to my display.
  265. A: The sequence is: Start transfer, send data and args, close transfer. Note that
  266. this is not portable, because these commands are specific to the display controller.
  267. The following C++/Arduino code will send one command with one argument to the
  268. display:
  269. u8x8_cad_StartTransfer(u8g2.getU8x8());
  270. u8x8_cad_SendCmd( u8g2.getU8x8(), <display command>);
  271. u8x8_cad_SendArg( u8g2.getU8x8(), <display-command-arg>);
  272. u8x8_cad_EndTransfer(u8g2.getU8x8());
  273. Q: RAM Overflow error when linking with u8g2
  274. A: With gcc use compiler flags -ffunction-sections -fdata-sections and
  275. linker flag -Wl,--gc-sections.