Code that "breaks" arduino

Can the code in conjunction with the wiring have a destructive effect on the arduino? Or is it just a specific wiring mishap that may have caused some damage? It just seemed unlikely to me considering I'm only using 5V, ...

To me this is the most concerning statement as it indicates a lack of understanding of a basic concern/issue.
Yes 5v is plenty of voltage to cause damage. As others have said, over-current is what really causes the damage and with nothing to limit the current (like an in line resistor) too much current can easily flow and damage the AVR.
This is why directly connecting a pin to a voltage, +5, GND, or the output of a another pin that is driving a signal has the potential to cause damage, if the pin is ever driven.
The damage occurs whenever the pin that "should" be an input is changed to be an output.

sbrown:
I see, would the input on the pins still register as "HIGH" with said resistor in place?

yes

I've set all those PWM pins to inputs and the arduino won't light the green LED unless they read HIGH.

Calling them "PWM pins" is confusing people as PWM refers to a pin that is outputting a PWM signal.
You do not appear to be using them for PWM, so while the Arduino pins you may be using may support PWM, I would not call them PWM pins unless you are really using them for PWM output. Just call them "Arduino pins".

The Arduino pins you are using will always read high if you have things hooked up the way they are shown in the images in post #33.
In those images, pins 7,8,9, & 10 are all directly connected to 5v.
In post #12 it isn't clear how you have things wired up.

Overall, I'm still very confused as to how you have things wired up and it sounds like you have also wired things up a a few different ways.

A few things to keep in mind:

The AVR will power up with all pins as inputs.
The bootloader will attempt to blink the LED as it comes up after a reset, (but not directly from a power up).
The led on an UNO is wired up to pin 13. So if you have pin 13 connected to something that has voltage on it or is grounded, the bootloader trying to blink the LED will damage the AVR as soon as the AVR is reset - which happens whenever the reset button is pressed, or whenever you upload something.

--- bill

Thank you Bill. The only way I've had it wired is as shown in image #33.

The final configuration is to use 2 connectors for each cable.

Using image #33 as an example: The red wires represent the 4-wire cable, therefore I will have 2 connectors each with 4 slots. One connector will attach to the wires coming from the 5V, and the other will connect to the wires leading to the arduino pins (7-10). The purpose of this code is to make sure a cable is continuous, these connectors are designed to fit the 4-wire cable. This way when i plug each end of the cable into the connectors, if a wire inside the cable is damaged the red LED will light, if all wires are good the green LED will light.

I've only wired it as shown in post #33, just to emulate the situation and see if the code worked.

You are only checking for open circuit fail condition. Is there any chance of a short circuit condition between two of the wire?

Robin2:
analogWrite() sets them as output.

...R

I never used analogWrite(). And I don't want them as outputs. Or are you saying that's something Arduino will do by default?

adwsystems:
You are only checking for open circuit fail condition. Is there any chance of a short circuit condition between two of the wire?

Unlikely, but that is a good point.

sbrown:
I never used analogWrite(). And I don't want them as outputs. Or are you saying that's something Arduino will do by default?

I don't know how the pins default and what happens if you have +5V on the pins when the Arduino is powered on or reset.

Testing for short circuit would require a different architecture but still within the abilities of the UNO.

Do you ever have cause to test a 2, 3, and a 4 position cables at the same time? Or only test one cable type at a time?

adwsystems:
I don't know how the pins default and what happens if you have +5V on the pins when the Arduino is powered on or reset.

Testing for short circuit would require a different architecture but still within the abilities of the UNO.

Do you ever have cause to test a 2, 3, and a 4 position cables at the same time? Or only test one cable type at a time?

  1. In the setup of my code I set pins 2-10 as inputs. Are you saying right when the arduino is powered on, 5V will be flowing to those pins immediately, and they could be defaulted to outputs upon reset / start up? They won't be set to inputs before the 5V is allowed to flow? I suppose the 5V pin is an open circuit with nothing on the arduino's part allowing it to stop it? I suppose I will try placing a ~200 Ohm resistor in series before the wires on my 5V output as Bill suggested.

  2. Shorting is not a concern.

  3. No, only one cable can be tested at a time. I'm aware it will cause issues if another cable is tested before the previous one is unplugged. The arduino needs to restart its "void loop()" in order for the LED and pin values to be reset.

