Read Arduino darts matrix

Hello,

I have a 16x4 dart matrix. I connected an Arduino and the correct pins of the dart machine with the help of Flex-Wago terminals. Now I want to evaluate the signals on the Arudino board. This is my code:

int masterLines = 16; //Change here to the number of lines of your Master Layer
int slaveLines = 4; //Change here to the number of lines of your Slave Layer
int matrixMaster[] = {26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41}; //Put here the pins you connected the lines of your Master Layer
int matrixSlave[] = {22,23,24,25}; //Put here the pins you connected the lines of your Slave Layer
void setup() {     
    Serial.begin(9600);     
    Serial.println("OpenDarts"); //This line is not necessary, is just here for debug purposes
    for(int i = 0; i < slaveLines; i++){         
        pinMode(matrixSlave[i], INPUT_PULLUP);     
    }
   for(int i = 0; i < masterLines; i++){         
       pinMode(matrixMaster[i], OUTPUT);         
       digitalWrite(matrixMaster[i], HIGH);     
   }
}
void loop() {     
    for(int i = 0; i < masterLines; i++){         
        digitalWrite(matrixMaster[i], LOW);         
        for(int j = 0; j < slaveLines; j++){             
            if(digitalRead(matrixSlave[j]) == LOW){                 
                Serial.print(j);                 
                Serial.print(",");                 
                Serial.println(i);   
                delay(100);                 
                break;             
            }         
        }         
        digitalWrite(matrixMaster[i], HIGH);     
    }
}

My problem is that the ardunio sends signals back to the pins of the machine. He shouldn't. He should only receive.

Which signals are being send back? You define all 16 lines of the matrixMaster as OUTPUTS and set them HIGH so that would impact those lines.

If you are referring to your slave pins, those are being defined as INPUT_PULLUP so you are tying them to +5V through the internal pullup resistor which can also impact those lines.

FYI based on: OpenDarts

it constantly sends back any data. How can I force the slave pins to not send any data back?

Hubii93:
it constantly sends back any data. How can I force the slave pins to not send any data back?

The pins are not "sending" data you are reading the pins continuously in loop(). I assume this is what is required by the OpenDarts program on the PC.

ToddL1962:
The pins are not "sending" data you are reading the pins continuously in loop(). I assume this is what is required by the OpenDarts program on the PC.

For Example: I throw 3 times single 19. If i dont plug in my Arduino the dart machine counts 3x19.
If i plug in the arduino the dart machine gives me random results.

Hubii93:
For Example: I throw 3 times single 19. If i dont plug in my Arduino the dart machine counts 3x19.
If i plug in the arduino the dart machine gives me random results.

You have the dart machine and the Arduino connected at the same time?

ToddL1962:
You have the dart machine and the Arduino connected at the same time?

Yes. My goal is, that the arduino just recive the data and send it to my server.

Hubii93:
Yes. My goal is, that the arduino just recive the data and send it to my server.

If you are modifying an electronic dartboard for this purpose then you cannot have the dartboard's electronics and the Arduino hooked up at the same time. It can't work that way.

ToddL1962:
If you are modifying an electronic dartboard for this purpose then you cannot have the dartboard's electronics and the Arduino hooked up at the same time. It can't work that way.

So there is no workaround for this issue?

Hubii93:
So there is no workaround for this issue?

Look at how the Arduino loop() code works. Each pin of the Master is set to LOW followed by reading the input pins. Now imagine the original dartboard electronics doing the same thing at the same time. Those signals are fighting with each other. I'm not sure how you would solve that without some additional hardware and even then I don't know how to design that.

If you are just trying to sample the data, all your pins will need to be INPUT. IF the electronics are sampling data is a manner to how your arduino program is doing it, it is possible you could watch for a master line to go LOW and then read all the slave line values.

I'd start by seeing if you can reliably detect the time that all the master lines are going low. This will give you the frequency that the electronics are sampling the lines. You should be able to detect a pattern.

blh64:
If you are just trying to sample the data, all your pins will need to be INPUT. IF the electronics are sampling data is a manner to how your arduino program is doing it, it is possible you could watch for a master line to go LOW and then read all the slave line values.

I'd start by seeing if you can reliably detect the time that all the master lines are going low. This will give you the frequency that the electronics are sampling the lines. You should be able to detect a pattern.

Good idea blh64. Assuming the electronics are using the same voltage for IO. But that could be easily measured.

ToddL1962:
Good idea blh64. Assuming the electronics are using the same voltage for IO. But that could be easily measured.

Excellent point, Veriify you are tapping into a 5V system before you start. Even if it is a 3.3V system, it should still read HIGH on a 5V arduino. You also will need to make sure you connect the electronics ground to the arduino so they are at the same reference level (e.g. ground)

