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

not reading serial data #64

Closed justinspam304 closed 1 year ago

justinspam304 commented 1 year ago

Hello Cleric! Nice work on the project I am sure many are enjoying this project! Keep up the good work! Unfortunately I am unable to read the serial data (in my case from com3) to vjoyserialfeeder. I opened the serial monitor in Arduino IDE and got byte data. When I open com3 in vjoyserialfeeder as shown I get "no data."

Capture

I run the code stock, but I thought the added println statements may help in diagnostics on this serial monitor.

mini

system details: windows 10 laptop Radio: exceed RC 2 channel transmitter (5K ohm potentiometer guts) arduino mini running your ibus code and connected to 2 potentiometers on a0 and a1 as per the proviced wiring diagram. The pots are not connected to the old radio board. Also: I changed the An alog Refrence to default.

Thank you again and have a great day!

Cleric-K commented 1 year ago

Hi, can you look at at this https://github.com/Cleric-K/vJoySerialFeeder/issues/24#issuecomment-504308045 and try to dump some data of the serial communication in hexadecimal format? We should make sure the receiver is sending actual IBUS packets.

justinspam304 commented 1 year ago

Thank you for the help and quick response!

I realiazed why I saw the value zero for the global variable of analog pins...I didn't add A0 and A1 to the array of analog pins. That still did not resolve the issue. Here is the hex output and screenshot of hterm.

At least we know it is trying to use IBUS since that is arduino sketch I uploaded and the arduino is only interfacing with the potentiomenters. hex output.txt

htmer hex
Cleric-K commented 1 year ago

I think there's something wrong in the Arduino code. Can you paste me your whole contents of Joystick.ino?

justinspam304 commented 1 year ago

Thanks again for helping me. Here is the code.

include "ibus.h"

// ////////////////// // Edit here to customize

// How often to send data?

define UPDATE_INTERVAL 10 // milliseconds

// 1. Analog channels. Data can be read with the Arduino's 10-bit ADC. // This gives values from 0 to 1023. // Specify below the analog pin numbers (as for analogRead()) you would like to use. // Every analog input is sent as a single channel. The ADC 0-1023 range is mapped to the 1000-2000 range to make it more compatible with RC standards.

// example: // byte analogPins[] = {A0, A1, A2, A3}; // This will send four analog channels for A0, A1, A2, A3 respectively

byte analogPins[] = {A0, A1};

// 2. Digital channels. Data can be read from Arduino's digital pins. // They could be either LOW or HIGH. The pins are set to use the internal pull-ups so your hardware buttons/switches should short them to GND. // Specify below the digital pin numbers (as for digitalRead()) you would like to use. // Every pin is sent as a single channel. LOW is the active state (when you short the pin to GND) and is sent as channel value 2000. // HIGH is the pulled-up state when the button is open. It is sent as channel velue 1000.

// example: // byte digitalPins[] = {2, 3}; // This will send two channels for pins D2 and D3 respectively

byte digitalPins[] = {};

// 3. Digital bit-mapped channels. Sending a single binary state as a 16-bit // channel is pretty wasteful. Instead, we can encode one digital input // in each of the 16 channel bits. // Make sure you activete "use 16-bit channels" in the Setup dialog of the IBUS protocol in vJoySerialFeeder // Specify below the digital pins (as for digitalRead()) you would like to send as // bitmapped channel data. Data will be automatically organized in channels. // The first 16 pins will go in one channel (the first pin goes into the LSB of the channel). // The next 16 pins go in another channel and so on // LOW pins are encoded as 1 bit, HIGH - as 0.

// example: // byte digitalBitmappedPins[] = {4, 5, 6, 7, 8, 9}; // This will pack D4, D5, D6, D7, D8, D9 into one channel

byte digitalBitmappedPins[] = {};

// Define the appropriate analog reference source. See // https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/ // Based on your device voltage, you may need to modify this definition

define ANALOG_REFERENCE DEFAULT

// Define the baud rate

define BAUD_RATE 115200

// /////////////////

define ANALOG_INPUTS_COUNT sizeof(analogPins)

define DIGITAL_INPUTS_COUNT sizeof(digitalPins)

define DIGITAL_BITMAPPED_INPUTS_COUNT sizeof(digitalBitmappedPins)

define NUM_CHANNELS ( (ANALOG_INPUTS_COUNT) + (DIGITAL_INPUTS_COUNT) + (15 + (DIGITAL_BITMAPPED_INPUTS_COUNT))/16 )

IBus ibus(NUM_CHANNELS);

void setup() { for(int i=0; i < DIGITAL_INPUTS_COUNT; i++) { pinMode(digitalPins[i], INPUT_PULLUP); }

for(int i=0; i < DIGITAL_BITMAPPED_INPUTS_COUNT; i++) { pinMode(digitalBitmappedPins[i], INPUT_PULLUP); }

analogReference(ANALOG_REFERENCE); // use the defined ADC reference voltage source Serial.begin(BAUD_RATE); // setup serial Serial.println("data"); //Serial.println( NUM_CHANNELS); Serial.println( ANALOG_INPUTS_COUNT); //Serial.println( DIGITAL_INPUTS_COUNT); //Serial.println( DIGITAL_INPUTS_COUNT); //Serial.println( DIGITAL_BITMAPPED_INPUTS_COUNT); }

void loop() { int i, bm_ch = 0; unsigned long time = millis();

ibus.begin();

// read analog pins - one per channel for(i=0; i < 3; i++) ibus.write(1000 + (uint32_t)analogRead(analogPins[i])*1000/1023); // map 0-1023 to 1000-2000

// read digital pins - one per channel for(i=0; i < DIGITAL_INPUTS_COUNT; i++) ibus.write(digitalRead(digitalPins[i]) == LOW ? 2000 : 1000);

// read digital bit-mapped pins - 16 pins go in one channel for(i=0; i < DIGITAL_BITMAPPED_INPUTS_COUNT; i++) { int bit = i%16; if(digitalRead(digitalBitmappedPins[i]) == LOW) bm_ch |= 1 << bit;

  if(bit == 15 || i == DIGITAL_BITMAPPED_INPUTS_COUNT-1) {
     // data for one channel ready
     ibus.write(bm_ch);
     bm_ch = 0;
  }

}

ibus.end();

time = millis() - time; // time elapsed in reading the inputs if(time < UPDATE_INTERVAL) // sleep till it is time for the next update delay(UPDATE_INTERVAL - time); }

Cleric-K commented 1 year ago

I tested it, you need to change your for(i=0; i < 3; i++) back to

// read analog pins - one per channel
for(i=0; i < ANALOG_INPUTS_COUNT; i++)
justinspam304 commented 1 year ago

Thank you for the resolution! It works now. So, first I forgot add anaolog pins to the array, then I did diagnostics and found that the loop to check pins would not run since the control variable was set to 0. I looped through the analog pins 1 too many times and got 'high latency.' Once I changed the loop control to the original code once again all works well. Have a blessed day!