Hallo liebe Community,
habe ein Problem mit meinem Raspi + Arduino Uno, die über USB Serial kommunizieren.
Wenn ich das ganz mit Sudo python joy.py ausführe und den linken Joystick des PS3 Controller bewege dann blinkt(leuchtet)die RX LED am Arduino.
Aber der Arduino schaltet nicht meine Lampe(Später soll es mal ein Motor werden).
Allerdings wenn ich den Arduino Sketch über die IDE Serial Monitor, teste funktioniert alles.
Könnt ihr mir helfen?
#!/usr/bin/env python
import os, sys, pygame
from pygame import locals
import time
import RPi.GPIO as GPIO
import serial
ser = serial.Serial(
port='/dev/ttyACM0',\
baudrate = 115200,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS,\
timeout=2,)
os.environ["SDL_VIDEODRIVER"] = "dummy"
pygame.init()
pygame.joystick.init() # main joystick device system
try:
j = pygame.joystick.Joystick(0) # create a joystick instance
j.init() # init instance
print 'Enabled joystick: ' + j.get_name()
except pygame.error:
print 'no joystick found.'
while 1:
for e in pygame.event.get(): # iterate over event stack
if e.type == pygame.locals.JOYAXISMOTION: # Read Analog Joystick Axis
x1 , y1 = j.get_axis(0), j.get_axis(1) # Left Stick
y2 , x2 = j.get_axis(2), j.get_axis(3) # Right Stick
print x1
print y1
print x2
print y2
if y1 < 0.01 :
print ' nullstellung'
ser.write("500")
if y1 > 0.10 and y1 < 0.20:
print 'Left Joystick 1 backwards 10'
ser.write("550")
if y1 > 0.21 and y1 < 0.3 :
print 'Left Joystick 1 backwards 20'
ser.write("600")
)
if y1 > 0.31 and y1 < 0.40 :
print 'Left Joystick 1 backwards 30'
ser.write("650")
if y1 > 0.41 and y1 < 0.50 :
print 'Left Joystick 1 backwards 40'
ser.write("700")
if y1 > 0.51 and y1 < 0.60 :
print 'Left Joystick 1 backwards 50'
ser.write("750")
if y1 > 0.61 and y1 < 0.70 :
print 'Left Joystick 1 backwards 60'
ser.write("800")
if y1 > 0.71 and y1 < 0.80 :
print 'Left Joystick 1 backwards 70'
ser.write("850".encode())
if y1 > 0.81 and y1 < 0.90 :
print 'Left Joystick 1 backwards 80'
ser.write("900")
ser.flush
if y1 > 0.91 and y1 < 0.99999999999999999999999 :
print 'Left Joystick 1 backwards 100'
ser.write("950")
time.sleep(stepDelay)