Cleric-K / vJoySerialFeeder

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

How to decipher Channels #58

Closed BuilderSky closed 2 years ago

BuilderSky commented 2 years ago

Hello, This is BuilderSky! I use the Arduino UNO and a Windows 11 OS. I am not sure how to tell what channel a sensor is connected to. I have four potentiometers connected consecutively from A0-A3, and I have found that these correspond to channels 1-4, consecutively. The problem is, I have buttons (Simple Pushbuttons) that I want to connect. For example, I'll use two buttons. I want to connect these buttons to D2 & D3 pins, but I cannot figure out what channel they correspond to. I have tried channels 2 & 3, but they obviously collide with the other channels (1-4) that are used by the Analog pins. I have also tried going all the way up to the 10th channel (and past, actually) to find the right channel, but none of them work. I have also moved both buttons past the D7 pin on the UNO, and still no luck finding the correct channel. Please tell me how to find the correct channel, or else add it to the Readme or something! Thank you! :)

Cleric-K commented 2 years ago

Hi,

first make sure you have configured the Arduino sketch properly. If you want to use D2 and D3 your code should look like:

#define DIGITAL_INPUTS_COUNT 2
byte digitalPins[] = {2, 3}; // element count MUST be == DIGITAL_INPUTS_COUNT

{2, 3} means {D2, D3}. Make sure DIGITAL_INPUTS_COUNT is 2.

Then your analog channels will be from 1 to 4, D2 will be channel 5 and D3 wil be channel 6. You can always use the Channel Monitor to easily observe how channel values change upon your inputs.

BuilderSky commented 2 years ago

Hi,

first make sure you have configured the Arduino sketch properly. If you want to use D2 and D3 your code should look like:

#define DIGITAL_INPUTS_COUNT 2
byte digitalPins[] = {2, 3}; // element count MUST be == DIGITAL_INPUTS_COUNT

{2, 3} means {D2, D3}. Make sure DIGITAL_INPUTS_COUNT is 2.

Then your analog channels will be from 1 to 4, D2 will be channel 5 and D3 wil be channel 6. You can always use the Channel Monitor to easily observe how channel values change upon your inputs.

Hey Cleric, thank you so much! I will try it and let you know how it goes!!! I was thinking that I should list all the pins on the Uno, not only the ones I'm using. I will try that right now and let you know how it goes! TYSM!!! I'm actually using your system for a BeamNG wheel and pedals. 😊

BuilderSky commented 2 years ago

@Cleric-K For some reason, it still does not want to recognize the button inputs.

BuilderSky commented 2 years ago

Actually, I figured it out.. the problem is that there is no pull-down resistor, so it simply jumps around when there is no input.

BuilderSky commented 2 years ago

Ok, so even after I added pinMode(2, INPUT_PULLUP); It still does not recognize that pin. I am not sure what is wrong here... I also added a 10KResistor for a physical Pullup instead of just the INPUT_PULLUP and it still didn't do anything

Cleric-K commented 2 years ago

I'm not sure what this is. Can you try using D13? It is wired to the onboard LED through a resistor so it is basically pulled down. If you supply 5V to it you should see the LED light up. In this way you'll have an idea if the problem is electric there's something else going on.

BuilderSky commented 2 years ago

I'm not sure what this is. Can you try using D13? It is wired to the onboard LED through a resistor so it is basically pulled down. If you supply 5V to it you should see the LED light up. In this way you'll have an idea if the problem is electric there's something else going on.

Yes, the LED on pin 13 successfully lights up. Let me use a fresh version of the .ino file here... EDIT: The Fresh re-install of the .ino file did not fix the issue.

Cleric-K commented 2 years ago

That's pretty strange. Can you send your whole source code of the .ino file?

BuilderSky commented 2 years ago

Steering Wheel.zip @Cleric-K Here you go... This is after I refreshed everything with your .ino file on your GitHub. I don't think I changed anything except the pin #'s and the count of the pins used. Sorry for taking so long to get back to ya, I was taking a MAP test :/ (Not fun...) Also, I set the pin to 13 to see what would happen there, I forgot to change it back to 2 & 3.

