Read one more vpins in micropython

hello,
I’m new on Blynk and I follow esp8266 example 01_potentiometer.py from your https://github.com/blynkkk/lib-python..it’s running well. Once I tried to add one more digital pin from my ESP8266 GPIO#4 as input pin and bind another V2 to LED widget for reading GPIO4 status but I found error that @blynk.handle_event(‘read V1’,read V2) which it won’t accept additional argument ‘read V2’ that I added it. Then I created one more r@blynk.handle_event(‘read V2’) function to make only one argument each. It’s running but taking care only first @blynk.handle_event(‘read V1’) handler, my additional V2 is not compiled. I’m running with latest lib as blynklib_mp version 0.2.6 on esp8266. Could you please guide me on how to handle one more digital pins either read/write. What happen once someone need to assign vPin more than 128. Could we assign multi digital pin under one vPin ? I’m sorry to ask many question as I said that I’m new for Blynk and almost of Blynk documents rely on Scretch not microPython…

adc = machine.ADC(0) #8266 ADC pins
door = machine.Pin(4, machine.Pin.IN)

@blynk.handle_event('read V1') 
def read_handler(vpin):
    p_value = adc.read() # read from AO 8266 pin
    print(' {} = {}  '.format(now(),p_value))
    blynk.set_property(vpin, 'color', 
    blynk.virtual_write(vpin, p_value) # write to Application
@blynk.handle_event('read V2') 
def read_handler(vdoor):
    door_value = door.value() # read from AO 8266 pin
    print(' {} = {}  '.format(now(), door_value))
    blynk.set_property(vdoor, 'color', '#FFFF00') # set red color for the widget UI element as #RRGGBB mixing between 00-FF in each colour
    blynk.virtual_write(vdoor, door_value) # write to Application
    #blynk.email('wr300000@gmail.com','Blynk data','this is testing Blynk data')
    #blynk.notify('this is Ex00')

while True:
    blynk.run() 

Isn’t the vpin in this command a “keyword” that needs to be used in every virtual pin handler?

Pete.

Hi Pete,
Thank you for prompt response, as I told before that i’m newbie for Blynk, def read_hadler(vpin): are totally from example that I referred in prior message and it was working well until I add one more digital to be read for LED widget. It’s making me confuse once I think in term of python, vpin must be parameter to be used under this function. I guess that you are telling that one V1 can handle more than one parameter that need to be used passing values of commands. If my guessing is right, I add vdoor parameter more under same read_handler(vpin,vdoor): as below code but it didn’t work anymore. What did I do something wrong ? Which virtual Pin should I bind in LED widget , V1, V2 or else? Could you please guide more?

‘’’

@blynk.handle_event(‘read V1’)
def read_handler(vpin,vdoor):
p_value = adc.read() # read from AO 8266 pin
print(’ {} = {} '.format(now(),p_value))
blynk.set_property(vpin, ‘color’, ‘#00FF00’) # set red color for the widget UI element as #RRGGBB mixing between 00-FF in each colour
blynk.virtual_write(vpin, p_value) # write to Application

door_value = door.value() # read from GPIO4 pin
print(' {} = {}  '.format(now(), door_value))
blynk.set_property(vdoor, 'color', '#FFFF00') # set red color for the widget UI element as #RRGGBB mixing between 00-FF in each colour
blynk.virtual_write(vdoor, door_value) # write to Application

‘’’

You need to use the correct triple backtick characters when posting code to the forum. The characters you used this time weren’t the correct ones.

I know nothing about micropython, so am just guessing - based on my take on the syntax.

I certainly wasn’t suggesting the approach you’ve gone for.

Pete.

Hi Pete,
I could see examples of ESP32 as reference and now it’s working well. Anyway, thank you so much.

1 Like