Manufaturação industrial
Internet das coisas industrial | Materiais industriais | Manutenção e reparo de equipamentos | Programação industrial |
home  MfgRobots >> Manufaturação industrial >  >> Manufacturing Technology >> Processo de manufatura

Matriz LED 8x8 com Bluetooth e Texto Rolante – Projeto Arduino

Componentes e Materiais

Arduino Nano R3 1
Módulo Bluetooth HC-05 1
Módulo Matriz LED 8x8 com MAX7219 7
Resistor 6.8 kΩ 1
Resistor 2.2 kΩ 2

Ferramentas Necessárias

Aplicativos e Serviços Online

Sobre o Projeto

Após várias tentativas de fazer texto rolante na matriz 8x8, encontrei o manual mais completo na página Embedded Lab: Portable Bluetooth Enabled Scrolling LED Matrix Display.

O dispositivo contém um Arduino Nano, módulo Bluetooth para receber dados do smartphone e matrizes 8x8 LED controladas por MAX7219.

Diferente do original, usei módulos prontos de matriz 8x8 com chip MAX7219, disponíveis barato no eBay ou AliExpress. No momento tinha apenas 7 módulos, então fiz pequena modificação no código. O app Android não existe mais na Google Play Store, pode baixar em: Bluetooth SPP Pro. Controla velocidade do scroll, brilho dos LEDs, pausa, apaga texto, e vários botões de texto predefinidos.

No final, coloquei tudo em uma caixa feita de material PVC com papel de parede preto.

Bibliotecas Arduino:

Código

/* Comandos reconhecidos pelo Arduino:
1. Qualquer fluxo de caracteres deve ser enviado entre parênteses.
   Exemplo: Para exibir "Hello! How are you?" envie: (Hello! How are you?)
   Ao receber '(', entende que caracteres seguintes são dados de exibição até ')'.
   Mensagem exibida rolando da direita para esquerda.
2. Intensidade do display incrementada/decrementada enviando /+ ou /- respectivamente.
   A cada '/', entende que é comando. Suporta 16 níveis de brilho.
3. Velocidade do scroll aumentada/diminuída enviando /< ou /> respectivamente.
4. /p pausa a mensagem rolante. Enviar novamente retoma.
5. /e apaga buffer e limpa display

Conexões:
Easy Matrix    Arduino
VCC            +5V
DIN            MOSI (Pino 11)
LOAD           pinCS (definido no programa)
CLK            SCK (Pino 13)
GND            Gnd

Comunicação UART a 9600 baud.
Escrito por: Rajendra Bhatt
Contato: admin@embedded-lab.com
Link produto Easy Matrix: https://embedded-lab.com/blog/?p=9186
*/
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>

int pinCS = 10; // CS neste pino, DIN no MOSI e CLK no SCK
int numberOfHorizontalDisplays = 7;
int numberOfVerticalDisplays = 1;
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);

int scrollspeed = 100; // Velocidade scroll padrão (ms)
int spacer = 1; // Espaço entre caracteres
int width = 5 + spacer; // Largura da fonte = 5 pixels
boolean inChar = false, NewData = false, pause = false;
boolean dataAvailable = false;
char inputString[512];
int count = 0, BTvalue = 5;

void setup() {
  matrix.setIntensity(1); // Valor entre 0 e 15 para brilho
  // Ajuste conforme necessário
  matrix.setPosition(0, 0, 0);
  matrix.setPosition(1, 1, 0);
  matrix.setPosition(2, 2, 0);
  matrix.setPosition(3, 3, 0);
  matrix.setPosition(4, 4, 0);
  matrix.setPosition(5, 5, 0);
  matrix.setPosition(6, 6, 0);
  // matrix.setRotation(0, 2); // Primeiro display de cabeça para baixo
  // matrix.setRotation(3, 2); // O mesmo para o último display
  matrix.fillScreen(0);
  matrix.write();
  Serial.begin(9600);
  pinMode(2, INPUT);
  digitalWrite(2, LOW);
  attachInterrupt(0, serialInterrupt, CHANGE);
}

