Are we not allowed to connect two different pwm signals to the same pinout?

I’m using multiple potentiometers outputs (4 in total for a joystick) and I created four pwm-write nodes and connected each potentiometer node to their own pwm-write node. The thing is the motor control board only uses 2 pwm pins. So my different pwm-write nodes are using the same digital pinouts. I figure this would be fine since only one potentiometer would be active at one time due to being a joystick. The problem is that most of the pwm signals are off now and are weaker than normal and only one direction has the normal pwm signal to turn a motor. Is this a bug or can we not do what I’m trying to do. Whats weird is the watch nodes shows full pwm signal but the motor control board in real life is not getting that signal and reacts like the signal is weak. If I change to only using d5 and d6 only once on the nodes. The motor control boards picks up a good pwm signal and runs the motor like it should. joystick.xodball (15.5 KB)

A single joystick only has 2 potentiometers and should only be producing 2 outputs (one for vertical position and one for horizontal position of joystick). Generally there are 3 pins for each potentiometer; the middle connects to your analog input pin, one to ground and one to power. Reading the analog pin should return a value between 0 (pushed to one extreme) and 1 (pushed to the other extreme). Ideally, middle will return 0.5, but there will usually be some variation in those values for each potentiometer.

You only want to be writing one value to a PWM pin at any time. If you have multiple nodes writing to the same pin, only one can be active at a time.

I mapped clipped the joystick to produce 4 values (up, down, left, and right) and I have up and down both power the same pwm pins. But only one value is active with a signal at one time but still its doesn’t work due the pwm signals not being the same for both up and down. Only one of the direction gets the true pwm signal. The other direction the pwm signal is so weak that the motor wont even turn and just buzzes.

edit: Nevermind. I see why it doesnt work because its still reading the 0 value from the other direction. I was thinking in my mind that the 0 value would be ignored. Is there a way I can couple these signals together and to send out when one is recieved?

You have 4 different nodes writing to the same pin, all using “loop” on UPD pin, so they are all active all the time. This is NOT going to work. To fix this, you would need to add logic so only one PWM node for a specific pin is allowed to UPD at a time. A better solution is to re-code to only need one PWM node for each pin.

If I understand correctly, you want pwm=0 when joystick is center. When you move it up or down PWM starts increasing until it reaches 1 at full joystick motion. I assume digitial-write nodes are for direction.

One idea would be to subtract 0.5 from joystick value so it is in the range -0.5 to 0.5. >0 gives direction; abs node will convert to absolute value, giving 0 to 0.5 which you can map to 0 to 1 (just multiply by 2) for PWM value. Now you just have one PWM value that doesn’t care if it is up or down, so you can just use one PWM node.

A more direct, but less elegant solution would be to use if-else nodes to select which value from your current code is “correct” and feed that to the single PWM node for each pin.

That gives you 3 entirely different solutions that are all equally correct.

  1. Use your current code, but add logic to only allow one node for each pin to UPD (this will probably generate the solution that uses the most nodes & be the most complicated).
  2. Use your current code, but feed each PWM value to if-else nodes and select the “correct” value to send to a single PWM node for each pin. (A little safer since you won’t have multiple nodes that could write different values to the same pin at the same time, but almost as complicated as first solution)
  3. Use math tricks to generate a single PWM value so you don’t need the logic to find the “correct” value to use. While not necessarily an obvious solution, it requires few nodes to code, making a very simple solution.