Interacción con Arduino y Blender

¡Saludos!

Estoy con un proyecto personal y necesito que mi placa Arduino interaccione por serial con Blender. He encontrado algunos ejemplos por Internet, pero no me funcionan.
No sé si alguien de por aquí tiene por mano Blender y Python además de Arduino y puede decirme qué está mal.

Utilizo Linux (concretamente Ubuntu) y la versión de Blender 2.62 .

El código para mi Arduino Duemilanove es este:

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

y el código en python para Blender:

#!/usr/bin/env python
import serial

ser = serial.Serial('/dev/ttyUSB0', 9600)

ser.write('H')

También he instalado la librería serial de python en la carpeta bin/blender-2.62/2.62/python/lib/python3.2 , que es dónde tengo el resto de librerías python.

El código de Arduino no me da ningún problema. Ahora bien, cuándo le doy al Run Script de Blender, me dice que hay errores en el fichero init.py de la librería serial.

¿Alguien sabe cuál puede ser el problema?

Gracias de antemano :slight_smile:

Hola!
Para el código de python te diría que uses unos sleep por las dudas. Al estilo:

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

ser = serial.Serial('/dev/ttyUSB0', 9600)
time.sleep(2) 
ser.write('H')
time.sleep(1) 
ser.close()

Testea algo más simple:

#define LEDPIN 13

void setup() {
    pinMode(LEDPIN, OUTPUT);
    Serial.begin(9600);
}

void loop() {
    if (Serial.available()) {
        char serbyte = Serial.read();
        if (serbyte== 'H') {
            digitalWrite(LEDPIN, HIGH);
        }
        else if (serbyte == 'L') {
            digitalWrite(LEDPIN, LOW);
        }
    }
}

¡Buenas!

Perdón por contestar tarde, pero últimamente he estado ausente y no he tenido ocasión de conectarme.

En primer lugar muchas gracias por contestarme, pero sigo teniendo problemas. :~ He probado con los dos códigos que me has dado, y el código en python sigue fallando (me dice "Python script fail, look in the console for now...").

Es cómo si no encontrara la librería "serial", aunque según las instrucciones la he instalado en la carpeta correcta (.../bin/blender-2.63/2.63/python/lib/python3.2).

¿Alguien sabe qué puede estar fallando?

Muchas gracias de nuevo.

Has probado que python funciona?

Yo instalaria Python independientemente de Blender y luego PySerial en el folder de python.