ribbon cable tester and lights

hey so i’m new and have been working on this project for a while now. the gist is that when the cable is tested then if it passes a green led goes off if not a read one. i dont know what’s wrong with the code because i keep getting the same error code.

fixing_part_2.ino (2.94 KB)

error_code.ino (743 Bytes)

You have a function that has a return type of void. Clearly, you don't know what that means, because you try to return a value, and can't understand when the compiler tells you that a void function can NOT return a value.

The solution is dirt simple. Do not try to return a value from a function with a return type of void.

If the function is supposed to return a value, then get real and use the proper type for the function return type. Hint, it will NOT be void.

PaulS:
You have a function that has a return type of void. Clearly, you don’t know what that means, because you try to return a value, and can’t understand when the compiler tells you that a void function can NOT return a value.

The solution is dirt simple. Do not try to return a value from a function with a return type of void.

If the function is supposed to return a value, then get real and use the proper type for the function return type. Hint, it will NOT be void.

but when i do anything void setup() or void loop() everything breaks like if i try to take the void out then nothing will make any sense but if i leave them there it wont compile(i’ve tried so many things at this point i might just say oh well)

You really need to take a closer look at your code. Try to match up your braces. It would be a lot easier if the code was formatted nicely.

int led = 2;
int led1 = 7;
int buttonApin = 13;
bool testCable() 
  Setup();
  pinMode(led, OUTPUT);
  pinMode(led1, OUTPUT);

