Starting with MicroPython and Blynk

Hi everybody,

I’m trying to start with Blynk using Micropython. However the official library seems to be too outdated

For that reason I’m using the library BlynkLib.py provided here

I have written an small program that I run locally that reads from the analog input (A0)

from machine import Pin, ADC
from time import sleep

pot = ADC(0)
led = Pin(2, Pin.OUT)

while True:
  pot_value = pot.read()
  print(pot_value)

I’d like to use Blynk to see the value of the analog input (A0) on my Dashboard in Blynk, I only got this

import BlynkLib

blynk = BlynkLib.Blynk('BLYNK_AUTH_TOKEN')

while True:
    blynk.run()

When I run the code, it connects to Blynk and I can see the status changes to ONLINE :smiley:
But if I try to add more code like:

@blynk.handle_event('read V02')
def my_read_handler():

I got errors:

AttributeError: 'Blynk' object has no attribute 'handle_event'

Unfortunatelly I couldn’t find examples that helped me

I’d appreciate if you can share an example with me or any suggestion, thanks!

@richard Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

Done it and thanks for help me to improve my post @PeteKnight
Now is more readable

1 Like

If you look at the examples for the Blynk library that you are now using (which is the correct, up-to-date official Blynk library, provided you have v1.0.0 manually installed) then you will see that a different syntax is needed.

Example “02_on_virtual_change.py” shows this syntax for the virtual pin handler…

# Register virtual pin handler
@blynk.on("V3")
def v3_write_handler(value):
    print('Current slider value: {}'.format(value[0]))

Pete.