Hi All,
I have moved on from the project guidance section. It's all about the code now, and this is my first project.
I have several digital inputs to an arduino micro, which then sends outputs over i2c to an i2c interface board connected to a board with 16 relays for outputs to various 12vdc solenoids.
My first problem was getting the library supplied by the interface board installed. I finally got that figured out, as far as I know, and have a library called Relay16 in the arduino library folder with the Relay16.cpp and Relay16.h files.
The manufacturer also supplied an example sketch that sequentially turns on each relay, then all on, then off in the loop.
Now, I can verify the example code and it finishes without errors.
If I try to upload to the micro, it errors out with "invalid library" and a path to where the sketch is.
I tried adding a copy of the Relay16 library folder to the example sketch folder, but that didn't help.
I can communicate with the micro just fine, it returns the board info just like it should.
Does the compiler use both the .h and .cpp files?
Does anyone see why this lib shouldn't run?
Here is the contents of the Relay.cpp file:
/*************************************************************************
Title: Iowa Scaled Engineering I2C-RELAY16 Driver Library
Authors: Nathan D. Holmes <maverick@drgw.net>
File: $Id: $
License: GNU General Public License v3
LICENSE:
Copyright (C) 2014 Nathan D. Holmes & Michael D. Petersen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
For more information about the Iowa Scaled Engineering I2C-RELAY16, see:
http://www.iascaled.com/store/I2C-RELAY16
*************************************************************************/
#include <stdlib.h>
#include <string.h>
#include "Arduino.h"
#include "Wire.h"
#include "Relay16.h"
Relay16::Relay16()
{
this->addr = 0;
this->relayBits = 0; // All relays off
this->dioReset = -1; // Unknown digital I/O for the reset line
}
void Relay16::refresh()
{
Wire.beginTransmission(this->addr);
Wire.write(~(this->relayBits & 0xFF));
Wire.write(~((this->relayBits >> 8) & 0xFF));
Wire.endTransmission();
}
void Relay16::allOff()
{
this->relayBits = 0;
refresh();
}
void Relay16::allOn()
{
this->relayBits = 0xFFFF;
refresh();
}
void Relay16::relayOn(byte relayNum)
{
if (relayNum < 1 || relayNum > 16)
return;
this->relayBits |= 1<<(relayNum-1);
refresh();
}
void Relay16::relayOff(byte relayNum)
{
if (relayNum < 1 || relayNum > 16)
return;
this->relayBits &= ~(1<<(relayNum-1));
refresh();
}
void Relay16::begin(boolean j5, boolean j6, boolean j7, char dioResetPin)
{
uint8_t addrBitmap = (j5?0x01:0x00) | (j6?0x02:0x00) | (j7?0x04:0x00);
this->addr = 0x20 | (addrBitmap);
// If there's a DIO pin assigned to reset, use it to do a hardware reset on initialization
if (-1 != dioResetPin)
{
pinMode(dioResetPin, OUTPUT);
digitalWrite(dioResetPin, LOW);
delayMicroseconds(100);
digitalWrite(dioResetPin, HIGH);
}
this->allOff();
}
And the example sketch:
/*************************************************************************
Title: Iowa Scaled Engineering I2C-RELAY16 Driver Library Example Sketch
Authors: Nathan D. Holmes <maverick@drgw.net>
File: $Id: $
License: GNU General Public License v3
LICENSE:
Copyright (C) 2014 Nathan D. Holmes & Michael D. Petersen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
For more information about the Iowa Scaled Engineering I2C-RELAY16, see:
http://www.iascaled.com/store/I2C-RELAY16
*************************************************************************/
#include <Wire.h>
#include <Relay16.h>
Relay16 relayBoard;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
Wire.begin();
// Both of the following initialization examples assume that address jumpers J5, J6, and J7
// on the I2C-RELAY16 are set to low (center pin is jumpered to the one away from the + sign on
// each jumper block). If they're set the other direction (center to + pin), replace "LOW" with "HIGH"
// If you're using a standard Iowa Scaled shield to connect the I2C lines to the Arduino,
// the /IORST line is likely tied to Digital IO line 4. Use the initializer below.
relayBoard.begin(LOW, LOW, LOW, 4);
// If the /IORST line on the I2C cable isn't connected anywhere, use this initializer
// instead of the one above.
// relayBoard.begin(LOW, LOW, LOW, -1);
}
void loop() {
// print the results to the serial monitor:
byte relayNum;
for (relayNum = 1; relayNum <= 16; relayNum++)
{
relayBoard.relayOn(relayNum);
delay(250);
relayBoard.relayOff(relayNum);
}
relayBoard.allOn();
delay(250);
relayBoard.allOff();
delay(250);
}
Thanks