0
\$\begingroup\$

I am trying to communicate with a Vending machine using MDB Protocol with the help of Arduino Mega and I am partially successful in doing so.

The circuit that I am using is attached here

Breadboard Layout of Circuit

While the circuit diagram is shown below

Circuit Diagram

The Arduino Mega is communicating with laptop via Serial 1 and the vending machine communication is done via Serial 2 of Arduino Mega.
USART is being use for communication.

The strange issue that I am facing is, the communication with the vending machine starts sending data only when brown colored wires A and B are initially not connected(which are connecting Arduino TX to Vending Machine RX). Once I see the data coming from Vending Machine, I short wires A and B and Arduino Starts sending data to the vending machine too.
But if Wires A and B are connected on the start of a vending machine, the vending machine doesn't send any data to Arduino and hence no communication takes place. I want to make it work without manually connecting wire A and B every time.


I have tried replacing Optocoupler PC817C with

  • PC814
  • 4N35
  • 6N137 High Speed Optocoupler

I tried replacing Hex Inverter with

  • 74HC04AP

I tried putting a mechanical and then solid-state relay between wires A and B and tried connecting them via external input but nothing happens
I tired adding an optocoupler as a switch between wires A and B and tried controlling it via firmware.

I even tried replacing the hex inverter with hex buffer HCF4050BE and a NOT Gate but regardless of any combination of mentioned components the issue remains the same, it only works if Wires A and B are initially not connected and then shorted once data starts coming from the vending machine.

I am using MateDealer's code.
I want to automate this manual process and need a simple solution for that.

\$\endgroup\$
  • 1
    \$\begingroup\$ Why are you using an optoisolator for Arduino's TX, but not for RX? Why are you using two inverters in series for TX? After you manually open and close the connection, are both devices able to communicate properly or is it that data is just sent around regardless of who is listening? \$\endgroup\$ – RaphaelP Dec 13 '19 at 11:34
  • \$\begingroup\$ Optoisolators are necessary for both of the pins and I had them on both of the pins but that's not an issue here. The signal is passed from two inverters{acting as a buffer}(the ic 74hc14n here is a Schmitt-Trigger) to make sure that signal is in good shape. After I open and close the connections, both of the devices start communicating with each other properly. \$\endgroup\$ – Nauman Shakir Dec 13 '19 at 11:37
  • \$\begingroup\$ Are you sure you need a schmitt trigger to guarantee the signal is in good shape? Maybe you should make things simpler and drive the opto directly. Also, there's no opto on Arduino's RX path on your diagram. As a last note, usually when using optos for isolating a communication line, you don't tie together the grounds. Arduino's ground goes on one side and vending machine on the other side of the optos. \$\endgroup\$ – RaphaelP Dec 13 '19 at 11:57
  • \$\begingroup\$ Actually the wires used for communication are pretty long in length that's why adding a Schmitt-Trigger is a good idea. I will surely add the opto on RX line and will share the update. Grounds are actaually isolated now but it didn't make any difference. \$\endgroup\$ – Nauman Shakir Dec 13 '19 at 12:02
  • \$\begingroup\$ Long lines should not matter like that. The Arduino is close to the opto (I assume) and should be able to drive it with perfect signal without the buffer. The long lines will only influence what happens after the opto. Nevertheless, you should keep an eye to what happens with the communication line when the Arduino is waking up. Without the buffer, the Arduino's outputs would start at high-z and wound not affect the comm line. With the buffer, there's a doubt about what is driving the opto and what it's doing before the Arduino initializes properly. \$\endgroup\$ – RaphaelP Dec 13 '19 at 12:19

Your Answer

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

Browse other questions tagged or ask your own question.