K.I.S.S.

What if for the two pin cable you look at pins 2-3, for the three pin cable look at pins 2-3-4, for the 4 pin cable look at pins 2-3-4-5?

=====================================================================

That makes available an option for version 2.

That reduces the number of pins you need from 9 to 4. If you make pins 2-3-4-5 inputs and 6-7-8-9 outputs you can loop the arduino pins back to itself rather than feeding from and external supply (or from the Arduino regulator.

Then you can take it one step further. Since pin 2 is connected to pin 6, then only pin 6 should be on when pin 2 is on. If pins 7, 8, or 9 are on then you have a short.

=====================================================================

That brings up another question. Where is the +5V coming from? The UNO board 5V pin or an external 5V supply? Have you ever attached and external 5V source to the other end of the cables?

adwsystems:
K.I.S.S.

What if for the two pin cable you look at pins 2-3, for the three pin cable look at pins 2-3-4, for the 4 pin cable look at pins 2-3-4-5?

=====================================================================

That brings up another question. Where is the +5V coming from? The UNO board 5V pin or an external 5V supply? Have you ever attached and external 5V source to the other end of the cables?

  1. I'll think about this, the issue I see with that is how does the arduino know which cable I'm testing? If I plug in a 3 wire cable that has discontinuity in its 3rd wire, the arduino will just detect it as the 2 wire cable and light the green LED.

  2. The +5V is always coming from the board, I've never hooked up an external power supply. The most I've done is have the USB and arduino power chord both hooked up to the arduino at the same time. In fact, I've never actually even tested with the cables yet. (just using 24AWG wire as shown in post 33 images)

Since your thinking about a PCB, i’d be looking at isolating the cable drivers and inputs. This isn’t your basic problem, but good form.
Any stray conditions or noise on the wires will damage your Arduino pins.
(Many professional cable testers even use small pc mounted relays for physical isolation - as well as the optos.)

Possibly a simple biased transistor outout, and opto-isolated input.
You can never have too much protection against the operating environment.

sbrown:

  1. I'll think about this, the issue I see with that is how does the arduino know which cable I'm testing? If I plug in a 3 wire cable that has discontinuity in its 3rd wire, the arduino will just detect it as the 2 wire cable and light the green LED.

I would say that's an issue. If you plug in a 3 wire cable with continuity only on pins 1 and 2 the result is PASS. If the failures for each pin are equal, then you accept 1/3 of failed cables of which those 100% are failed on pin 3.

(manufacturing statistics are useful sometimes, otherwise they are a pain)

In the bigger picture, i'm not sure why you are not worried about shorts in your cables, as a true cable tester should test for both continuity of each wire as well as any shorts between wires.
And as a true aid, it would be useful to indicate which wire(s) has the issue(s).

like mentioned above, I'd use arduino "output" pins to detect continuity and shorts rather than full voltage.

However, to avoid any high current issues,
i'd use arduino pins in INPUT_PULLUP mode and then drive the Arduino "output" pin connected to the wire low to test for continuity.
I'd also never use high outputs.
i.e. I'd change the pin connected through the wires connected to the input pins between OUTPUT and INPUT_PULLUP
that will change the signal from driven high to pulled up.
There is no need to actually use digitalWrite() as the default bit state in the register is zero.
Simply changing the mode will flip between the two states.

The input pins will then see a LOW when the "output" pin is set to OUTPUT mode and HIGH when the "output" pin is set to INPUT_PULLUP mode -or- there is no continuity like a broken wire.
You can easily detect the difference between the "output" being INPUT_PULLUP and a broken wire because if you see the input drop low when the "output" pin is set to OUTPUT, then you know there is continuity.

This avoids any type of short issue and there is never any signal driving 5v on the wires.

--- bill

adwsystems:
I would say that's an issue. If you plug in a 3 wire cable with continuity only on pins 1 and 2 the result is PASS. If the failures for each pin are equal, then you accept 1/3 of failed cables of which those 100% are failed on pin 3.

(manufacturing statistics are useful sometimes, otherwise they are a pain)

Unless I can find some way around this by rewriting the code, but it's hard to see.

I mean, it's unlikely that would be the case, but given that the only thing I'm testing for is continuity I don't think that's an option unless I can figure out a work around.

Good idea though.

lastchancename:
Since your thinking about a PCB, i’d be looking at isolating the cable drivers and inputs. This isn’t your basic problem, but good form.

You can never have too much protection against the operating environment.

Thanks, I'll consider that.

bperrybap:
In the bigger picture, i'm not sure why you are not worried about shorts in your cables, as a true cable tester should test for both continuity of each wire as well as any shorts between wires.
And as a true aid, it would be useful to indicate which wire(s) has the issue(s).

like mentioned above, I'd use arduino "output" pins to detect continuity and shorts rather than full voltage.

However, to avoid any high current issues,
i'd use arduino pins in INPUT_PULLUP mode and then drive the Arduino "output" pin connected to the wire low to test for continuity.
I'd also never use high outputs.
i.e. I'd change the pin connected through the wires connected to the input pins between OUTPUT and INPUT_PULLUP
that will change the signal from driven high to pulled up.
There is no need to actually use digitalWrite() as the default bit state in the register is zero.
Simply changing the mode will flip between the two states.

The input pins will then see a LOW when the "output" pin is set to OUTPUT mode and HIGH when the "output" pin is set to INPUT_PULLUP mode -or- there is no continuity like a broken wire.
You can easily detect the difference between the "output" being INPUT_PULLUP and a broken wire because if you see the input drop low when the "output" pin is set to OUTPUT, then you know there is continuity.

This avoids any type of short issue and there is never any signal driving 5v on the wires.

--- bill

This sounds like good stuff. I'm new to arduino and have only 1 semester of programming in c++ so I'll have to do some reading on what all that means.

I'm not sure why they don't care about shorting (this is for work) but if I can detect shorts and also detect which wire is giving a continuity issue that's a bonus. I've thought about it myself just wasn't sure how I'd make it work.

Thank you all for your help and ideas.

You will need to signal to the board how many conductors to test. In the event the operator leave the knob on two pin and puts a three pin cable on it would be an issue. That would lead back to using your arrangement of separate pins for each cable. But with some clever I/O management both can work.

There are 20 I/O pins on the UNO.

0-1: USB TX/RX

2: Pin 1 all cables
3: 2 pin cable pin 2
4-5: 3 pin cable pins 2-3
6-7-8: 4 pin cable pins 2-3-4

9: Pin 1 all cables
10-11: 2 pin cable pin 2
A0-A1: 3 pin cable pins 2-3
A2-A3-A4: 4 pin cable pins 2-3-4

LEDs on pins 12 and 1
A5-A6: Cable select 0-0=2 pin, 0-1=3 pin; 1-1=4 pin

You can read the analog pins using digitalRead(Ax)

As for the direction bperrybap is heading, instead of toggling the outputs HIGH and LOW using digitalWrite(x), change the the pinMode from INPUT_PULLUP (which becomes the high output) and OUTPUT (which becomes low output). As mentioned the advantage is the built-in current limiting.

Even if you don't test for the shorts, bperrybap comments have a good advantage for your setup.

sbrown:
I'm not sure why they don't care about shorting (this is for work) but if I can detect shorts and also detect which wire is giving a continuity issue that's a bonus. I've thought about it myself just wasn't sure how I'd make it work.

I would go talk to whoever is wanting this.
Talk to them about what they really need and ask about detecting shorts.
You need a good functional specification or at least accurate guidance as to what the product needs to do.

It could be that shorts just don't happen on the their cables given their manufacturing process.
You don't want to go off and do lots of design work for something that may not be needed.

And then there is the issue of how to communicate any issues.
Like is pass/fail enough? or does it it need to also indicate the type of failure including which wires are involved?
The latter is quite a bit more complicated, particularly when considering all the combinations of opens and shorts between wires.

For example, if all that is needed is continuity and no concern for shorts, you don't really need an Arduino.
A simple led that gets voltage through each wire would be good enough.
i.e. plug in the cable, and an LED on each wire lights if there is conductivity.
Kind reminiscent of the old rs232 breakout boxes from days past.

--- bill

bperrybap:
I would go talk to whoever is wanting this.
Talk to them about what they really need and ask about detecting shorts.
You need a good functional specification or at least accurate guidance as to what the product needs to do.

It could be that shorts just don't happen on the their cables given their manufacturing process.
You don't want to go off and do lots of design work for something that may not be needed.

And then there is the issue of how to communicate any issues.
Like is pass/fail enough? or does it it need to also indicate the type of failure including which wires are involved?
The latter is quite a bit more complicated, particularly when considering all the combinations of opens and shorts between wires.

For example, if all that is needed is continuity and no concern for shorts, you don't really need an Arduino.
A simple led that gets voltage through each wire would be good enough.
i.e. plug in the cable, and an LED on each wire lights if there is conductivity.
Kind reminiscent of the old rs232 breakout boxes from days past.

--- bill

I asked, they said they don't need to check for shorts. As for which wire is causing the issue, that can just be check with a voltmeter once its found the cable has an error, but it would be nice to have it built in to the arduino code.

Yes, I could just have a bunch of LED's lined up for each cable, that would also tell which wire isn't continuous and I wouldn't need an arduino.

adwsystems:
As for the direction bperrybap is heading, instead of toggling the outputs HIGH and LOW using digitalWrite(x), change the the pinMode from INPUT_PULLUP (which becomes the high output) and OUTPUT (which becomes low output). As mentioned the advantage is the built-in current limiting.

Even if you don't test for the shorts, bperrybap comments have a good advantage for your setup.

So... for example, in my code.. This:

  digitalWrite(12, HIGH); // 12 is red LED, no continuity
  digitalWrite(11, LOW);  // 11 is green LED, continuity

becomes this?:

  pinMode(12, INPUT_PULLUP); // 12 is red LED, no continuity
  pinMode(11, OUTPUT);  // 11 is green LED, continuity

sbrown:
So... for example, in my code.. This:

  digitalWrite(12, HIGH); // 12 is red LED, no continuity

digitalWrite(11, LOW);  // 11 is green LED, continuity




becomes this?:



pinMode(12, INPUT_PULLUP); // 12 is red LED, no continuity
  pinMode(11, OUTPUT);  // 11 is green LED, continuity

no.
Those are the Arduino pins controlling the LEDs.
The Arduino pins we were referring to are pins that would be used on the cable wires instead of 5v.

I think you need to take a step back and think through the design and then figure out how you want to wire things up, including coming up with a real schematic, before you go in and start mucking with any code.

--- bill

bperrybap:
no.
Those are the Arduino pins controlling the LEDs.
The Arduino pins we were referring to are pins that would be used on the cable wires instead of 5v.

I think you need to take a step back and think through the design and then figure out how you want to wire things up, including coming up with a real schematic, before you go in and start mucking with any code.

--- bill

I have the design all figured out, I just don't understand these new coding terms. Besides, I can make a different copy of the code. So instead of using 5V you're saying to use the other pins on the arduino?

sbrown:
I have the design all figured out,

That may be, but you haven't ever fully described it and shared it with us.
My suspicion is that if you really had it "all figured out" you wouldn't be asking all these questions and wouldn't have blown up your Arduino boards.

I just don't understand these new coding terms. Besides, I can make a different copy of the code. So instead of using 5V you're saying to use the other pins on the arduino?

Not exactly.
You manipulate a pin on one end of the wire and watch for the change on a another pin on the other end of the wire.
That said, No pin is ever driving a 5v output signal like your direct connection to 5V.

In non coding terms, you want to create an open drain signal or "bus" on your wires.
You use the internal pullups on the AVR pins to create the high level signal on the wires and use a pin to drive the signal low.
You NEVER drive the signal high with a pin.

When done this way, the low output from the output pin on one end of the wire has to travel through the wire to ground the input pin on the other end of the wire in order for the input pin to see a low.
If the wire is broken, or the output pin is set to input mode, the input pin reads a high from its internal pullup.
And you never have to worry about a high level output shorting to a low level output since no pin ever creates a high level output.

In terms of Arduino:
setting an Arduino pin mode to INPUT_PULLUP sets the pin to input mode and turns on the internal pullup.
setting an Arduino pin to OUTPUT will set the pin to output mode - and if you have not ever written to the pin it will default to LOW.

--- bill