How to control GPIO for raspberry?

Forum Home Forums Rapid SCADA on Raspberry Pi How to control GPIO for raspberry?

This topic contains 9 replies, has 4 voices, and was last updated by Mikhail Mikhail 3 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #618

    jeffwoo
    Participant

    May i know how to control GPIO for raspberry? I have a small project, need to use raspberry as a human machine interface communicate with arduino thru modbus serial. arduino will capture the realworld signal and processing. And raspberry will use to key in parameter and display the result. This project will have data logger to store the data to USB storage on raspberry and export to excel file. Is that possible to be done in Rapid Scada? Please advice how to do it ? Thank you very much.

    #619
    Mikhail
    Mikhail
    Moderator

    Yes, your task can be solved by Rapid SCADA.
    Are you going to use GPIO of Arduino and use Raspberry as a server only?
    Or Raspberry also should work with its own GPIO?

    #620

    jeffwoo
    Participant

    Thank you very much for fast reply. Currently plan to use GPIO of arduino and Raspberry as server only. but is it possible to control raspberry GPIO as well?

    #621

    jeffwoo
    Participant

    May i know how to do it?

    #622
    Mikhail
    Mikhail
    Moderator

    You should develop a driver for SCADA-Communicator as describerd here.
    To access Raspberry GPIO look for a wrapper such as this one.

    #623
    Mikhail
    Mikhail
    Moderator

    I recommend to implement Modbus prorocol on your Arduino. In this case you can easily connect it to Rapid SCADA.

    #1498

    sarinda
    Participant

    Hi,
    Can you please tell me a Modbus library for Arduino which is compatible with RapidScada. I am having troubles with communicating with an arduino.

    I tried following code. It works with QMB (for modbus checking) but no data is received by rapidScada.

    #include <modbus.h>
    #include <modbusDevice.h>
    #include <modbusRegBank.h>
    #include <modbusSlave.h>
    
    /* PINS
    Add more registers if needed
    Digital input pins 2,3,4,5,6,7
    Digital output pins 8,9,12,13
    Analog output pins 10,11 (PWM)
    Analog input pins 0,1,2,3,4,5
    */
    
    modbusDevice regBank;
    modbusSlave slave;
    
    int AI0,AI1,AI2,AI3,AI4,AI5;
    
    void setup()
    {   
      regBank.setId(1); ///Set Slave ID
    
    //Add Digital Input registers
      regBank.add(10002);
      regBank.add(10003);
      regBank.add(10004);
      regBank.add(10005);
      regBank.add(10006);
      regBank.add(10007);
    // Add Digital Output registers
      regBank.add(8);
      regBank.add(9);
      regBank.add(12);
      regBank.add(13);
    //Analog input registers
      regBank.add(30001);
      regBank.add(30002);
      regBank.add(30003);
      regBank.add(30004);
      regBank.add(30005);
      regBank.add(30006);
    //Analog Output registers
      regBank.add(40010);  
      regBank.add(40011);  
    
      slave._device = &regBank;  
      slave.setBaud(9600);   
      
      pinMode(2,INPUT);
      pinMode(3,INPUT);
      pinMode(4,INPUT);
      pinMode(5,INPUT);
      pinMode(6,INPUT);
      pinMode(7,INPUT);
      pinMode(8,OUTPUT);
      pinMode(9,OUTPUT);
      pinMode(12,OUTPUT);
      pinMode(13,OUTPUT);
       
    }
    void loop(){
    
      while(1){   
      //Digital Input
        byte DI2 = digitalRead(2);
        if (DI2 >= 1)regBank.set(10002,1);
        if (DI2 <= 0)regBank.set(10002,0);
        byte DI3 = digitalRead(3);
        if (DI3 >= 1)regBank.set(10003,1);
        if (DI3 <= 0)regBank.set(10003,0);
        byte DI4 = digitalRead(4);
        if (DI4 >= 1)regBank.set(10004,1);
        if (DI4 <= 0)regBank.set(10004,0);
        byte DI5 = digitalRead(5);
        if (DI5 >= 1)regBank.set(10005,1);
        if (DI5 <= 0)regBank.set(10005,0);
        byte DI6 = digitalRead(6);
        if (DI6 >= 1)regBank.set(10006,1);
        if (DI6 <= 0)regBank.set(10006,0);
        byte DI7 = digitalRead(7);
        if (DI7 >= 1)regBank.set(10007,1);
        if (DI7 <= 0)regBank.set(10007,0);
                                    
      //Digital output
        int DO8 = regBank.get(8);
          if (DO8 <= 0 && digitalRead(8) == HIGH)digitalWrite(8,LOW);
          if (DO8 >= 1 && digitalRead(8) == LOW)digitalWrite(8,HIGH);
        int DO9 = regBank.get(9);
          if (DO9 <= 0 && digitalRead(9) == HIGH)digitalWrite(9,LOW);
          if (DO9 >= 1 && digitalRead(9) == LOW)digitalWrite(9,HIGH);
        int DO12 = regBank.get(12);
          if (DO12 <= 0 && digitalRead(12) == HIGH)digitalWrite(12,LOW);
          if (DO12 >= 1 && digitalRead(12) == LOW)digitalWrite(12,HIGH);
        int DO13 = regBank.get(13);
          if (DO13 <= 0 && digitalRead(13) == HIGH)digitalWrite(13,LOW);
          if (DO13 >= 1 && digitalRead(13) == LOW)digitalWrite(13,HIGH);
                
      //Analog input  ***READ Twice deliberately
        AI0 = analogRead(0);
        delay(10);
        AI0 = analogRead(0);
        regBank.set(30001, (word) AI0);
        delay(10);
        
        AI1 = analogRead(1);
        delay(10);
        AI1 = analogRead(1);
        regBank.set(30002, (word) AI1);
        delay(10);
        
        AI2 = analogRead(2);
        delay(10);
        AI2 = analogRead(2);
        regBank.set(30003, (word) AI2);
        delay(10);
        
        AI3 = analogRead(3);
        delay(10);
        AI3 = analogRead(3);
        regBank.set(30004, (word) AI3);
        delay(10);
        
        AI4 = analogRead(4);
        delay(10);
        AI4 = analogRead(4);
        regBank.set(30005, (word) AI4);
        delay(10);
        
        AI5 = analogRead(5);
        delay(10);
        AI5 = analogRead(5);
        regBank.set(30006, (word) AI5);
        delay(10);
            
      //Analog output 
        word AO10 = regBank.get(40010);
        analogWrite(10,AO10);
        delay(10);
        word AO11 = regBank.get(40011);
        analogWrite(11,AO11);
        delay(10);
            
      slave.run();  
      }
    }
    #1500
    Mikhail
    Mikhail
    Moderator

    Hi,

    This topic has another subject. Please create a new one. I can’t recommend you a library but I’ll try to help you to establish connection if you post communication line log.

    #2285

    manjey73
    Participant

    https://github.com/Manjey73/OpnenKPs/tree/master/KpRpi3 (readme – online translate)
    https://github.com/Manjey73/OpnenKPs/releases/tag/KpRpi3 (use gpio 5-27, in archive use all gpio)

    #2289
    Mikhail
    Mikhail
    Moderator

    Thanks a lot!
    A also recommend to post the above links with a description of a work to RPi forum, like this.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.