I'm a new python/Blender user I'm trying to move an object using an Arduino. I've watched many videos and tutorials, and somehow i could write a code using others codes. here is my code
import bge import math import serial controller = bge.logic.getCurrentController() own = controller.owner serialport = serial.Serial('COM4', 9600) sens = controller.sensors['run'] val1=0.0 val2=0.0 val3=0.0 p = pi/255 def run(): if sens.positive: serialport.write('s'.encode('ascii')) #blender sends the ascii code of "s" to the Arduino n = serialport.readline() #receive data from the arduino val1 = (float) (n) val2 = (val1-val3)* p val3 = val1 print ('The value is: ') print (val2) own.applyRotation((0 , val2 , 0),0) # own.position.y = val2
my problem is with the
sens = controller.sensors['run'] when i run the game engine the following message appears:
Python module can't be imported - object 'Cube', controller 'Python': KeyError: 'requested item "run" does not exist'
as usual i looked for a solution by checking questions of people have the same problem here and elsewhere. so i followed some of the best answers. such as, setting the actor flag in physics tab, some people suggested that reinstalling blender would help. nothing worked for me. thanks anyway