# Connecting Arduino communicating in OPC to Ignition SCADA

**URL:** <https://forum.inductiveautomation.com/t/connecting-arduino-communicating-in-opc-to-ignition-scada/71761>\
**Category:** Ignition\
**Created:** [March 29, 2023, 10:01am UTC](https://forum.inductiveautomation.com/t/connecting-arduino-communicating-in-opc-to-ignition-scada/71761 "2023-03-29T10:01:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohamed\_AbdelGhaffar](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@Mohamed\_AbdelGhaffar](https://forum.inductiveautomation.com/u/Mohamed_AbdelGhaffar)\
**Post date:** [March 29, 2023, 10:01am UTC](https://forum.inductiveautomation.com/t/connecting-arduino-communicating-in-opc-to-ignition-scada/71761/1 "2023-03-29T10:01:16Z")

</div>

Has anyone tried to connect an Arduino to ignition scada through OPCDA ?  
Arduino is connected through a serial port and I have Arduino OPC server already installed and functioning as well as output parameters can be read by external sources OPC client/explorer applications.  
However, when I try to connect to the OPC server from the gateway (opc connections - opc da connection) it displays connecting and does not connect .  
Is there any further configurations that I should go through?  
Here is the code of the Arduino:

```auto
#include <OPC.h>

// declare opc object
OPCSerial aOPCSerial;

// declare pins that will be in use
int ledPin = 7;
int buttonPin = 2;
int analogPin = 0;
char ledState = 0;

// callback function
int callback1(const char *itemID, const opcOperation opcOP, const int value){

  static int ledValue = ledState;
    
  if (!strcmp(itemID,"led"))
  {
    // if a write
    if (opcOP == opc_opwrite) {
      /*ledValue = ledState;*/
      
      if (ledValue)  
        digitalWrite(ledPin, HIGH);
      else
        digitalWrite(ledPin, LOW);
    } 
    else 
      /*
       * read the led status
       */
      return ledValue;
  } 

  if (!strcmp(itemID,"button"))
  {    
    return digitalRead(buttonPin);  
  }

}

int callback2(const char *itemID, const opcOperation opcOP, const int value){
  
  if (!strcmp(itemID,"analog0"))
  {    
    return analogRead(analogPin);  
  } 
  
}

void setup() {

  Serial.begin(9600); // serial comms

  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, OUTPUT);

  aOPCSerial.setup(); // opc init
  
  // declare items
  aOPCSerial.addItem("led", opc_readwrite, opc_bool, callback1);
  aOPCSerial.addItem("button", opc_read, opc_bool, callback1);
  aOPCSerial.addItem("analog0",opc_read, opc_int, callback2);
  
}

void loop() {
  
  // Read the analog value from A0
  int analogValue = analogRead(analogPin);

  // If the analog value is less than 500, turn on the pump
  if (analogValue < 500) {
    digitalWrite(buttonPin, HIGH); // turn on the pump
    ledState = 1;
  } else {
    digitalWrite(buttonPin, LOW); // turn off the pump
    ledState = 0;
  }
 
  // start processing of opc commands
  aOPCSerial.processOPCCommands();
}

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 29, 2023, 10:24am UTC](https://forum.inductiveautomation.com/t/connecting-arduino-communicating-in-opc-to-ignition-scada/71761/2 "2023-03-29T10:24:00Z")

</div>

Please format the code.

- Hit the 🖉 edit button below your post.
- Select the code.
- Press the \</\> button on the editor toolbar. It's a formatting button so it works the same as the B or _I_ buttons. It will preserve indentation and apply syntax highlighting.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 29, 2023, 12:10pm UTC](https://forum.inductiveautomation.com/t/connecting-arduino-communicating-in-opc-to-ignition-scada/71761/3 "2023-03-29T12:10:57Z")

</div>

I assume you’re using [this library](https://github.com/ildemartinez/OPC)…

…which appears to be written by someone who has absolutely no idea what “OPC” is and has completely mis-used the term to describe some made up data sharing scheme he invented.

Try finding a Modbus library for Arduino instead?