There seems to be a { missing between line 4 and line 5.

i fixed that the it goes to this and every testCable is defined and in working order. it worked perfectly brfore the leds

/tmp/ccqxRTwl.ltrans0.ltrans.o: In function `loop':

/tmp/207366453/sketch_jul24a/sketch_jul24a.ino:78: undefined reference to `testCable()'

collect2: error: ld returned 1 exit status

exit status 1

i fixed that the it goes to this and every testCable is defined and in working order. it worked perfectly brfore the leds

I have no idea what you meant to say there. I AM sure that you meant to post the revised code, but got in a hurry and missed doing so.

Take a deep breath, and try again. Take your time. We’ll be here all week.

What I think you want;

uint8_t outPins[] = {3, 4, 5, 6,};              // Output pins
uint8_t inpPins[] = {8, 9, 10, 11,};            // Input pins
//the button to start testing and to turn on the lights
int led = 2;
int led1 = 7;
int buttonApin = 13;

void  Setup()
{
  pinMode(led, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(buttonApin, INPUT_PULLUP);
  bool testResult = true;                         // Assume cable is good
  uint8_t count = 0;                              // Count of correct connections
}

bool testCable()
{
  if (sizeof(outPins) != sizeof(inpPins)) {

sorry im just kinda stressed

this is my revised code. there are new errors as well.

uint8_t outPins[] = {3, 4, 5, 6,};              // Output pins
uint8_t inpPins[] = {8, 9, 10, 11,};            // Input pins
# define testcable;
# define count;
int led = 2;
int led1 = 7;
int buttonApin = 13;

//the button to start testing and to turn on the lights
void setup()
{
  pinMode(led, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(buttonApin, INPUT_PULLUP);
  bool testResult = true;                         // Assume cable is good
  uint8_t count = 0;                              // Count of correct connections
}

bool testCable()
{
  if (sizeof(outPins) != sizeof(inpPins)) {      // Array sizes match?
    Serial.println(F("ERROR: Array Sizes Do Not Match."));
    return false;                                 // Exit now
  }

  for (uint8_t o = 0;  o < sizeof(outPins); o++) { // Loop though output pins
    Serial.print("Output Pin \t");
    Serial.print(o);
    Serial.print("[");
    Serial.print(outPins[o]);
    Serial.print("]\t");

    digitalWrite(outPins[o], HIGH);               // Set pin high
    if (digitalRead(inpPins[o]) == HIGH) {        // Is correct pin connected?
      count++;                                    // Increment count
      Serial.print("x");                          // Display it as first pin
      Serial.print(o);                            // Display it as first pin
      Serial.print("[");
      Serial.print(inpPins[o]);
      Serial.print("]");
    }

    for (uint8_t i = 0; i < sizeof(inpPins); i++) { // Scan input pins
      if (digitalRead(inpPins[i]) == HIGH) {      // If pin is high must be connected to output
        if (o != i) {                             // If array numbers don't match then must be error
          Serial.print(",\t");
          Serial.print(i);
          Serial.print("[");
          Serial.print(inpPins[i]);
          Serial.print("]");
          testResult = false;                     // Bad wire
        }
      }
    }
    digitalWrite(outPins[o], LOW);                // Set output back to low
    Serial.println();                             // New line ready for next pin
  }

  if (count != sizeof(outPins)) {                 // Have we had the correct number of correct pins?
    testResult = false;                           // If not then must be error
  };
  return testResult;
}





void loop() {


  Serial.begin(115200);
  Serial.println("Begin...");
  if (testCable() == true)
    Serial.println("Passed");
  else
    Serial.println("Failed");
  Serial.println("End.");



  if (digitalRead(buttonApin) == LOW)
  {

    for (uint8_t i = 0; i < sizeof(outPins); i++) { // Setup output pins
      pinMode(outPins[i], OUTPUT);
      digitalWrite(i, LOW);
    }
    for (uint8_t i = 0; i < sizeof(inpPins); i++) { // Setup input pins
      pinMode(inpPins[i], INPUT);                   // Turn off internap pullup resistor
    }

  }


  if (Serial.println("Passed"))
  {
    digitalWrite(led, HIGH);
  }
  else
  {
    digitalWrite(led, LOW);
  }
if (Serial.println("failed"))
  {
    digitalWrite(led1, HIGH);
  }
  else
  {
    digitalWrite(led, LOW);
  }
  



}

these are the new errors

./opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -hardware opt/arduino-builder/hardware -hardware ./opt/cores -tools opt/arduino-builder/tools -tools ./opt/tools -built-in-libraries opt/libraries/latest -logger humantags -fqbn arduino:avr:uno -build-cache /tmp -build-path /tmp/693527833/build -verbose -libraries /tmp/693527833/custom -libraries /tmp/693527833/pinned /tmp/693527833/sketch_jul24a

Compiling sketch...

/tmp/693527833/sketch_jul24a/sketch_jul24a.ino: In function 'void setup()':

/tmp/693527833/sketch_jul24a/sketch_jul24a.ino:16:17: error: expected primary-expression before '=' token

uint8_t count = 0; // Count of correct connections

^

/tmp/693527833/sketch_jul24a/sketch_jul24a.ino: In function 'bool testCable()':

/tmp/693527833/sketch_jul24a/sketch_jul24a.ino:35:14: error: expected primary-expression before ';' token

count++; // Increment count

^

/tmp/693527833/sketch_jul24a/sketch_jul24a.ino:51:11: error: 'testResult' was not declared in this scope

testResult = false; // Bad wire

^

/tmp/693527833/sketch_jul24a/sketch_jul24a.ino:4:15: error: expected primary-expression before ';' token

# define count;

^

/tmp/693527833/sketch_jul24a/sketch_jul24a.ino:59:7: note: in expansion of macro 'count'

if (count != sizeof(outPins)) { // Have we had the correct number of correct pins?

^

/tmp/693527833/sketch_jul24a/sketch_jul24a.ino:4:15: error: expected ')' before ';' token

# define count;

^

/tmp/693527833/sketch_jul24a/sketch_jul24a.ino:59:7: note: in expansion of macro 'count'

if (count != sizeof(outPins)) { // Have we had the correct number of correct pins?

^

/tmp/693527833/sketch_jul24a/sketch_jul24a.ino:59:13: error: expected primary-expression before '!=' token

if (count != sizeof(outPins)) { // Have we had the correct number of correct pins?

^

/tmp/693527833/sketch_jul24a/sketch_jul24a.ino:62:10: error: 'testResult' was not declared in this scope

return testResult;

^

exit status 1
# define testcable;
# define count;

If you do not understand what the #define statement does, DO NOT USE IT.

  bool testResult = true;                         // Assume cable is good
  uint8_t count = 0;                              // Count of correct connections

After the preprocessor is done, the compiler sees:

  bool testResult = true;                         // Assume cable is good
  uint8_t ; = 0;                              // Count of correct connections

Now, does that error message make sense?

      count++;                                    // Increment count

The compiler sees:

      ;++;                                    // Increment count

Makes no sense to me, either.

PaulS:

      count++;                                    // Increment count

The compiler sees:

      ;++;                                    // Increment count

Makes no sense to me, either.

so what your telling me is that the count is being substituted as a ;?

so what your telling me is that the count is being substituted as a ;?

Yes, because that is what the value is in the #define statement.

A #define statement has a name (count in your case) followed by a value (; in your case).

What did you intend for the #define statement to do?

For new programmers, preprocessor directives, except #include, are to be avoided.

oh ok. i wanted the count to count the pins but i fixed most of it i fixed most of the code but the LEDs are still messed up.

my code. now only the green LED is lit. like it wont even off.

uint8_t outPins[] = {3, 4, 5, 6, };              // Output pins
uint8_t inpPins[] = {8, 9,10,11,};              // Input pins
const int led1 = 12; // green led
const int led2 = 13; // red led 
void setup(){
  Serial.begin(115200);
  
  for (uint8_t i = 0; i < sizeof(outPins); i++){  // Setup output pins
    pinMode(outPins[i],OUTPUT);
    digitalWrite(i,LOW);
  }
  for (uint8_t i = 0; i < sizeof(inpPins); i++){  // Setup input pins
    pinMode(inpPins[i],INPUT);                    // Turn off internap pullup resistor
  }
  Serial.println("Begin...");
  if (testCable() == true)
  Serial.println("Passed");
  else 
  Serial.println("Failed");
  Serial.println("End.");
if (Serial.println("Passed"))
  {
    digitalWrite(led1, HIGH);
  }
  else
  {
    digitalWrite(led1, LOW);
  }
if (Serial.println("failed"))
  {
    digitalWrite(led2, HIGH);
  }
  else
  {
    digitalWrite(led2, LOW);
  }

}



bool testCable(){
  bool testResult = true;                         // Assume cable is good
  uint8_t count = 0;                              // Count of correct connections
  
  if (sizeof(outPins) != sizeof(inpPins)) {       // Array sizes match?
    Serial.println(F("ERROR: Array Sizes Do Not Match."));
    return false;                                 // Exit now
  }
  
  for (uint8_t o = 0;  o < sizeof(outPins); o++){ // Loop though output pins
    Serial.print("Output Pin \t");
    Serial.print(o);
    Serial.print("[");
    Serial.print(outPins[o]);
    Serial.print("]\t");
    
    digitalWrite(outPins[o],HIGH);                // Set pin high
    if (digitalRead(inpPins[o]) == HIGH){         // Is correct pin connected?
      count++;                                    // Increment count
      Serial.print("x");                          // Display it as first pin
      Serial.print(o);                            // Display it as first pin
      Serial.print("[");
      Serial.print(inpPins[o]);
      Serial.print("]");
    }
    
    for (uint8_t i = 0; i < sizeof(inpPins); i++){// Scan input pins
      if (digitalRead(inpPins[i]) == HIGH){       // If pin is high must be connected to output
        if (o != i){                              // If array numbers don't match then must be error
          Serial.print(",\t");
          Serial.print(i);
          Serial.print("[");
          Serial.print(inpPins[i]);
          Serial.print("]");
          testResult = false;                     // Bad wire
        }
      }
    }
    digitalWrite(outPins[o],LOW);                 // Set output back to low
    Serial.println();                             // New line ready for next pin
  }
  
  if (count != sizeof(outPins)){                  // Have we had the correct number of correct pins?
    testResult = false;                           // If not then must be error
  }
  return testResult;
}





void loop(){

}
    pinMode(inpPins[i],INPUT);    // Turn off internap pullup resistor

Why do you want to do that? Are you adding external pullup or pulldown resistors? If not, you will have floating pins if there is a cable break. That is NOT a problem you want to cause yourself.

if (Serial.println("Passed"))

The println() method returns the number of characters printed. I can't imagine why you want to use that number in an if statement.

if (Serial.println("failed"))

Ditto.

thanks yea i figured that the Serial.println(“Begin…”); was probly not going to work so i used the if (testCable() == true) to fix it. now everythng works

thanks

uint8_t outPins[] = {3, 4, 5, 6, };              // Output pins
uint8_t inpPins[] = {8, 9, 10, 11,};            // Input pins
const int led1 = 12; // green led
const int led2 = 13; // red led
const int button = 2;
int buttonState = 0;
void setup() {
  Serial.begin(115200);

  for (uint8_t i = 0; i < sizeof(outPins); i++) { // Setup output pins
    pinMode(button, INPUT);
    pinMode(outPins[i], OUTPUT);
    digitalWrite(i, LOW);
  }
  for (uint8_t i = 0; i < sizeof(inpPins); i++) { // Setup input pins
    pinMode(inpPins[i], INPUT);                   // Turn off internap pullup resistor
  }
  Serial.println("Begin...");
  if (testCable() == true)
    Serial.println("Passed");
  else
    Serial.println("Failed");
  Serial.println("End.");
  if ((testCable() == true))
  {
    digitalWrite(led1, HIGH);
  }
  else
  {
    digitalWrite(led1, LOW);
  }
  if ((testCable() != true))
  {
    digitalWrite(led2, HIGH);
  }
  else
  {
    digitalWrite(led2, LOW);
  }

}



bool testCable() {
  bool testResult = true;                         // Assume cable is good
  uint8_t count = 0;                              // Count of correct connections

  if (sizeof(outPins) != sizeof(inpPins)) {       // Array sizes match?
    Serial.println(F("ERROR: Array Sizes Do Not Match."));
    return false;                                 // Exit now
  }

  for (uint8_t o = 0;  o < sizeof(outPins); o++) { // Loop though output pins
    Serial.print("Output Pin \t");
    Serial.print(o);
    Serial.print("[");
    Serial.print(outPins[o]);
    Serial.print("]\t");

    digitalWrite(outPins[o], HIGH);               // Set pin high
    if (digitalRead(inpPins[o]) == HIGH) {        // Is correct pin connected?
      count++;                                    // Increment count
      Serial.print("x");                          // Display it as first pin
      Serial.print(o);                            // Display it as first pin
      Serial.print("[");
      Serial.print(inpPins[o]);
      Serial.print("]");
    }

    for (uint8_t i = 0; i < sizeof(inpPins); i++) { // Scan input pins
      if (digitalRead(inpPins[i]) == HIGH) {      // If pin is high must be connected to output
        if (o != i) {                             // If array numbers don't match then must be error
          Serial.print(",\t");
          Serial.print(i);
          Serial.print("[");
          Serial.print(inpPins[i]);
          Serial.print("]");
          testResult = false;                     // Bad wire
        }
      }
    }
    digitalWrite(outPins[o], LOW);                // Set output back to low
    Serial.println();                             // New line ready for next pin
  }

  if (count != sizeof(outPins)) {                 // Have we had the correct number of correct pins?
    testResult = false;                           // If not then must be error
  }
  return testResult;
}





void loop() {
 
}

so i used the if (testCable() == true) to fix it. now everythng works

You test each cable three times. Is that really necessary?

kinda yea. one is to make sure its connected one is continuity ten the last is shorts against other wires

ttkaigler:
kinda yea. one is to make sure its connected one is continuity ten the last is shorts against other wires

You do exactly the same thing each time you call testCable(), so it doesn't seem to make sense to call it three times.

  bool goodShit = testCable();
  if(goodShit)
  {
     Serial.println("The cable is connected");
  }

  if(goodShit)
  {
     Serial.println("There are no continuity errors");
  }

  if(goodShit)
  {
     Serial.println("There are no shorts; someone get that cable some pants");
  }

Of course, now you can see that three tests is silly.

  bool goodShit = testCable();
  if(goodShit)
  {
     Serial.println("The cable is connected");
     Serial.println("There are no continuity errors");
     Serial.println("There are no shorts; someone get that cable some pants");
  }