This is a cache of https://www.96boards.org/documentation/mezzanine/shiratech-fpga/guides/relay.md.html. It is a snapshot of the page at 2024-11-21T03:08:55.844+0000.
Interfacing with Relay Shield - 96Boards

Hardware

Hardware Requierments

HArdware Setup

  • Connect the Shiratech Mezzanine to the 96Boards CE Development Board
  • Connect the Relay shield on the FPGA Mezzanine’s Arduino Header

Software setup

#include #include

/* mraa header */ #include “mraa/i2c.h” #include “fpga_mezz.h”

int main() { /Initialise MRAA i2c/ mraa_result_t status = MRAA_SUCCESS; mraa_i2c_context i2c; mraa_init();

i2c = mraa_i2c_init(i2c_BUS);

/*Use i2c Bus0 for FPGA Mezzzanine*/
int input, ver;

if (i2c == NULL) {
    fprintf(stderr, "Failed to initialize i2c\n");
    mraa_deinit();
    return EXIT_FAILURE;
}

/* set slave address */
status = mraa_i2c_address(i2c, FPGA_MEZZI_ADDR);
if (status != MRAA_SUCCESS) {
}

/* Simple Test function to test the i2c Communication */
if(test(i2c)==0)
{
    printf("Test Passed\n");
}
else
{
  printf("Test Failed\n");
  return 1;
}

/* Check Firmware Revision of the FPGA Mezzanine */
ver = check_version(i2c);
if(ver == -1)
{
  printf("Version Check Error\n");
  return 1;
}
else
{
  printf("Version %d\n",&ver);
}

/* Set Pins 7,6,5 and 4 as output */
pinMode(7,OUTPUT,i2c);
pinMode(6,OUTPUT,i2c);
pinMode(5,OUTPUT,i2c);
pinMode(4,OUTPUT,i2c);


while(1)
{
    /* Sequentially toggle each relay on and off. */
    digitalWrite(7,LOW,i2c);
    sleep(1);
    digitalWrite(7,HIGH,i2c);
    sleep(1);
    digitalWrite(6,LOW,i2c);
    sleep(1);
    digitalWrite(6,HIGH,i2c);
    sleep(1);
    digitalWrite(5,LOW,i2c);
    sleep(1);
    digitalWrite(5,HIGH,i2c);
    sleep(1);
    digitalWrite(4,LOW,i2c);
    sleep(1);
    digitalWrite(4,HIGH,i2c);
    sleep(1);
} }

```

  • Compile using: gcc relay.c <path-to-fpga_mezz_lib>/src/fpga_mezz.c -o relay -I<path-to-fpga_mezz_lib>/include/
  • Run using: sudo ./relay
    • All four relays should turn on and off, one at a time.