void loop() {
  if (dataAvailable) {
    display_data();
  }
}

void display_data() {
  for (int i = 0; i < width * count + matrix.width() - 1 - spacer; i++) {
    matrix.fillScreen(0);
    int letter = i / width;
    int x = (matrix.width() - 1) - i % width;
    int y = (matrix.height() - 8) / 2; // Centraliza texto verticalmente
    while (x + width - spacer >= 0 && letter >= 0) {
      if (letter < count) {
        matrix.drawChar(x, y, inputString[letter], HIGH, LOW, 1);
      }
      letter--;
      x -= width;
    }
    matrix.write();
    if (!dataAvailable) {
      i = width * count + matrix.width() - 1 - spacer;
      matrix.fillScreen(LOW);
      matrix.write();
    }
    if (NewData) {
      i = 0;
      matrix.fillScreen(LOW);
      matrix.write();
      NewData = false;
    }
    while (pause == true) {
      delay(0);
    }
    delay(scrollspeed);
  }
}

volatile boolean inService = false;

void serialInterrupt() {
  if (inService) return;
  inService = true;
  interrupts();
  while (!Serial.available());
  while (Serial.available()) {
    char ch = Serial.read();
    if (ch == '(') {
      count = 0;
      inChar = true;
      while (inChar) {
        if (Serial.available()) {
          ch = Serial.read();
          if (ch == ')') {
            inChar = false;
            dataAvailable = true;
          } else {
            inputString[count] = ch;
            count++;
          }
          if (count > 0) {
            NewData = true;
          }
        }
      }
    }
    if (ch == '/') {
      inChar = true;
      while (inChar) {
        if (Serial.available()) {
          ch = Serial.read();
          // '/+' incrementa brilho
          if (ch == '+') {
            if (BTvalue < 15) {
              BTvalue++;
              matrix.setIntensity(BTvalue);
            }
            break;
          }
          // '/-' decrementa brilho
          if (ch == '-') {
            if (BTvalue > 0) {
              BTvalue--;
              matrix.setIntensity(BTvalue);
            }
            break;
          }
          // '/>' torna scroll mais lento
          if (ch == '>') {
            if (scrollspeed < 200) {
              scrollspeed += 20;
            }
            break;
          }
          // '/<' torna scroll mais rápido
          if (ch == '<') {
            if (scrollspeed > 10) {
              scrollspeed -= 10;
            }
            break;
          }
          // '/e' apaga display
          if (ch == 'e') {
            dataAvailable = false;
            break;
          }
          // '/p' pausa display
          if (ch == 'p') {
            if (pause == false) {
              pause = true;
            } else {
              pause = false;
            }
            break;
          } else {
            break; // Comando não reconhecido
          }
        }
      }
    }
  }
  inService = false;
}

Esquemáticos

Matriz LED 8x8 com Bluetooth e Texto Rolante – Projeto Arduino

Processo de manufatura

  1. Mealheiro Inteligente: Controlar Aceitador de Moedas com Arduino Nano
  2. Construa um Console Pong 24×16 LED com Arduino Nano e MAX7219
  3. Controlar um LED via Bluetooth com Arduino – Guia DIY Simples
  4. Teletransportador de Texto Bluetooth: Arduino + Android
  5. Eletrodomésticos Ativados por Voz: Controle Bluetooth com Google Assistant
  6. Controlando Matriz de LED 8×8 com Arduino Uno: Guia Passo a Passo
  7. Medição Precisa de Radiação Solar com Arduino UNO e Ethernet Shield
  8. Controle Remoto de Carro com Arduino Uno e Bluetooth: Guia Passo a Passo
  9. Envie e Receba SMS Facilmente com o Shield GSM SIM900 para Arduino Mega
  10. UPS HID com Arduino: Transforme Fonte "Burra" em Backup USB Inteligente