Blender and PyBoard

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
adamboho
Posts: 15
Joined: Fri Oct 10, 2014 4:27 pm

Blender and PyBoard

Post by adamboho » Fri Oct 10, 2014 4:35 pm

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.

riklaunim
Posts: 32
Joined: Fri Aug 22, 2014 5:42 pm

Re: Blender and PyBoard

Post by riklaunim » Fri Oct 10, 2014 11:22 pm

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 :twisted:

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: Blender and PyBoard

Post by Turbinenreiter » Sat Oct 11, 2014 9:46 am

If you want to use the pyboard as inputdevice for blender, you could use HID to generate mouse input.

adamboho
Posts: 15
Joined: Fri Oct 10, 2014 4:27 pm

Re: Blender and PyBoard

Post by adamboho » Mon Oct 13, 2014 9:50 pm

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?

riklaunim
Posts: 32
Joined: Fri Aug 22, 2014 5:42 pm

Re: Blender and PyBoard

Post by riklaunim » Mon Oct 13, 2014 11:09 pm

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.

adamboho
Posts: 15
Joined: Fri Oct 10, 2014 4:27 pm

Re: Blender and PyBoard

Post by adamboho » Wed Oct 15, 2014 9:08 pm

Ok, I've managed to do it.

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
In Blender:

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

Post Reply