blh64:
Excellent point, Veriify you are tapping into a 5V system before you start. Even if it is a 3.3V system, it should still read HIGH on a 5V arduino. You also will need to make sure you connect the electronics ground to the arduino so they are at the same reference level (e.g. ground)

I would suspect it is 3.3V or 5V but you never know...and you don't want to damage your Arduino if it is higher.

int masterLines = 16; //Change here to the number of lines of your Master Layer
int slaveLines = 4; //Change here to the number of lines of your Slave Layer
const int matrixMaster[4] = { 22, 24, 49, 47 };
// Input Pins
const int matrixSlave[16] = { 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 53, 51 };
void setup() {     
    Serial.begin(9600);     
    Serial.println("OpenDarts"); //This line is not necessary, is just here for debug purposes
    for(int i = 0; i < slaveLines; i++){         
        pinMode(matrixSlave[i], INPUT_PULLUP);     
    }
   for(int i = 0; i < masterLines; i++){         
       pinMode(matrixMaster[i], INPUT);         
       digitalWrite(matrixMaster[i], HIGH);     
   } 
}
void loop() {     
    for(int i = 0; i < masterLines; i++){         
        digitalWrite(matrixMaster[i], LOW);         
        for(int j = 0; j < slaveLines; j++){             
            if(digitalRead(matrixSlave[j]) == LOW){                 
         
                delay(100);                 
                break;             
            }         
        }         
        digitalWrite(matrixMaster[i], HIGH);     
    } 
}

actually i dont recive any data. Additionally the arduino board still send some datas. Where is my fault ?

Hubii93:
actually i dont recive any data. Additionally the arduino board still send some datas. Where is my fault ?

If this is going to work you need to read all of the inputs. The code you have in loop() is still trying to write to the master inputs which doesn't make any sense now that they are inputs.

Perhaps this is a little above your head. You are going to have to read all of those lines to observe the behavior of the electronics in order to determine how to decode it IF this strategy even works. If it were me I would hook up the Arduino, configure the inputs but not even try to read them. Then, I would make sure the electronics still work as expected. If the electronics still works then I would read the inputs at say 100ms interval and see if I could decode it based on where a dart is. If you can then you have to make sure you send the data to Open Darts in a way that it expects.

This is a investigative and trial and error process. Did you confirm that the voltage is either 3.3 or 5V?

ToddL1962:
If this is going to work you need to read all of the inputs. The code you have in loop() is still trying to write to the master inputs which doesn't make any sense now that they are inputs.

Writing HIGH to an input is the old way of enabling the internal pullup resistor for the pin

pinmode( pin, INPUT );
digitalWrite( pin, HIGH );
// is the same as
pinmode( pin, INPUT_PULLUP);

so yes, you are affecting your signal lines.

You have any code examples, for solve this problem?
I asked many friends, but no one knew how to launch the matrix without interrupt the signal to the dart machine.

This will report how long each of your master lines goes low, in microseconds. That may give you an idea of how often the electronics read these lines. It may give you nothing. I don't know since I don't have a dart system.

By the way - why did you swap your Master and Slave lines compared to your original post?

const int masterLines = 16; //Change here to the number of lines of your Master Layer
const int slaveLines = 4; //Change here to the number of lines of your Slave Layer
const int matrixSlave[slaveLines] = { 22, 24, 49, 47 };
// Input Pins
const int matrixMaster[masterLines] = { 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 53, 51 };
void setup() {
  Serial.begin(9600);
  Serial.println("OpenDarts"); //This line is not necessary, is just here for debug purposes

  // all pins are input by default so this code is not needed
#if 0
  for (int i = 0; i < slaveLines; i++) {
    pinMode(matrixSlave[i], INPUT_PULLUP);
  }
  for (int i = 0; i < masterLines; i++) {
    pinMode(matrixMaster[i], INPUT);
    digitalWrite(matrixMaster[i], HIGH);
  }
#endif

}
unsigned long timing[masterLines];

void loop() {
  for (int i = 0; i < masterLines; i++) {
    timing[i] = measureTime(matrixMaster[i]);
  }

  Serial.println( "Timing measurements in microseconds" );
  for (int i = 0; i < masterLines; i++) {
    Serial.print( "Master line ");
    Serial.print( i );
    Serial.print( ": " );
    Serial.println( timing[i] );
  }
  while (1); // loop forever
}

unsigned long measureTime( int pin ) {

  const unsigned long timeout = 2 * 1000 * 1000UL;  // only wait 2 seconds, max
  unsigned long start = micros();
  // wait for pin to be high
  while( digitalRead(pin) == HIGH) {
    if( micros() - start >= timeout ) {
      return timeout;
    }
  }
  // pin has gone low, time how long it stays low
  start = micros();
  while( digitalRead(pin) == LOW) {
    if( micros() - start >= timeout ) {
      return timeout;
    }
  }
  return micros() - start;
}