├── LICENSE ├── README.md └── ScrollingTextMatrixTelegram └── ScrollingTextMatrixTelegram.ino /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Brian Lough 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ScrollingLEDMatrixTelegram 2 | Send messages to a LED Matrix display through Telegram. Inspired by a tweet from Smarter Every Day 3 | 4 | ## Parts 5 | 6 | I used the following parts to build the project: 7 | 8 | - [ESP32 i2s Matrix Shield available on Tindie](https://www.tindie.com/products/brianlough/esp32-i2s-matrix-shield/) - This is not essential, you can use the wiring diagram [described here](https://github.com/mrfaptastic/ESP32-HUB75-MatrixPanel-I2S-DMA#wiring-esp32-with-the-led-matrix-panel) 9 | - ESP32 Mini32 Development board (ESP32 D1 Mini) 10 | - [Aliexpress\*]( https://s.click.aliexpress.com/e/_dSi824B) 11 | - [Amazon.com\*](https://amzn.to/3gArkAY) 12 | - Also available as an add-on on the Tindie listing 13 | - 2 x RGB LED Matrix. 64x32 P3 Matrix display - [Aliexpress\*](https://s.click.aliexpress.com/e/_dYz5DLt) 14 | 15 | If you are not using my shield, you can use the method described in [step 5 of this post](https://www.instructables.com/RGB-LED-Matrix-With-an-ESP8266/) to power the panel. 16 | 17 | I also mention in the video about a bigger power supply, it's not important for this project as the scrolling text doesn't use much power (how many leds are on dictates how much power is used) but for other projects you would be safer to use one. This is the one I use: [5V 8A laptop style power supply\*]( https://s.click.aliexpress.com/e/_d7uVLXt) 18 | 19 | ## Instructions 20 | 21 | ### Arduino Software Setup 22 | 23 | These are the steps for setting up the Arduino IDE to work with the ESP32. 24 | 25 | - Download and install the [Arduino IDE](https://www.arduino.cc/en/software). (Note: you can not use the web version) 26 | - Follow [these instructions](https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md) to install the ESP32 Software for the Arduino IDE. (Use the "stable release" URL) 27 | 28 | ### Programming the board 29 | 30 | These steps assume you are using the same board I did in the video, and may need to be adapted for different boards. When finished these steps you should be able to install the Blink sketch 31 | 32 | - In the Arduino IDE, got to "Tools->Board:" and under the "ESP32 Arduino" section select "WEMOS D1 Mini ESP32" 33 | - Expand "Tools-> Port:" and take note of the options, then plug the USB cable into your board and repeat the same steps. The new option that shows up is your board, select it. (If no new option shows up, you may need to [install a driver]). 34 | 35 | ### Installing Arduino Libraries 36 | 37 | Some of features I used in the video came from libraries. This section will allow you to install these libraies. 38 | 39 | - In the Arduino IDE, go to "Sketch -> Include Library -> Manage Libraries" 40 | - When the Library Manager Opens, search for and then install the following libraries: 41 | - **Universal Telegram Library** by Brian Lough 42 | - **Arduino Json** by Benoit Blanchon 43 | - **ESP32 HUB75 LED MATRIX PANEL DMA Display** by Faptastic 44 | - **Adafruit GFX** by Adafruit 45 | 46 | ### Enabling Two Matrix Displays 47 | 48 | This section is what configures the LED Matrix to work with two panels instead of one. 49 | 50 | - Open the "Arduino" folder, it is under the "Documents" folder on both Windows and Mac. 51 | - In that folder open "libraries" and then "ESP32_HUB75_LED_MATRIX_PANEL_DMA_Display" folder 52 | - Open the "ESP32-HUB75-MatrixPanel-I2S-DMA.h" file with a text editor 53 | - Change ` #define MATRIX_WIDTH 64` to `#define MATRIX_WIDTH 128`. You will need to change this value back if you ever go back to using a single panel. 54 | 55 | ### Setting Up Telegram 56 | 57 | These are the steps you need to get a bot token to use in your porject. 58 | 59 | - Install Telegram from your phones app store (I believe you need to set the account up on your phone to begin with, I'm not 100% sure though as I set it up years ago). Once logged in you can install the desktop versions, or even use the Telegram web interface version. 60 | - Inside Telegram, search for a user called "botfather" and open a chat 61 | - Click the "/newbot" option or you can type that message in either (exactly as shown) 62 | - Follow the on screen instructions to create your bot 63 | - You will get a message back with the token, you can copy this into Arduino code. 64 | - You should click on the link up the top of the message to open the chat with the new bot. There will be a "/start" button, you should click that to activate the bot. 65 | -------------------------------------------------------------------------------- /ScrollingTextMatrixTelegram/ScrollingTextMatrixTelegram.ino: -------------------------------------------------------------------------------- 1 | /******************************************************************* 2 | A scrolling text sign on 2 RGB LED matrixes where the text 3 | can be updated via telegram. 4 | 5 | Parts Used: 6 | 2 x 64x32 P3 Matrix display * - https://s.click.aliexpress.com/e/_dYz5DLt 7 | ESP32 D1 Mini * - https://s.click.aliexpress.com/e/_dSi824B 8 | ESP32 I2S Matrix Shield (From my Tindie) = https://www.tindie.com/products/brianlough/esp32-i2s-matrix-shield/ 9 | 10 | * * = Affilate 11 | 12 | If you find what I do useful and would like to support me, 13 | please consider becoming a sponsor on Github 14 | https://github.com/sponsors/witnessmenow/ 15 | 16 | 17 | Written by Brian Lough 18 | YouTube: https://www.youtube.com/brianlough 19 | Tindie: https://www.tindie.com/stores/brianlough/ 20 | Twitter: https://twitter.com/witnessmenow 21 | *******************************************************************/ 22 | 23 | // ---------------------------- 24 | // Standard Libraries 25 | // ---------------------------- 26 | 27 | #include 28 | #include 29 | 30 | // ---------------------------- 31 | // Additional Libraries - each one of these will need to be installed. 32 | // ---------------------------- 33 | 34 | #include 35 | // This is the library for interfacing with the display 36 | 37 | // Can be installed from the library manager (Search for "ESP32 MATRIX DMA") 38 | // https://github.com/mrfaptastic/ESP32-HUB75-MatrixPanel-I2S-DMA 39 | 40 | #include 41 | // This is the library for connecting to Telegram 42 | 43 | // Can be installed from the library manager (Search for "Universal Telegram") 44 | // https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/ 45 | 46 | // ---------------------------- 47 | // Dependancy Libraries - each one of these will need to be installed. 48 | // ---------------------------- 49 | 50 | // Adafruit GFX library is a dependancy for the matrix Library 51 | // Can be installed from the library manager 52 | // https://github.com/adafruit/Adafruit-GFX-Library 53 | 54 | // ArduinoJson is used for parsing Json from the API responses. 55 | // It is required by the Telegram Library. 56 | // Search for "Arduino Json" in the Arduino Library manager 57 | // https://github.com/bblanchon/ArduinoJson 58 | 59 | 60 | // ------------------------------------- 61 | // ------- Replace the following! ------ 62 | // ------------------------------------- 63 | 64 | // Wifi network station credentials 65 | #define WIFI_SSID "YOUR_SSID" 66 | #define WIFI_PASSWORD "YOUR_PASSWORD" 67 | 68 | // Telegram BOT Token (Get from Botfather) 69 | #define BOT_TOKEN "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 70 | 71 | //------- ---------------------- ------ 72 | 73 | // True enables dubble buffer, this reduces flicker 74 | MatrixPanel_I2S_DMA dma_display(true); 75 | 76 | WiFiClientSecure secured_client; 77 | UniversalTelegramBot bot(BOT_TOKEN, secured_client); 78 | 79 | // ------------------------------------- 80 | // ------- Text Configuraiton ------ 81 | // ------------------------------------- 82 | 83 | #define FONT_SIZE 2 // Text will be FONT_SIZE x 8 pixels tall. 84 | 85 | int delayBetweeenAnimations = 35; // How fast it scrolls, Smaller == faster 86 | int scrollXMove = -1; //If positive it would scroll right 87 | 88 | int textXPosition = dma_display.width(); // Will start one pixel off screen 89 | int textYPosition = dma_display.height() / 2 - (FONT_SIZE * 8 / 2); // This will center the text 90 | 91 | String text = "Hello Smarter Every Day!"; //Starting Text 92 | 93 | //------- ---------------------- ------ 94 | 95 | // For scrolling Text 96 | unsigned long isAnimationDue; 97 | 98 | uint16_t myBLACK = dma_display.color565(0, 0, 0); 99 | uint16_t myWHITE = dma_display.color565(255, 255, 255); 100 | uint16_t myRED = dma_display.color565(255, 0, 0); 101 | uint16_t myGREEN = dma_display.color565(0, 255, 0); 102 | uint16_t myBLUE = dma_display.color565(0, 0, 255); 103 | 104 | void setup() { 105 | 106 | Serial.begin(115200); 107 | 108 | // Display Setup 109 | dma_display.begin(); 110 | dma_display.fillScreen(myBLACK); 111 | dma_display.showDMABuffer(); 112 | dma_display.setTextSize(FONT_SIZE); 113 | dma_display.setTextWrap(false); // N.B!! Don't wrap at end of line 114 | dma_display.setTextColor(myRED); // Can change the colour here 115 | 116 | // attempt to connect to Wifi network: 117 | Serial.print("Connecting to Wifi SSID "); 118 | Serial.print(WIFI_SSID); 119 | WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 120 | secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org 121 | while (WiFi.status() != WL_CONNECTED) 122 | { 123 | Serial.print("."); 124 | delay(500); 125 | } 126 | Serial.print("\nWiFi connected. IP address: "); 127 | Serial.println(WiFi.localIP()); 128 | 129 | 130 | } 131 | 132 | // Will be used in getTextBounds. 133 | int16_t xOne, yOne; 134 | uint16_t w, h; 135 | bool checkTelegram = false; 136 | 137 | void loop() { 138 | unsigned long now = millis(); 139 | if (now > isAnimationDue) 140 | { 141 | // This tells the code to update the second buffer 142 | dma_display.flipDMABuffer(); 143 | 144 | // This sets the timer for when we should scroll again. 145 | isAnimationDue = now + delayBetweeenAnimations; 146 | 147 | textXPosition += scrollXMove; 148 | 149 | // Checking if the very right of the text off screen to the left 150 | dma_display.getTextBounds(text, textXPosition, textYPosition, &xOne, &yOne, &w, &h); 151 | if (textXPosition + w <= 0) 152 | { 153 | checkTelegram = true; 154 | textXPosition = dma_display.width(); 155 | } 156 | 157 | dma_display.setCursor(textXPosition, textYPosition); 158 | 159 | // The display has to do less updating if you only black out the area 160 | // the text is 161 | //dma_display.fillScreen(myBLACK); 162 | dma_display.fillRect(0, textYPosition, dma_display.width(), FONT_SIZE * 8, myBLACK); 163 | 164 | dma_display.print(text); 165 | 166 | // This code swaps the second buffer to be visible (puts it on the display) 167 | dma_display.showDMABuffer(); 168 | 169 | } 170 | 171 | // Telegram will only be checked when there is no data on screen 172 | // as checking interfeers with scrolling. 173 | if (checkTelegram) 174 | { 175 | checkTelegram = false; 176 | int numNewMessages = bot.getUpdates(bot.last_message_received + 1); 177 | 178 | if (numNewMessages > 0) 179 | { 180 | Serial.println("got response"); 181 | 182 | // This is where you would check is the message from a valid source 183 | // You can get your ID from myIdBot in the Telegram client 184 | //if(bot.messages[0].chat_id == "175753388") 185 | if (true) { 186 | // Takes the contents of the message, and sets it to be displayed. 187 | text = bot.messages[0].text; 188 | } 189 | } 190 | } 191 | 192 | } 193 | --------------------------------------------------------------------------------