0
\$\begingroup\$

I'm working on a device based on an ESP8266 (Wemos D1 Mini) that shall be connected to a C64 or Atari 8-Bit computer's joystick port. At the same time, a normal joystick could be connected (signals are passed through). The device should then both be able to listen to the joystick movements as well as also be able to simulate a joystick.

In my current setup, I have taken the risk of hooking up the ESP directly to the joystick cable, despite the fact that the ESP should not have 5V as input on the pins. So far it has been running for a few days now without a problem, but I want to make it right and apply the correct voltage. If possible, this should be a voltage divider done with resistors because I want people to be able to build this device on a bread board.

My problem now lies in the fact that the joystick port constantly delivers 5V on the direction pins. For a voltage divider to work, I would have to have, say, a 1k and a 2k resistor leading from 5V to GND, and then tap the signal between the resistors and connect the resulting 3.3V to the ESP. However, the joystick only connects the corresponding wires to ground if it is moved to that direction. If I understand things correctly, that would mean if the joystick is in idle position, none of the 5V pins are connected to ground and thus there is no voltage division. As a result, the 5V from the joystick port would then again be applied directly to the ESP's pins.

On the other hand, if I make a bypass after the two resistors to GND for the voltage divider to work, the C64/Atari would detect that the direction pin has been connected to ground and thus interpret this as the joystick's move in that direction.

If my thoughts are correct, what other way could there be to bring down the joystick port's current to 3.3V?

Thanks in advance for any ideas!

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Please draw the circuit how it is according to you \$\endgroup\$ – Umar Aug 21 '19 at 19:06
  • \$\begingroup\$ Sorry, should have done this right away... \$\endgroup\$ – fredlcore Aug 21 '19 at 20:59
  • \$\begingroup\$ i use red LEDs instead of wires for these situations involving esp8266s. they drop about 1.8v on the way to the output (5v-1.8v = 3.2v). Yes, the Vf varies slightly with load, but that doesn't really matter to the input. \$\endgroup\$ – dandavis Aug 21 '19 at 21:02
  • \$\begingroup\$ @dandavis: Thanks, I was thinking of diodes, could you post this as a solution, as I would still have some questions? Thanks! \$\endgroup\$ – fredlcore Aug 21 '19 at 21:05
  • \$\begingroup\$ @dandavis: Although I have a voltage drop to 3.6V, the voltage only goes down to 3.3V when the pin is pulled to ground by the joystick which is probably the ESP's voltage on the pin. But it's probably better we discuss this properly below. Thanks! \$\endgroup\$ – fredlcore Aug 22 '19 at 7:47
1
\$\begingroup\$

Here's a way you could isolate the C64's +5V from the ESP8266, and still be able to 'listen' to the joystick switches.

schematic

simulate this circuit – Schematic created using CircuitLab

When the joystick switch or ESP output pulls to Ground, Q1 is turned on through R1. When the joystick switch is off The transistor's Emitter is pulled up to ~2.7V by R1, which should be high enough for the ESP8266 to detect as a high logic signal.

\$\endgroup\$
  • \$\begingroup\$ Thanks! V1 would be the 3.3V pin of the Wemos, correct? And are the 2.7V specific to the 2N3904 transistor or could I use a BC547 as well (also NPN and I have lots of them still laying around here...)? \$\endgroup\$ – fredlcore Aug 21 '19 at 22:04
  • \$\begingroup\$ Yes, use the 3.3V on the ESP8266. BC547 should work fine (it's practically equivalent to the 2N3904). 2.7V is 3.3V - 0.6V estimated Base-Emitter voltage drop, which is a feature of bipolar transistors. \$\endgroup\$ – Bruce Abbott Aug 22 '19 at 1:05
  • \$\begingroup\$ Hmm, this almost seems to work... I wired just the fire button to test this setup, and the ESP detects presses of the button perfectly. However, the C64 does not detect when a button is pressed. Although I measure 0V on the emitter as well as on the joystick's fire button pin, the collector and thus the C64's fire button pin stays at 5V. Any idea what I could have done wrong or how to fix this? \$\endgroup\$ – fredlcore Aug 22 '19 at 7:50
  • \$\begingroup\$ Only thing I can think of is that you have the transistor wired wrong. Disconnect the 'Collector'. Does voltage at the 'Emitter' drop below 3.3V? \$\endgroup\$ – Bruce Abbott Aug 22 '19 at 7:51
  • \$\begingroup\$ It was indeed a wiring error, but not with the transistor - turns out the power rails of my bread board only go halfway on each side of the board. Now it works perfectly, thank you so much! \$\endgroup\$ – fredlcore Aug 22 '19 at 7:54
2
\$\begingroup\$

On the C64, all pins (up, down, left, right, button) are pulled high internally by resistors and will show 5V.

When a classic joystick is moved, it will mechanically connect the corresponding pin to GND, forcing it to 0V.

To emulate this from a microcontroller you can use either:

  • An NPN transistor with emitter to ground, collector to joystick pin, base to the microcontroller output via a resistor
  • A N-channel logic-level MOSFET with source to ground, drain to joystick pin, gate to microcontroller output

Replicate this circuit for each of the 5 signals and you're good to go.

\$\endgroup\$
  • \$\begingroup\$ Thanks! I upvoted your answer, but it doesn't show due to my still "low" reputation. \$\endgroup\$ – fredlcore Aug 21 '19 at 20:46
  • \$\begingroup\$ I like the idea with the NPN transistors, but one question remains for me: Would I be still able to "listen" on what is going on on the joystick port? I uploaded the schematic in my original post to show my current (very simple and not voltage compliant) setting. I can both "listen"/detect what kind of joystick moves are being made and also let the Wemos react to that as if it was a joystick. I fear that with the transistor solution, I might lose the possibility to detect what movements are being made with the joystick if the Wemos' pins are behind the transistors? \$\endgroup\$ – fredlcore Aug 21 '19 at 20:58
  • \$\begingroup\$ Also, how would I calculate the resistor's value that goes from the base to the Wemos? \$\endgroup\$ – fredlcore Aug 21 '19 at 21:01
1
\$\begingroup\$

Make a "FET level shifter" from discrete components. All you need is 2 resistors and the FET, for each data pin. It limits the voltage to 3.3V microcontroller and it can still pull the 5V side down.

\$\endgroup\$
  • \$\begingroup\$ Thanks! I upvoted this solution, but due to my still "low" reputation, it is not displayed here... \$\endgroup\$ – fredlcore Aug 21 '19 at 20:45
  • \$\begingroup\$ Would this still enable me to "listen" to what is going on on the joystick port or just enable me to let the Wemos act like a joystick? \$\endgroup\$ – fredlcore Aug 21 '19 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.