串行通信搅拌机游戏引擎的Arduino? [英] serial communication Blender Game Engine to arduino?

查看:444
本文介绍了串行通信搅拌机游戏引擎的Arduino?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助从搅拌机游戏引擎的的Arduino 的通信的串行数据。

I need help from communicating serial data from blender game engine to arduino.

我是从搅拌机使键盘输入,并试图沟通的的Arduino 的,但它不工作。

I'm making keyboard input from blender and trying to communicate to arduino, but it's not working.

这是搅拌机code

import serial

ser = serial.Serial("COM6", 9600)
x=ser.write(1)   
print(x)
ser.close()

逻辑

键一 - > Python脚本

Key "a" --> Python script

这是Arduino的code我试图从搅拌机沟通。

int led = 2;

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

void loop() {
    if ( Serial.available())
    {
        char ch = Serial.read();
        if(ch >= '0' && ch <= '9')
        {
        digitalWrite(led, HIGH);
        }
    }
}

其实,当的 Blender的游戏引擎的(BGE)上运行,而我preSS主要'一'搅拌器与Arduino的沟通和LED亮起。

Actually, when Blender Game Engine (BGE) running, and I press Key 'a' blender communicate with arduino and LED turn on.

难道我做错了吗?

任何人可以帮助我解决这个?

Can anybody help me to solve this?

推荐答案

在您的搅拌机蟒蛇code,你发送一个整数:

in your blender python code, you're sending an integer:

x=ser.write(1)   

而在你的Arduino code你检查之间的ASCII数字'0''9',48和57之间的数字,即

whereas in your arduino code you're checking for an ASCII digit between '0' and '9', i.e. numbers between 48 and 57

if(ch >= '0' && ch <= '9')

要么试图改变你的Python code到 ser.write('1')或更改您的Arduino code到沟道&GT; = 0&放大器;&放大器; CH&LT; = 9 ,它应该工作

either try to change your python code to ser.write('1') or change your arduino code to ch >= 0 && ch <= 9, and it should work.

此外,结合您的code作为搅拌机里面的脚本之前,你应该先搅拌机外测试Python脚本。简单地通过使用命令行运行:蟒蛇script.py ,在目录中的脚本

Also, before binding your code as a script inside blender, you should first test your python script outside of blender. simply by running using the commandline: python script.py, in the directory where the script is.

这篇关于串行通信搅拌机游戏引擎的Arduino?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