Skip to content

Interface and application programming

Thinking about Machines that make assignment implementation project I’ve introduced myself to some python scripting in blender results of which could also be seen in input devices week.

Communicating Arduino with Blender

The initial setup with links to the source was made during week 9 as prototype for yaw-pitch platform using Arduino with potentiometer then connecting it to Blender with Python.

3DS Max is the editor I have the most experience working in, but for this project it’s missing one function that is maximizing view-port to achieve 1 : 1 camera-view projection. Without full-screen it would be not possible to project virtual surfaces correctly, so I chose Blender which allows maximizing the view-port into full-screen leaving no borders or bars.

▼ Entering the full-screen mode

▼ Using Ctrl Alt Space to maximize the view-port

▼ Blender Python script

import time 
import bpy 
import serial 


ser = serial.Serial('COM7','115200')
time.sleep(3)
ser.write(b'dist\n')
angle = float(ser.readline())

camera = bpy.context.selected_objects[0]

for x in range(10000):


    ser.write(b'dist\n')
    current = float (ser.readline())
    rad = current * 0.0090016981518625
    print(rad)
    camera.rotation_euler.z = rad

    bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)

ser.close()

This script is sending the dist string to previously opened serial port and then reading serial output and mapping it to radians. In the final step its assigning radians value to camera rotation property. Also, to redraw the view-port I’m using hack from Blender-wiki which is that line: bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1).


Communicating designed board with Blender

pic

▣ Board files

traces.svg

outline.png

Since the week 12 I’ve switched my final project to the idea that was born after playing a while with tof sensors . Physical interface of such devices could be shrunk to 1 button. For the first development spirals the function could be fixed and tuned in code but for fine adjustment and good user experience such device should be tuned through some interface.

Interfacing with blender would not be suitable for tuning the feedback but it could be beneficial in terms of simulation or visualisation. To understand the geometry I’ve tried to represent the use setting in virtual space and then connect the physical device to virtual scene.

blender-script.py

Trying to visualize 3 sensors simultaneously didn’t succeeded to 100%. Although all the sensors are active and values are received by Blender the order is shifted. Blender should write char and then read value that Arduino prints in response. Troubleshooting had no results leaving me with not so useful (but at least working) setup. I hope in the further developments I will resolve this issue.

▣ Arduino sketch and Python script for blender

serial-char-response-tof-array.ino

Interfacing Genuino 101 with blender

I have spotted some strange Arduino in Lab. Turns out, it’s Genuino 101 with gyroscope and accelerometer on board. It has Intel’s “Curie” module on board which provides additional capabilities to Arduino. This board is retired, but it’s working, so why not to use it.

▼ The Genuino 101 with Intel’s Curie module

▼ Applying accelerometer data to Blender‘s object rotation angles

▼ Screen recording from above


Last update: June 19, 2021