Hi all, i have very simple question, is it possible to send data between Blender and PyBoard without any sleep() or delay(), if so can some one post some code?
It will be very helpful.
Thanks in advance.
Blender and PyBoard
Re: Blender and PyBoard
You will need an event loop on the host PC looking for events from Blender (or checking it in a loop) and sending some signals via UART to pyBoard where similar looping script is running and responds to data sent via UART - like if someone sent "led1" then toggle LED on pin X and if it's "pomidor" then turn it red
-
- Posts: 288
- Joined: Sun May 04, 2014 8:54 am
Re: Blender and PyBoard
If you want to use the pyboard as inputdevice for blender, you could use HID to generate mouse input.
Re: Blender and PyBoard
Thank you for reply. What I really need is controlling stepper motors, let say if I move something in blender then the motors should move, sending data in real time or some commands, the best thing will be REPL between blender and pyboar. Is that possible?
Re: Blender and PyBoard
Stepper motor needs more than one command to move, so the best way would be to script it on pyboard and just provide serial high level api for it, so that from the Blender side it would be easy to use.
Re: Blender and PyBoard
Ok, I've managed to do it.
On PyBoard:
In Blender:
On PyBoard:
Code: Select all
# main.py -- put your code here!
import pyb
from pyb import USB_VCP
VCP_object = USB_VCP()#Create a new USB_VCP object
while True:
data = VCP_object.recv(10, timeout=0)# Receiving data (how many bytes?, how long wait for it?)
if data:# If data received
data = data.decode("UTF-8")# Decoding
if data == "on":
pyb.Pin('X1', pyb.Pin.OUT_PP).high()# Pin X1 on
if data == "off":
pyb.Pin('X1', pyb.Pin.OUT_PP).low()# Pin X1 off
Code: Select all
import bpy
import serial
pyboard = serial.Serial('COM4', 9600, timeout=0) # connect to pyboard
pyboard.write(b'on') # sending data to pyboard
pyboard.close()# closed connection to pyboard