Compatibility with pygame
I want to read joystick inputs from my ps4 controller using pygame. When I run this script, I don't receive any messages. Running the example transmission script works just fine.
#!/usr/bin/python3
import sys, pygame, os
import time
import piVirtualWire.piVirtualWire as piVirtualWire
import pigpio
pygame.init()
size = [500, 700]
screen = pygame.display.set_mode(size)
start_time = time.time()
# os.system('sudo /home/pi/PIGPIO/pigpiod')
pi = pigpio.pi()
tx = piVirtualWire.tx(pi, 4, 1000)
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
tx.cancel()
pi.stop()
pygame.quit()
sys.exit()
if time.time() - start_time > 0.5:
start_time = time.time()
tx.put("12")
print("Sending")
tx.waitForReady()
pygame.display.flip()
There are no erros. I also ran pigpio before. While loop works fine. The console show "Sending" every 0.5 seconds. Any help?
My apologies if I'm mistaken, but if you are trying to read input from the controller should you not be RXing instead of TXing?
Sorry, I think I was not very precise with what I am trying to achieve. I read inputs from the controller and try to send messages to my arduino, when input happens. The joystick axis return numbers between -1 and 1. In my real script, I map these values to a two digit number between 00 and 99 and send the code to my arduino, so I know how much the axis is used. But when I simply try to transmit a message in the while loop above, it does not work. So the code above does not differ from the example code. But it does not work at all. The example code works My problem is exactly that I cannot use pygame and piVirtualWire in one script together. Can you help me out?