So, after letting this thread sit for a couple days, here's my answer to everyone's frustration:
I'm not trying to be a thorn in your side or to this community. I was placed on this project after the 2 people "above" me decided to up-and-leave and I had no experience with this device to that point. I've never produced wiring diagrams before this, nor have I worked with electronics to this extent. My electronics experience has been, up to this point, capping and running ethernet wire for the company and the occasional light switch--that's it. I know what voltage, current and resistance are and few other basics, but beyond that, I'm a total greenhorn. I apologize for being difficult, I'm not trying to be.
You might be wondering "well, why did you accept this project" or "why aren't they finding someone else"? Here's the answer: money. The company I work for is not doing so hot right now (we've lost 30% of our workforce), so many of us here are wearing hats in fields of which we have little experience (i.e. IT is wiring electronics testers). The people who built this tester didn't leave any wiring schematics (don't ask me why, I'm not them) nor any real documentation except for a notebook with equations and the code I've been trying to decipher.
Some of you are getting frustrated with me because I'm ignoring advice or failing to provide the information you require to help me. Again, I apologize, I'm not doing it with spite or intention. It's actually a bad habit of mine. If I don't understand something fully, I ignore it. I do it without even realizing it. This is a flaw of mine, so I apologize for it. But, please don't call this thread a waste of time or not worth the effort. I have learned so much since we've started--it's just that, again, I am severely lacking in areas I don't even know where to start. Plus, even though we might have rehashed the same issue repeatedly, there will be others who encounter this issue and might find the solution to their issue.
But, onto specific replies...
I started with, what I believed, to be an accurate circuit diagram that pertained only to what I believed was relevant (i.e. I left out buttons, relays, and switches). But as we've progressed, I've implemented some changes without updating the diagram. I apologize for that. For reference, here's a picture of what I'm up against:
For example, the Arduino was originally powered with a secondary 7.5V @ 1A power supply that was independent of the 5.15V @ 10A power supply that powered the circuits. The only connections the two had were a single dupont wire that was connected into a GND pin on the Arduino and soldered to the ground rail of the circuits; and a common power strip at the base of the unit, but I'm not knowledgeable enough to know if that really counts. Many have said, though, that this is a poor idea, so I removed the 7.5V power supply and now have the entire unit running off the single 5.15V power supply.
I also left out the shield and the LEDs because I didn't have them hooked up during this thread and the issue still persisted. This is why I asked if there would be any complications to adding them back. For the record though, the shield and LEDs showed absolutely no issue with being powered off the 5V pin on the Mega before I took this apart. The 5V pin is measuring 4.98V after about a month of use for this unit with no issue. Regardless, I will be powering the LEDs directly through the 5.15V supply just to avoid any issues in the future.
#83 broke down why using floating point is a very poor decision, especially on embedded controllers like this. Again, I apologize for ignoring some advice related to this, but this reply makes total sense to me. Thank you for the explanation @GoForSmoke and to everyone else who suggested using ints wherever possible.
But, as an update on the current status, here is what I have:
I'll make a "proper" schematic the best I can and post it when I am finished. Everything will be included and nothing will be left out. In the meantime, #82 does have an accurate schematic related to the actual "testing" portion as far as I can tell.
I've updated the code to this:
const int ANALOG_REFERENCE = INTERNAL2V56;
const float VOLTAGE_REFERENCE = 2.56; // v; must match ANALOG_REFERENCE
const int KNOWN_RESISTANCE = 10;
const int POWER_SUPPLY_VOLTAGE_MV = 5150; // 5.15V power supply
const int N_READINGS = NUM_ANALOG_INPUTS; // should be 16 on the MEGA
const float V_SCALE = (VOLTAGE_REFERENCE * 1000 / 1024);
// Set the reference voltage
analogReference(ANALOG_REFERENCE);
// Get the voltage for each input and calculate the resistance
for (int i=0; i < N_READINGS; i++) {
uint8_t pin = A0 + i;
analogRead(pin); // Dummy read; allow the MUX to switch and settle
delay(10);
// Average the readings
int sum = 0;
for (int n=0; n < N_READINGS; n++) {
sum += analogRead(pin);
delay(10);
}
// Calculate the voltage
// Taken directly from http://www.skillbank.co.uk/arduino/readanalogvolts.ino
float mv = (sum + 0.5) * V_SCALE;
int voltage = mv / N_READINGS;
// Calculate the resistance from voltage (using ohms law)
float knownCurrentmO = (POWER_SUPPLY_VOLTAGE_MV - voltage) / KNOWN_RESISTANCE;
float resistance = voltage / knownCurrentmO; // Convert to ohms from milli-ohms/volts
Serial.println(resistance);
}
I've tried to follow the advice given here and follow the equations see in @johnerrington's website.
The results are better than they were before (6.4 - 7.1 ohms as compared to 5.9 - 6.7 when we started), but this improvement has been incremental as changes have been made in both hardware and software. Regardless, this is within the range I needed, so thank you to everyone for your persistent help with this problem of mine. I don't know if I will be able to get this much better since I still have yet to replace those thin wires (they're the ribbon cable in the picture above), so I'll just have to tune a small correction factor. I unfortunately don't have the time now to replace these wires as this unit is needed next week.
At any rate, further suggestions are always welcome and I will post that diagram later today or tomorrow. It just depends on how long it takes me to trace each wire.
