So, my setup is as following:
ESP32 with joystick running micropython + blynk
Raspberry pi running python + blynk
What I want to do:
Use the joystick to control the pan&tilt movement of the camera
What I have managed to do:
With as slider connected to a virtual pin, i can use the app on my android phone to control the pan&tilt movement of the camera. This is pretty simple and straightforward, when I move the slider the value gets passed to the raspberry pi and it updates the pan/tilt
What I can’t seem to do:
I want the joystick to update the pan&tilt of the raspberry pi. I can use the same virtual pin (use the same token even though I’m using two devices, I don’t think bridge exists for python). When I move the joystick, the value on the slider updates, but this new value is not passed on to the raspberry pi.
Is there a command to automatically update the value from the joystick to the raspberry pi? Otherwise I think I could make the raspberry pi do a virtual sync, but I am afraid to flood the server?
import BlynkLib
import time
import pantilthat
BLYNK_AUTH = 'ABC'
blynk = BlynkLib.Blynk(BLYNK_AUTH)
@blynk.VIRTUAL_WRITE(20)
def v20_write_handler(value):
#print(value)
value = str(value)
value = value.replace("[u'","")
value = value.replace("']","")
value = int(value)
pantilthat.pan(value)
print(value)
while True:
blynk.run()
time.sleep(0.1)
blynk.sync_virtual(20)
The joystick:
from m5stack import *
from m5ui import *
import units
import BlynkLib
clear_bg(0x000000)
joystick0 = units.Joystick(units.PORTA)
BLYNK_AUTH = 'ABC'
blynk = BlynkLib.Blynk(BLYNK_AUTH)
circle0 = M5Circle(160, 120, 15, 0xFFFFFF, 0xFFFFFF)
from numbers import Number
X = None
Y = None
i = None
X = 0
Y = 0
while True:
blynk.run()
blynk.virtual_write(20,X)
circle0.setPosition(x=X)
circle0.setPosition(y=Y)
if (joystick0.X) > 160:
if X > -90:
X = (X if isinstance(X, Number) else 0) + -5
if (joystick0.X) < 80:
if X < 90:
X = (X if isinstance(X, Number) else 0) + 5
wait(0.1)
(I have to replace the sleeps with a function that gets called every X seconds