Blynk and M5Stack

Using my M5Stack with Blynk makes sense: it has plenty sensors and a display and LEDs.

❯ export AMPY_PORT=/dev/ttyUSB0
❯ export AMPY_BAUD=115200
❯ ampy ls /flash
/flash/apps
/flash/blocks
/flash/boot.py
/flash/emojiImg
/flash/img
/flash/main.py
/flash/res
❯ ampy mkdir /flash/lib
❯ ampy put BlynkLib.py /flash/lib/BlynkLib.py
❯ ampy get /flash/boot.py > boot.py
# Edit boot.py to include /flash/lib in the Python search path
# Like this:
#import machine, os, sys
#try:
#    sd = machine.SDCard(slot=3, miso=19, mosi=23, sck=18, cs=4)
#    sd.info()
#    os.mount(sd, '/sd')
#    print("SD card mounted at \"/sd\"")
#    sys.path.append('/flash/lib')
#except:
#    pass
❯ ampy put boot.py /flash/boot.py

Sample program:

from m5stack import *
from m5ui import *
from uiflow import *

import BlynkLib

BLYNK_AUTH = "YOUR_BLYNK_AUTH_KEY"
blynk = BlynkLib.Blynk(BLYNK_AUTH)

setScreenColor(0x000000)
lcd.clear()

# Register virtual pin handler
@blynk.on("V3")
def v3_write_handler(value):
  v=int(value[0])
  s='Current slider value:'+str(v)+'.'
  lcd.clear(0x000000)
  lcd.text(0, 20, s)

while True:
  blynk.run()

Using the Bylnk App update Virtual Pin 3 and the value should be displayed on the M5Stack’s LCD.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create your website at WordPress.com
Get started
%d bloggers like this: