Displaying Telegram Message on Dot Matrix Using Raspberry Pi

In this video we will show you how to display Telegram message on dot matrix using Raspberry Pi.

INTRODUCTION

Continue from the previous tutorial Displaying On MAX7219 Dot Matrix Using Raspberry Pi. In this video we will show you how to display Telegram message on 4 In 1 MAX7219 Dot Matrix Display Module Using Raspberry Pi.

VIDEO

In this video we will show you how to display Telegram message on 4 In 1 MAX7219 Dot Matrix Display Module Using Raspberry Pi.

HARDWARE PREPARATION

Wiring Connections

4 In 1 MAX7219 Dot Matrix Display ModuleMaker pHAT
VCC5V
GNDGND
DINMOSI
CSCE0
CLKSCK

Software Preparation

Install Telegram Bot library for Python. Open Terminal and write following command.

sudo apt-get install python-pip

sudo pip install telepot

Sample Code

Write this code to display Telegram message on dot matrix. Please edit and put your Telegram Bot token in the code.

from gpiozero import Buzzer
from time import time, sleep, strftime
from datetime import datetime
import telepot
from luma.core.interface.serial import spi, noop
from luma.core.render import canvas
from luma.core.virtual import viewport
from luma.led_matrix.device import max7219
from luma.core.legacy import text, show_message
from luma.core.legacy.font import proportional, CP437_FONT, LCD_FONT
serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, width=32, height=8, block_orientation=-90)
device.contrast(5)
virtual = viewport(device, width=32, height=16)
buzzer = Buzzer(26)
def handle(msg):
global telegramText
global chat_id
global showMessage
chat_id = msg['chat']['id']
telegramText = msg['text']
print('Message received from ' + str(chat_id))
if telegramText == '/start':
bot.sendMessage(chat_id, 'Welcome to Idris Dot Matrix Bot')
else:
buzzer.beep(0.1, 0.1, 2)
showMessage = True
bot.sendMessage(chat_id, 'Text received.')
bot = telepot.Bot('PUT YOUR TELEGRAM BOT TOKEN HERE')
bot.message_loop(handle)
show_message(device, 'Telegram Bot Ready!', fill="white", font=proportional(LCD_FONT), scroll_delay=0.05)
showMessage = False
count = 0
try:
while True:
if showMessage == True:
show_message(device, telegramText, fill="white", font=proportional(LCD_FONT), scroll_delay=0.1)
count = count + 1
if count == 3:
count = 0
showMessage = False
else:
with canvas(virtual) as draw:
#text(draw, (0, 1), "Idris", fill="white", font=proportional(CP437_FONT))
text(draw, (0, 1), datetime.now().strftime('%I:%M'), fill="white", font=proportional(CP437_FONT))
except KeyboardInterrupt:
show_message(device, 'Thanks...', fill="white", font=proportional(LCD_FONT), scroll_delay=0.05)

Thank you

References

  1. Luma.LED_Matrix, credit to Richard Hull.
  2. Telegram Bot Python Library 

Thanks for reading this tutorial. If you have any technical inquiry, please post at Cytron Technical Forum.

1 thought on “Displaying Telegram Message on Dot Matrix Using Raspberry Pi”

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

Send Data to Firebase Using Arduino Uno WiFi Rev2
Simple Alarm System Using Maker Nano
Program Cucumber ESP32-S2 Using CircuitPython
Face Recognition Using OpenCV on Raspberry Pi 400
Turned Your Tablet as a Display for the Raspberry Pi 400
Scroll to Top