Control a Due with a cabled remote - Why so hard?

Hi everybody,
I have a seemingly simple question which I'm stuck with for weeks already now (beginner) concerning the general plan of a project rather then the microcontroller itself.
I have a Arduino Due that controls a nema 23 Stepper motor. I want to be able to control different modes the stepper in in using push buttons, as well as the speed etc. using pots, which should then be displayed on a 16x2 I2C LCD display.

The problem I have is that the box containing the arduino, power supply and stepper driver is quite bulky, so I want to have all the buttons and the LCD mounted on a smaller remote control, that is connected to the main box via a ~3m long cable. I did all of that, tested it and failed.

Here's the problem: I have 5 push buttons, 1 toggle switch and 3 pots on the remote as well as the I2C display and a Logic level shifter equates to quite a few channels that have to run from the Due to the remote. I archived this by 2 cables with 7 cores and 2 8 pin aviation connectors.

The buttons and pots work, the display does not, which could have been foreseeable if I found out about the limited range of I2C earlier. Just to be exact: The display receives power and turns on, but the communication is essentially 0. I already checked all my soldering of the aviation connectors many times and tested the same without the cable between the Due and the LCD - using only short jumper cables - which works. So I think that the main reason that it doesn't work is the length of the cable.

So my question to you: What would be the easiest way to control my Due using a cable remote with an LCD screen? I thought about radio and Bluetooth already but I want to stay with the cable because (1) it SHOULD be more reliable and (b) requires less modifications.

Thanks for your advice!
Cheers

Hello @ptrckw98 ,
Welcome.

I2C is not designed for long cables as you have found out, however it is possible to make it work over longer distances than it is designed for; I have it working perfectly well over about 30m.

You have not said if the cable is twisted pair or individual wires. Get some twisted pair cable, such as cat 5, and use it for I2C as follows:
On one pair put ground and SCL.
On another pair put +5V and SDA.
Put 0μ1 capacitors between 0V and 5V at both ends of the cable.
Use pull up resistors of, maybe, 2k Ohms or even lower down to 1k Ohm if required.
Better still use something like 4k pull up resistors at the Due end of the cable and again use 4k resistors at the display end, so the resistors are in parallel but at opposite ends of the cable.
If you can lower the clock frequency of the I2C do so Wire - Arduino Reference, if you can get it to 10kHz that would be good, but I don't know if that's possible on a Due, you have to experiment.

1 Like

Hello @PerryBebbington and thanks for the advice!

Yes, my cable solution is not perfect - I started with cat 6 cable but the stuff I had was of such low quality that soldering and wire stripping was very frustrating. In addition, the shield was made of some kind of materials that were not solderable at all, so I also picked up tons of EMI from the stepper motor (at least thats my theory from all the glitches I had). My current solution are individual silicone wires that, yes, you're right - I did not twist. However their surrounded by heavy duty speaker cable shielding - so this problem is alleviated.

I have some questions concerning your advice:
(1) I understand that the capacitors are to smooth out the current here, right? What size should I choose and why should I add two? Also, why should this fix my problem? The power supply of the LCD works (seemingly) well, It just does not display anything except the top row of black blocks.
(2) What do the pullup resistors do and where should I connect them? I understand what a pullup does (I think) I just don't understand why it is needed in this context.

So I guess I'll get myself some better quality network cable then...
Again, thanks so much for the help!

Then it was not cat 6 cable, it was some cheap imitation of cat 6 cable.

Get your display working without running the motors, then try the motors and see if they cause interference. If you are using screened cable the screen should be connected to ground at one end only, preferably the controller (Due) end. Us the cat 6 cable for the display and nothing else.

My current solution are individual silicone wires that, yes, you're right - I did not twist. However their surrounded by heavy duty speaker cable shielding - so this problem is alleviated.

It's not alleviated (well, unless you are telling me it now works OK), you need twisted pairs because the signal and it's return path need to be in the same path, twisted pairs achieves this.

[quote]I have some questions concerning your advice:
(1) I understand that the capacitors are to smooth out the current here, right? What size should I choose and why should I add two? Also, why should this fix my problem? The power supply of the LCD works (seemingly) well, It just does not display anything except the top row of black blocks.
(2) What do the pullup resistors do and where should I connect them? I understand what a pullup does (I think) I just don't understand why it is needed in this context.[/quote]

The advice I gave is based on a mixture of experimentation on my part to get I2C working over distances it was not designed for, and transmission line theory, there is too much behind the advice to explain in one short reply. The most important part of my suggestion is to use twisted pairs and to put one of the signals on one pair and the other signal on the other. From the point of AC (which in this case means the signals you are interested in) 0V and +5 are the same thing. The signals need a return path and the return path should be shared with the path the signal takes along the cable, hence a twisted pair. It does not matter what DC is also carried on the wire, so it's OK to use one for 0V and there other for +5V. The capacitors I suggested are to ensure that from an AC point of view those wires are the same. You could instead use SCL + ground on one pair, SDA + ground on another pair then +5V on both wires of a 3rd pair.

Pull up resistors are part of how I2C works, without them there is no source of +5V on SDA and SCL so it does not work. It probably makes no significant difference over 3m of cable but the reason for putting them at both ends of the cable is to absorb any reflections in the cable. With 3m and the frequencies we are talking about this is probably not worth the effort, but I include it as an extra point just in case. The pull up resistors have to charge the capacitance of the cable, making the a lower value means they can do this more quickly, which will be the difference between clean pulses at the other end and pulses that are unuseable.

You need to read up about characteristic impedance, transmission lines, reflections and balanced pairs.

Yes, did exactly that with my first cheap / fake cat 6 prototype. LCD went crazy (and motor too since limit switches probably also experienced EMI) as soon as the motor received power.

So my plan based on your advice will be:

  • Get quality networking cable
  • Don't forget to earth shield
  • Used twisted pairs following: GND + SCL and 3.3 V + SDA
  • Put 0.1μF caps between 3.3V + GND and 5V + GND? on both sides of the cable
  • Use 4k pullups connected between SDA + 3.3V and SCL + 3.3V on both sides of the cable
  • Try to lower the clock frequency in the code

Yes, I just assumed the ones on the I2C backpack of the LCD are enough...
Maybe a follow up question: Does it make a difference whether I use the logic level converter on the Due end or on the remote end of the cable? It is currently in the remote box.
And is there any particular pattern I should follow when connecting the buttons/switches/pots?
In total, I'll need

  • +5V
  • +3.3V
  • GND
  • SDL
  • SCA
  • 5 channels for push buttons
  • 3 channels for pots
  • 1 channel for switch

So a total of 14 channels, meaning I'll have to use 2 cables. Does it matter which of those I combine with the I2C lines (outside the twisted pairs of course)?

Yes, I have to, but time for hobbies is scarce when studying two full time master degrees parallelly, especially when it's biology which is not that related to electrical engineering ...

Again, thank you so much for your advice!

Only put I2C on the cable for the display, put everything else on a different cable. Also, as there will be spare wires in the cat 6 cable you should also connect them to ground at the Due end, along with the screen. DO NOT connect the to ground at both ends.

I didn't know there were any! I don't know what's on the backpack, can you find out? Probably be OK but put some at the Arduino end of the cable too, start with about 4k and see how it goes.

If the display works without the motor running and goes mad when it runs then you need to pay attention to the motor, the cable feeding it and to suppressing the noise at source, that is a different subject and probably worth a different question in the motor's section of the forum with a link to this question.

You can put the io's also on the I2C reducing the number of threads considerably. There are small transducers available that create I2C out of the the digital and analog inputs.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.