Skip to content

esp1/dot-matrix

Repository files navigation

Dot Matrix

Hardware

Software


A little electronics knowledge

Ohm's Law

  • Voltage = Current * Resistance
  • V = IR

A word on safety

  • These electronics operate at low voltages (5V or 3.3V) and currents (< 1A)
  • They will not shock you
  • You might shock them!
    • Be careful of short circuiting exposed pins
      • i.e. keep away from metal, keep pins from touching each other
      • I = V / R
      • when R = 0, I = infinite
    • Be careful of electrostatic discharge

What is a microcontroller?

And how is it different from the computers you're used to?

  • Basically a little computer that only runs 1 program
  • Tiny - can embed in almost anything
  • Power efficient - can run on a battery
  • Essentially instantaneous boot time
  • You can interact with the physical world! 😎
    • Lights, motors, switches, sensors, etc
  • You have to deal with the physical world 🙁
  • Debugging can be difficult
    • Have to debug hardware as well as software
      • Connection issues
    • No stack traces
    • No debugger
  • You can actually run out of memory, and you need to worry about this
  • Much easier to run into performance issues

ESP8266 microcontroller

  • CPU
  • Memory
    • RAM - volatile
    • Flash, EEPROM - non-volatile
  • Input/Output
    • 17 GPIO pins
    • SPI, I2C, I2S, UART
    • 10-bit ADC (Analog to Digital Converter)
  • IEEE 802.11 b/g/n Wi-Fi

ESP8266 Dev Kit

ESP8266 image

Anatomy:

  • ESP8266 microcontroller module
  • Power regulator
  • USB chip and connector
  • Reset button
  • Flash programming button
  • GPIO (General Purpose Input/Output) pins
  • we will be using pins:
    • GPIO14
    • GPIO13
    • GPIO15
    • GND
    • 3.3V

Firmware

  • The software that runs on a microcontroller
  • Needs to be installed ('flashed') into the non-volatile flash memory of the microcontroller

Arduino

  • Popular microcontroller software development platform
  • Originally made for AVR microcontrollers, but has been ported to other chips, including ESP8266
  • C++ library

Anatomy of an Arduino program:

  • void setup() - runs once on startup
  • void loop() - runs continuously after setup()

Blink

The 'Hello world' of embedded microcontroller programming

Code

  • Create new PlatformIO project
    • Name: Blinky
    • Board: NodeMCU 1.0 (ESP-12E Module)
    • Framework: Arduino
#include <Arduino.h>

void setup() {
  // put your setup code here, to run once:
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(LED_BUILTIN, HIGH);
  delay(200);
  digitalWrite(LED_BUILTIN, LOW);
  delay(200);
}
  • pinMode(pin, mode)
  • digitalWrite(pin, value)
  • delay(msec)

Connect

  • Connect ESP8266 to computer via USB cable (& adapter)
    • USB cable used for communication and power
  • Build firmware
  • Upload firmware
  • Reset button

Serial debug

#include <Arduino.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Hello");
  
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("On!");
  digitalWrite(LED_BUILTIN, HIGH);

  delay(200);

  Serial.println("Off.");
  digitalWrite(LED_BUILTIN, LOW);
  
  delay(200);
}
  • Serial.begin(baud_rate)
  • Serial.printf()
  • Serial Monitor

MAX7219 matrix display

  • The MAX7219 is an IC made for controlling 8 digit, 8 segment LED displays
  • Can also be used to control 8x8 LED matrix displays
  • Controlled via 3 pin SPI interface
  • Can be daisy chained

Connect Matrix display to ESP8266 dev board

                        MAX7219 
         4 8x8 LED matrix modules = 32x8 matrix
		 
        <-OUT                                IN<-                  ESP8266
                                                                Amica NodeMCU
      [r0, c31]    24       16       8     [r0, c0]
 bit  row +--------+--------+--------+--------+   pin         pin
   0   0  |        |        |        |        |  label       label
   2   1  |        |        |        |        | - CLK   <->    D5  GPIO14  HSCLK
   4   2  |        |        |        |        | - CS    <->    D8  GPIO15  HCS
   8   3  |    3   |    2   |    1   |    0   | - DIN   <->    D7  GPIO13  HMOSI
  16   4  |        |        |        |        | - GND   <->   GND 
  32   5  |        |        |        |        | - VCC   <->   3V3 
  64   6  |        |        |        |        |
 128   7  |        |        |        |        |
          +--------+--------+--------+--------+
      [r7, c31]    24       16       8     [r7, c0]

wiring diagram

Code

MD_MAX72XX matrix(
    MD_MAX72XX::FC16_HW,
    15, // CS
    4   // # of devices
);
  • matrix.begin()
  • matrix.clear()
  • matrix.setPoint(row, column, state)
  • matrix.setColumn(column, value)
    • uint8_t - 8 bits, 0 to 255

Dot Matrix

Try it

  • Build firmware
  • Upload firmware
  • Upload filesystem image
    • PlatformIO -> Project Tasks -> nodemcuv2 -> Platform -> Upload Filesystem Image
    • If you have problems, close any other processes that may be using the serial port, e.g. Serial Monitor

Initial setup

  • Matrix should display dot matrix
  • Open Serial Monitor
  • Connect to the dot matrix wifi network with your phone
  • The captive portal wifi settings page will appear
  • Enter text into the text box to see it show up on the LED display
  • Enter your wifi settings at the bottom of the page to have the Dot Matrix display connect to your wifi network instead of starting a captive portal

Normal operation

  • Matrix should display -> wifi and it will attempt to connect to your wifi network
  • When it connects, the matrix will display its IP address
  • Open the IP address of the matrix in a browser
  • Enter some text and see it show up on the matrix!
  • Disconnect from computer, power with e.g. USB battery

Code anatomy

setup()

  • server.serveStatic("/", LittleFS, "/web/")
    • data directory
  • server.on(url, callback)
    • req->hasParam()
    • req->getParam()
    • req->send()

loop()

  • render::update_display(&state)
  • delay(state.loop_delay_msec)

Testing firmware

  • Put tests in test dir
  • Run PlatformIO: Test command

Updating web application code

  • Put web application code in data/web/

3D Printed Enclosure

enclosure image 1

enclosure image 2

Here are files to 3D print an enclosure for the LED matrix:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published