Cleric-K commented 2 years ago

That's strange. I uploaded your sketch to an UNO and it seems fine. Here's a capture from the channel monitor. capt2

Actually now as I think, is the problem that you don't see change of the channel value in the monitor? Or you can't set up the Button mapping? For the mapping you need to change the threshold. The default value is 1500 which is the the standard middle value for RC controllers (their value change from 1000 to 2000). But the Arduino sends 0 to 1023, so you need to change the threshold somewhere around 500 through the Setup button.

BuilderSky commented 2 years ago

That's strange. I uploaded your sketch to an UNO and it seems fine. Here's a capture from the channel monitor. capt2

Actually now as I think, is the problem that you don't see change of the channel value in the monitor? Or you can't set up the Button mapping? For the mapping you need to change the threshold. The default value is 1500 which is the the standard middle value for RC controllers (their value change from 1000 to 2000). But the Arduino sends 0 to 1023, so you need to change the threshold somewhere around 500 through the Setup button.

@Cleric-K Yeah, it doesn't show up in the Channel Monitor as changing, and the "Input" does not change in the Feeder, either; even after I changed the value to 50 in the threshold. The "Input" value is sitting at 1023. Do you have Discord or something where I could show you what's going on?

Cleric-K commented 2 years ago

I need to get off the PC now but all this is pretty strange. Do you have another Arduino to test with?

BuilderSky commented 2 years ago

I need to get off the PC now but all this is pretty strange. Do you have another Arduino to test with?

Alright, Just chat whenever, if you do have Discord and are in the Arduino server, I am Sky777 (Pings Accepted). Yes, I have another Arduino, and I will try it on that. I will post my results here.

BuilderSky commented 2 years ago

Ok, so I created a video.. Oddly enough, Pin 13 works like a charm on the second Arduino, but no other pin will work. I am not sure what to do at this point :/ https://www.dropbox.com/t/vhHWgHIYjPFa8PX6

Cleric-K commented 2 years ago

I have no idea what this could be.

You can try this minimal sketch.

void setup() {
  Serial.begin(115200);
}

void loop() {
  for(int i=0;i<14;i++) {
    Serial.print(digitalRead(i));
    Serial.print(" ");
  }

  Serial.println();
  delay(500);
}

Upload it, then open in Arduino IDE Tools/Serial Monitor, change the speed to 115200 and observe. Take a jumper wire and give 5V to the various ports. Don't touch port 0 and 1 (TX/RX) because they're in use by the serial communication. The sketch prints 14 digits (0/1) for ports 0 through 13. You should see them changing to 1 when connected to 5V. Don't worry that most ports may seem to change randomly - it's because they are not pulled down so they are floating.

Try giving GND or 5V to each port and make sure the corresponding digit in the output changes accordingly. In this way you'll know if everything with the hardware works OK.

BuilderSky commented 2 years ago

I have no idea what this could be.

You can try this minimal sketch. (...) Upload it, then open in Arduino IDE Tools/Serial Monitor, change the speed to 115200 and observe. Take a jumper wire and give 5V to the various ports. Don't touch port 0 and 1 (TX/RX) because they're in use by the serial communication. The sketch prints 14 digits (0/1) for ports 0 through 13. You should see them changing to 1 when connected to 5V. Don't worry that most ports may seem to change randomly - it's because they are not pulled down so they are floating.

Try giving GND or 5V to each port and make sure the corresponding digit in the output changes accordingly. In this way you'll know if everything with the hardware works OK.

Yes, I had tried something similar before, and even now, on the new board, they still recognize the Voltage input just fine. Like you said, they tend to float around a lot when not connected to anything, but when the 5V goes in, they immediately lift up to 1 and stay there for the duration of the 5V Input.

Should I perhaps un-install and reinstall the VJoy Feeder?

Cleric-K commented 2 years ago

Should I perhaps un-install and reinstall the VJoy Feeder?

I don't see how this can be related. Try for a test a sketch with only digital channel. Make:

