Go Down

Topic: blender 3d (Read 8355 times) previous topic - next topic


Apr 28, 2007, 09:46 pm Last Edit: Apr 28, 2007, 09:46 pm by videokuenstler Reason: 1
did anyone found a way to connect blender with arduino-boards?


May 13, 2007, 06:47 pm Last Edit: May 13, 2007, 06:48 pm by thorolf Reason: 1

it should be easy, since blender is written in python and you can easily control the arduino with python.

here is a simple example to control it with python (very simple one)

arduino code

int ledPin13 = 13;   // select the pin for the LED
int ledPin12 = 12;   // select the pin for the LED
int ledPin11 = 11;   // select the pin for the LED
int ledPin10 = 10;   // select the pin for the LED
int ledPin9 = 9;   // select the pin for the LED
int ledPin8 = 8;   // select the pin for the LED
// int inPin = 7;

void setup()
 pinMode(ledPin13,OUTPUT);   // declare the LED's pin as output
 pinMode(ledPin8,OUTPUT);   // declare the LED's pin as output
 pinMode(ledPin9,OUTPUT);   // declare the LED's pin as output

 Serial.begin(9600);        // connect to the serial port
 Serial.println("Arduino is ready");
} //setup

void loop ()
 int serbyte = 0;

 serbyte = Serial.read();
 // if the input is '-1' then there is no data
 if (serbyte != -1)
   if (serbyte == 'H')
     digitalWrite(ledPin13, HIGH);
   if (serbyte == 'L' )
   digitalWrite(ledPin13, LOW);
   if (serbyte == '1')
     digitalWrite(ledPin9, HIGH);
   if (serbyte == '0' )
   digitalWrite(ledPin9, LOW);
   if (serbyte == 'h')
     digitalWrite(ledPin8, HIGH);
   if (serbyte == 'l')
     digitalWrite(ledPin8, LOW);

 } // if

} //loop

python code
#!/usr/bin/env python
import serial

ser = serial.Serial('/dev/tty.usbserial-A5001amK', 9600)


what do you want to do with blender?



hello thorolf,

thank's for your advice - i want to interface the game-engine from blender with some hardware sensors and actuators to build some experimental media installations.

blender's realtime engine has a node based system for defining behaviors and interaction - and indeed it has it's own python-api which can be accessed through the 'python-controller'. i will give it a try and post the results...

# lars


only slightly related but this guy connected Arduino to second life. AFAIK you can integrate blender with second life also

Arduino in second life

Video describing this and some other ideas


May 21, 2007, 02:55 am Last Edit: May 21, 2007, 03:05 am by videokuenstler Reason: 1
so far, i made a simple blender-setup where the 'Cube' with an 'Always'-sensor triggers the python-controller.
every cycle of the game-engine calls the script once.

on the arduino-side i used some 'Potentiometer to Processing' code-example which sends a raw binary that can be read in python and with the 'print x, type (x)' commands i can see the binary as an ascii type (that changes by moving the potentiometer) and as type i got 'str' in the console: * <type 'str'>

at this point the 'str' datatype needs to be converted into a 'float' for controlling parameters in blender, which i couldn't solve with my very basic python knowledge tonight.

any help with python would be appreciated here...
(the next question would be, how to send different values at the same time for more than one parameter?)

# lars

