﻿{"id":1809,"date":"2019-01-08T22:23:27","date_gmt":"2019-01-08T14:23:27","guid":{"rendered":"http:\/\/nick.txtcc.com\/?p=1809"},"modified":"2019-01-08T22:26:16","modified_gmt":"2019-01-08T14:26:16","slug":"nodemcu8266%e9%a9%b1%e5%8a%a88x8%e7%82%b9%e9%98%b5max7219","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/scm\/1809","title":{"rendered":"NodeMCU8266\u9a71\u52a88\u00d78\u70b9\u9635max7219"},"content":{"rendered":"<img decoding=\"async\" class=\"aligncenter size-full wp-image-497\" src=\"http:\/\/nick.txtcc.com\/wp-content\/uploads\/remote_image\/2019\/01\/1423293jS.png\" sizes=\"(max-width: 1085px) 100vw, 1085px\" alt=\"\" \/>\n<p>Since the awesome\u00a0<a href=\"https:\/\/github.com\/devsaurus\" target=\"_blank\" rel=\"noopener\">devsaurus<\/a>\u00a0recently fixed\u00a0<a href=\"https:\/\/github.com\/nodemcu\/nodemcu-firmware\/pull\/693\" target=\"_blank\" rel=\"noopener\">important SPI issues<\/a>\u00a0(<a href=\"https:\/\/github.com\/nodemcu\/nodemcu-firmware\/issues\/50#issuecomment-75843276\" target=\"_blank\" rel=\"noopener\">#50<\/a>\u00a0is from Christmas 2014!) in NodeMCU it\u2019s now possible to run\u00a0<a href=\"http:\/\/www.banggood.com\/2Pcs-MAX7219-Dot-Matrix-MCU-LED-Display-Control-Module-Kit-For-Arduino-p-945280.html?p=PT19151269030201502M\" target=\"_blank\" rel=\"noopener\">MAX7219 8\u00d78 LED matrix<\/a>\u00a0displays with an ESP8266 and the NodeMCU firmware.<\/p>\n<h2>Connect NodeMCU with MAX7219 display<\/h2>\n<p>According to the\u00a0<a href=\"https:\/\/github.com\/nodemcu\/nodemcu-devkit-v1.0\" target=\"_blank\" rel=\"noopener\">pin layout<\/a>\u00a0for the\u00a0<a href=\"http:\/\/www.banggood.com\/NodeMcu-Lua-WIFI-Development-Board-For-ESP8266-Module-p-976440.html?p=PT19151269030201502M\" target=\"_blank\" rel=\"noopener\">NodeMCU dev kit v1<\/a>\u00a0and\u00a0<a href=\"http:\/\/s.click.aliexpress.com\/e\/6EqB2naAA\" target=\"_blank\" rel=\"noopener\">v2<\/a>\u00a0(see\u00a0<a href=\"http:\/\/frightanic.com\/iot\/comparison-of-esp8266-nodemcu-development-boards\/\">comparison<\/a>) you need to connect the MAX7212 as follows:<\/p>\n<table class=\"table table-striped\">\n<thead>\n<tr>\n<th>MAX7219<\/th>\n<th>ESP8266<\/th>\n<th>NodeMCU devkit<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>VCC<\/td>\n<td>+3.3V<\/td>\n<td>3V3<\/td>\n<\/tr>\n<tr>\n<td>GND<\/td>\n<td>GND<\/td>\n<td>GND<\/td>\n<\/tr>\n<tr>\n<td>DIN<\/td>\n<td>HSPID\/HMOSI<\/td>\n<td>D7<\/td>\n<\/tr>\n<tr>\n<td>CS<\/td>\n<td>HSPICS\/HCS<\/td>\n<td>D8<\/td>\n<\/tr>\n<tr>\n<td>CLK<\/td>\n<td>HSPICLK\/HSCLK<\/td>\n<td>D5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In the second column I listed commonly found names on pin layouts and schemas. The values in the third column signify the actual pin numbers as printed on the NodeMCU development boards.<\/p>\n<h2>Drawing on the MAX7219<\/h2>\n<p>Writing and drawing on those 8\u00d78 matrix displays took some getting used to for me. Interestingly the fact that you can rotate them whichever way you like made it\u00a0<em>more<\/em>\u00a0difficult rather than less difficult. There is a way to\u00a0<a href=\"http:\/\/www.gammon.com.au\/forum\/?id=11516\" target=\"_blank\" rel=\"noopener\">identify pin 1<\/a>\u00a0but eventually it doesn\u2019t really matter. However, you need to understand how \u201ccharacters\u201d are represented.<\/p>\n<p>In font files (e.g.\u00a0<a href=\"https:\/\/github.com\/squix78\/MAX7219LedMatrix\/blob\/master\/cp437font.h\" target=\"_blank\" rel=\"noopener\">cp437.h<\/a>) you\u2019ll usually see one character per line as an array of 8 hex values. This could look as follows for \u20180\u2019 (zero) :<\/p>\n<p><code>{ 0x3E, 0x7F, 0x71, 0x59, 0x4D, 0x7F, 0x3E, 0x00 }<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-1800 size-full\" src=\"https:\/\/dziadalnfpolx.cloudfront.net\/blog\/wp-content\/uploads\/2015\/10\/MAX7219-8x8-LED-matrix-e1445717926318.png\" alt=\"MAX7219 8x8 LED matrix displaying 0x3E\" width=\"184\" height=\"283\" \/>There is one byte per column of the 8\u00d78 matrix i.e. 8 bytes. One byte signifies\u00a0<em>which<\/em>\u00a0of the 8 LEDs in a column should be turned on.\u00a0<code>0x3E<\/code>\u00a0in binary form is\u00a0<code>00111110<\/code>\u00a0and every bit represents the state of one LED. So, the first LED and the last two will be OFF while the others will be ON. Again, the notion of \u201cfirst\u201d and \u201clast\u201d of course depends on the orientation of the matrix but as long as all characters are defined consistently it doesn\u2019t matter.\u00a0<code>0x3E<\/code>\u00a0on the matrix will look as shown on the left.<\/p>\n<p>&nbsp;<\/p>\n<h2>Moody, cycling through smilys<\/h2>\n<p>Moody is a simple program that declares 3 smilys and an array which contains all of them. It shows how to initialize NodeMCU\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Serial_Peripheral_Interface_Bus\" target=\"_blank\" rel=\"noopener\">SPI<\/a>\u00a0for the MAX7219 8\u00d78 LED matrix and how to cycle through the smilys array and display one face after the other in a loop.<\/p>\n<div class=\"gist-oembed\" data-gist=\"marcelstoer\/63f138f47f765e602a64.json\"><\/div>\n<h2>Showtime, please<\/h2>\n<p><span class=\"embed-youtube\"><iframe loading=\"lazy\" class=\"youtube-player\" src=\"https:\/\/www.youtube.com\/embed\/Voihp1yu_gs?version=3&#038;rel=1&#038;fs=1&#038;autohide=2&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent\" width=\"792\" height=\"446\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>Since the awesome\u00a0devsaurus\u00a0recently fixed\u00a0important SPI issues\u00a0(#50\u00a0is from Christmas 2014!) in Nod&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39],"tags":[],"class_list":["post-1809","post","type-post","status-publish","format-standard","hentry","category-scm"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=1809"}],"version-history":[{"count":4,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1809\/revisions"}],"predecessor-version":[{"id":1815,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1809\/revisions\/1815"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=1809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=1809"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=1809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}