#define ANALOG_INPUTS_COUNT 0
byte analogPins[] = {};

Also you may try in vjsf to click the Setup button next to the IBUS protocol selector and then check the Use 16bit channels (although in my tests this shouldn't be an issue).

BuilderSky commented 2 years ago

Ok, so I use VJoy 2.1.9... I saw the instructions on this page, and thought maybe that could fix something, even though it's for 2.1.8... And then I started looking, you have an Interface file for driver version 2.1.9 as well. I was wondering maybe that would fix something if I used the one for 2.1.9 instead of the one for 2.1.8? Here is what I found in the code... the Code

BuilderSky commented 2 years ago

Should I perhaps un-install and reinstall the VJoy Feeder?

I don't see how this can be related. Try for a test a sketch with only digital channel. Make:

#define ANALOG_INPUTS_COUNT 0
byte analogPins[] = {};

Also you may try in vjsf to click the Setup button next to the IBUS protocol selector and then check the Use 16bit channels (although in my tests this shouldn't be an issue).

Yes, I check that [16bit Channel] almost every time. It has stayed selected the whole time.

Ok, so I did what you said.. something interesting.... The button will work, I tried it on pins 12, 2 and 3 individually, but it will only tell the signal to go HIGH, I physically have to insert the pin into GND to get it to go back to a LOW state.

I also tried using a second button, making a separate channel and everything, and the second button received no input signal whatsoever. It stayed at a constant LOW, while the first button continued to work as described above. (EDIT: I just now tried adding a resistor, same result)

Cleric-K commented 2 years ago

OK. Try this

void setup() {
  for(int i=2;i<13;i++) {
    pinMode(i, INPUT_PULLUP);
  }
  Serial.begin(115200);
}

void loop() {
  for(int i=0;i<14;i++) {
    Serial.print(digitalRead(i));
    Serial.print(" ");
  }

  Serial.println();
  delay(500);
}

It sets the ports to use the internal pullup resistors. In this case you should see all 1s in the monitor and you should connect GND to a port to bring it down. Make sure all ports respond.

BuilderSky commented 2 years ago

Alright, I will do this tonight. I am at work right now, without the Arduino or anything. My apologies Thank you!

BuilderSky commented 2 years ago

OK. Try this (...) It sets the ports to use the internal pullup resistors. In this case you should see all 1s in the monitor and you should connect GND to a port to bring it down. Make sure all ports respond.

Checked successfully! Although port D1 does float around, all other pins completed the check successfully! Even D0.

Cleric-K commented 2 years ago

Try with this: Joystick.zip

I've changed digital ports to work with internal pull ups. You man need to make slight changes to your hardware. Your switches should connect to ports to GND. When the port is connected to GND the button is considered pressed. Otherwise it is pulled high and it is considered depressed.

I also changed the numbers to make it more compatible with the RC standards (values 1000 to 2000). In this way the default mappings should work without calibrating.

BuilderSky commented 2 years ago

Try with this: Joystick.zip

I've changed digital ports to work with internal pull ups. You man need to make slight changes to your hardware. Your switches should connect to ports to GND. When the port is connected to GND the button is considered pressed. Otherwise it is pulled high and it is considered depressed.

I also changed the numbers to make it more compatible with the RC standards (values 1000 to 2000). In this way the default mappings should work without calibrating.

Well, You're an absolute genius!!! It works like a charm now! TYSM! What's strange is, I was trying to do the same thing with pulling it up, using the PinMode, but I was doing it inside of the same loop that wrote the HIGH vs LOW to the Serial port. I wonder why that wasn't compatible... But TYSM!!! That is absolutely awesome, I am so excited!!! I wish there was a way to show you my progress, with as much as you helped me... TYSM, again!!! :)

Cleric-K commented 2 years ago

Great news! And thank you for bringing this up. I have updated the Arduino sketch to make use pulled up inputs by default. Also I have removed the requirement to #define DIGITAL_INPUTS_COUNT. These are now calculated automatically. So overall I think it will be easier for other users too :)