Code: [Select]
/* Potentiometer to Processing
* ---------------------------
* This program sends data from a potentiometer to Processing
* over the serial port (works in PC: Windows and Linux, and MAC)
* The code reads a potentiometer plugged to an analog
* input and sends the data as a byte back to the computer.
* In order to make the data transfer as simple as possible
* we will only send a byte back to the computer, what means
* that the data coming from the ADC will be divided by 4.
* (cleft) 2005 DojoDave for K3
* @author: David Cuartielles
* @context: ID3 - K3 - MAH - Sweden

int ledPin = 12;      // pin for the LED
int potPin = 4;       // analog pin for the potentiometer
int ledStatus = LOW;  // we use a variable to toggle the LEDs state
int val = 0;          // variable to store the potentiometer's reading

void setup() {
 pinMode(ledPin, OUTPUT);  // declare the ledPin as an output
 Serial.begin(9600);        // initialize the serial port

void loop() {
 // read the potentiometer's value and store it
 val = analogRead(potPin)/4;

 // send the value over the port
 Serial.print(val, BYTE);     // Print the raw binary value analogValue
 // Serial.print('\t');          // print a tab
 // Serial.print(val, BIN);      // print the ASCII encoded binary analogValue
 // Serial.print('\t');          // print a tab
 // Serial.print(val, DEC);      // print the ASCII encoded decimal analogValue
 // Serial.print('\t');          // print a tab
 // Serial.print(val, HEX);      // print the ASCII encoded hexadecimal analogValue
 // Serial.println();            // print a linefeed and carriage return

 // wait a bit

 // change the state of the LED (if HIGH, then LOW, and viceversa)
 ledStatus = !ledStatus;
 digitalWrite(ledPin, ledStatus);


May 21, 2007, 10:36 am Last Edit: May 21, 2007, 10:38 am by thorolf Reason: 1
hi lars

that's cool.

To Your problem. The serial connection is only the "network Layer", so you have to implement a protocol on top of this connection.
I'm myself searching for a solution for this. I'll keep You updated if I find something interesting.

For now, and in case You don't know this link



next try with the same setup and the use of existing protocol libraries: (pyduino) and the firmata hardware.
unfortunately, the input has irregular values (0) between the correct values.

the problem seems to be here, that the python code in blender has to open and close the port for every game-cycle and causes irregular wrong (zero)-values...

example from the shell output (print):

any help appreciated!
# lars



python code in blender / analog input at pin 0
Code: [Select]
import pyduino

port = "/dev/ttyUSB0"
pin = 0

arduino = pyduino.Arduino(port)
dings = arduino.analog[pin].read()
print dings


Jun 07, 2007, 08:07 pm Last Edit: Jun 07, 2007, 09:09 pm by videokuenstler Reason: 1
this script works as a 'proof of concept'
[with a little hack from my programming friend brendan howell]

you will find a little 'step by step' tutorial and the blend file with this example here.

further development is necessary - the best solution would be a logic-brick sensor, that's written inside blender's source code.

therefore we would like to ask the blender community for support...

Code: [Select]
import pyduino
import GameLogic

#same port than arduino
port = "/dev/ttyUSB0"
pin = 0

       init = 0
       init = 1

if init:
       GameLogic.Object = {}
       arduino = pyduino.Arduino(port)
       GameLogic.Object['arduino'] = arduino
       GameLogic.Object['last_val'] = 0

arduino = GameLogic.Object['arduino']
dings = arduino.analog[pin].read()
if dings != GameLogic.Object['last_val']:
       GameLogic.Object['last_val'] = dings
       changed = True
       dings = 17 - float(dings)/30
       print dings
       changed = False

Gareth Hewes

Not entirely the same as the previous posts, what I want to do is connect Arduino to Blender as well, but all I really need to do is send a string with the value of a couple of potentiometers via a serial connection.  Those values need to be changed to coordinates in the program and, in turn, made into points.

I don't know how to go about this.  My programming skills are lacking (at best), but the math (conversion) isn't a problem for me, so if anyone knows of anywhere that I can find out about the commands I need to do this, that would be much appreciated.


I started a project to record stick movements on radio-controllers for education and teachning purposes. However I dropped it because of limitations to get the signals from the RC during a real flight.

Why I am telling this? I used a serial connection to controll a virtual RC controller in Blenders gameengine.

Here is the page, it is german, but you can grab the code and the .blend and have a look.



PS: Yes I do everything in Blender, look at http://blenderbuch.de to see why ;-)


Hi again,

I did play a bit with Blender, Python and Firmata.


Change the COM-Port (Windows, Linux/Mac use the correct device) and start it by pressing "P" over the 3D Window. End with ESC.

This version is nice and closes the serial port, cleans up firmata etc.

However, it seems that pyduino.py is not 100% working with the V2 Firmata. From the analog ports I only get one value at program start. Stangly the values have some noise but not showing the input at the board.

The digital output works (press SPACE in the .blend which will switch on Port 13).

On the Arduino side I did try a simple own sketch or StandardFirmata.pde from the Firmata examples, but with the same mixed results.

The example from the pyduino page works with my simple sketch but not with StandardFirmata.pde.

Thats all from me, maybe someone can pick up some news here.


Nikolaus Gradwohl

you could use the arduino to send osc events (via the ethernet shield, processing, pd, ...) and react in the bge to the osc events.

i wrote a post on my blog a while ago how this can be done


Hello there,

I've been trying to get this example of videokuenstler to work, but for some reason it just doesn't want to. I have everything installed as it should be, the problem is that I don't get any analog input into python. Digital is no problem. There is no problem with the arduino, when I stay in the arduino ide I can process analog input without any problems. Does anyone have an idea what I might be missing? I've searched the net up down and found nothing that works.




Hi wimmm,

see my post above, I had the same results. I guess it is a incompatibility between pyduino and firmata.



hey Carsten,

thanks for your repply. I'll be trying it out today. It's been a while since I used pd though, so I hope I dot right. In your experience, do you get any delays if you have to go over osc? This is the reason I wanted to try to go directly over python.
Do you have experience going directly from serial.py instead of using pyduino?
I'll let know how it goes.



Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131