OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) OSPi 1.3 Relay Control

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #22769

    QMan
    Blocked

    Took a little trial-n-error, but I was able to create a simple program to turn the new relay on/off that is part of OSPi 1.3.
    Wanted to share, but also wanted to ensure this is the right snippet to control it within a C program. Sometimes ‘works’ is not always ‘right’…

    #include 
    #include
    #include

    main() {
    int duration=1; /*leave relay on 1 minute */
    wiringPiSetupGpio ();
    pinMode (15, OUTPUT) ;
    digitalWrite (15, HIGH);
    delay((unsigned int) duration*1000*60);
    digitalWrite(15,LOW);
    exit(0);
    }
    #26095

    Ray
    Keymaster

    Looks correct to me. Now, there are some differences between wiringPi’s pin numbers vs. the BCM GPIO numbers:
    https://projects.drogon.net/raspberry-pi/wiringpi/pins/
    on OSPi 1.3, the rain sensor is connected to the TXD pin (the 4th pin on the right column of P1), and relay is RXD pin (the 5th pin), depending on whether you are referencing wiringPi’s pin number or BCM GPIO numbers, it could be either 15 or 16.

    #26096

    QMan
    Blocked

    Thanks Ray for the link on the wiring diagram and confirming my code. I wasn’t sure which was the preferred function to initialize since wiringPi had three (wiringPiSetup, wiringPiSetupGpio, wiringPiSetupSys) but the first one I tried worked so I ran with it. Also, it was easy to solder a couple jumper wires to the board to use the relay’s output. That was clearly marked on the board. Nice touch having the +5V power and ground breakouts on the board conveniently located an inch away too. Just waiting for the snow to melt now!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) OSPi 1.3 Relay Control