Cleric-K / vJoySerialFeeder

Feed Virtual Joystick driver with data from a serial port
GNU General Public License v3.0
252 stars 55 forks source link

Raspberry Pi Pico IBUS - Failsafe (Serial Port Read Timeout) #74

Closed xenocide702 closed 10 months ago

xenocide702 commented 10 months ago

Hey guys, I'm attempting to roll my own controller built around a rpi pico board using micropython and communicating using the 2040's virtual COM port and IBUS. The arduino example code was very helpful and straightforward, but I must be missing something because I can't get it to connect to vJoySerialFeeder.

Looking at the output with realterm, it looks okay per the specs (I think?): image

(most of) the python code:

class ibus:
    checksum=0xFFFF
    numChannels = 1
    len = 2 + (numChannels*2) +2  #length byte, start byte (0x40), data (16 bits per channel), checksumLow, checksumHigh

    def __init__(self):
        self.len = 4 + (self.numChannels*2)    

    def begin(self):
        buf = bytes([self.len, 0x40])
        self.checksum = 0xFFFF - buf[0] - buf[1] #checksum includes length byte and start byte
        sys.stdout.write(bytes(buf))

    def write(self, val):
        buf = bytes([val&0xFF, (val>>8) & 0xFF])
        self.checksum-=buf[0]
        self.checksum-=buf[1]
        sys.stdout.write(bytes(buf))

    def end(self):
        sys.stdout.write(pack("<H",self.checksum))

ib = ibus()

while True:    
    ib.begin()
    ib.write(1000) #output 1 channel, value = 1000 (0x03E8)
    ib.end()

    sleep(.05)

I think I've got vJoySerialFeeder set up properly: image image image image

I've tried messing around with the Update Rate and Activate After settings (and most other settings too).

I'm sure I'm missing something simple, I'd appreciate any insight you guys may have, thanks!

Cleric-K commented 10 months ago

I'm not sure what's going on. A don't have a Pi Pico but tried Micropython with an ESP 8266 (Wemos D1 mini). I used your code without any modifications (only the imports were needed). It works normally:

image

The bytes are exactly as yours:

image

At this point I'm out of ideas. The Update Rate and Activate After only set up the behavior of Failsafe when there's no serial signal. Maybe we'll need some way to debug if vjsf sees anything at all at the COM port although I don't see why it wouldn't.

xenocide702 commented 10 months ago

vjsf doesn't implement any software flow control, does it?

Good to know the framing/checksum right at least, thanks for confirming that!

Cleric-K commented 10 months ago

No, there's no flow control.

xenocide702 commented 10 months ago

I apologize to anyone who stumbles across this with the same problem. I gave up and changed over to using an ESP32 and C++.

Thanks for Cleric-K for the support and the great software!

Cleric-K commented 10 months ago

Sorry that it didn't work out for you. As said, your python code is just fine, it works perfectly on ESP8266. It would have been interesting to find out what the nature of the problem was but I'm at least glad that it works now on the ESP32.

xenocide702 commented 10 months ago

If anyone else comes across this and has an idea I'm happy to try something. I sort of ran out of ideas and ran out of time to try different things, but I am still curious what's going on.