did anyone found a way to connect blender with arduino-boards?
hi
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 outputSerial.begin(9600); // connect to the serial port
Serial.println("Arduino is ready");
} //setupvoid 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 serialser = serial.Serial('/dev/tty.usbserial-A5001amK', 9600)
ser.write('H')
what do you want to do with blender?
/me
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...
cheers
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
http://www.joshuakauffman.org/2007/02/23/building-bacteria-in-second-life/
Video describing this and some other ideas
http://www.hackdiary.com/archives/000105.html
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

/* 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
delay(50);
// change the state of the LED (if HIGH, then LOW, and viceversa)
ledStatus = !ledStatus;
digitalWrite(ledPin, ledStatus);
}
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
mfg
thorolf
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):
694
0
0
0
886
0
0
1019
0
0
0
1023
any help appreciated!
lars
pyduino
http://orphans.atspace.com/pyduino-0.1.tar.gz
firmata
http://at.or.at/hans/pd/Pduino-0.3.zip
python code in blender / analog input at pin 0
import pyduino
port = "/dev/ttyUSB0"
pin = 0
#connect
arduino = pyduino.Arduino(port)
arduino.analog[pin].set_active(1)
arduino.iterate()
dings = arduino.analog[pin].read()
print dings
arduino.exit()
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...
import pyduino
import GameLogic
#same port than arduino
port = "/dev/ttyUSB0"
pin = 0
try:
GameLogic.Object
init = 0
except:
init = 1
#connect
if init:
GameLogic.Object = {}
arduino = pyduino.Arduino(port)
GameLogic.Object['arduino'] = arduino
arduino.analog[pin].set_active(1)
GameLogic.Object['last_val'] = 0
arduino = GameLogic.Object['arduino']
arduino.iterate()
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
else:
changed = False
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.
http://wiki.rc-heli-fan.org/index.php/Sticki
Carsten
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.
http://blenderbuch.de/arduino/TestAnalog.blend
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.
Carsten
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.
grtz
wimmm
Hi wimmm,
see my post above, I had the same results. I guess it is a incompatibility between pyduino and firmata.
Carsten
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.
grtz,
wim
I wrote something similar that uses osc. I tired to document it carefully.
But I didn't make the movie for it as I should have.
http://code.google.com/p/chrisworld-projects/wiki/ArduinoMeetsBlender
"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."
I've been contemplating writing a patch to add libserial into the blender 2.5's event loop those providing blender with another event type in which to use all over.
What I really need is for blenders rigs to be updated in real time.
but I couldn't access that data in the previous versions of the program.
i did everythin that was in this page
http://www.3d-disco.com/arduino_blender.htm
but doesn't work for me..
i have arduino 18 whit firmata and blender 2.49 ,,
does anyone know how to do it?