Page 1 of 1

Newbie questionnaire

Posted: Sat May 02, 2015 9:35 pm
by joshlawless
It took much longer than I had hoped, but I have water in my tank and all my hardware installed. I'd like to get my RA+ programmed, but am pretty intimidated by everything I have to do. I'd like to break this process into bite-sized chunks, and would be grateful for some community input.

To start with, I'd like to understand how the syntax for a setup with a relay expansion works. Each relay box has two analog dimming channels -- I'd like my first coding project to be setting up the two Jebao return pumps and one Waveline circulation pump on three of these four dimming channels. Looking through all the example code, and walking through the Wizard-generated code, I can't figure out how to map these three pumps onto those dimming channels.

The Wizard lets me set up two of the pumps with code that looks like this:

Code: Select all

    ReefAngel.DCPump.UseMemory = false;
    ReefAngel.DCPump.SetMode( LongPulse,100,60 );
    ReefAngel.DCPump.DaylightChannel = Sync;
    ReefAngel.DCPump.ActinicChannel = AntiSync;
I assume "DaylightChannel" and "ActinicChannel" refer to the two dimming ports on the main relay (the one directly connected to the RA+. How do I get a DCPump function to control the circulation pump attached to one of the dimmers on the other relay box?


Also, what's the difference between DCPump Nutrient Export mode and Short pulse mode? They both take exactly the same format variables, and appear to be described in similar terms. Happy to have any insight on this one.

Thanks,

Josh

Re: Newbie questionnaire

Posted: Sat May 02, 2015 11:19 pm
by davaraj
Only the dimming ports on the first relay will work. The dimming ports on the 2nd relay will not work. You need a dimming module if you want to use any equipment to make use of the dimming functions.

Re: Newbie questionnaire

Posted: Sun May 03, 2015 8:19 am
by joshlawless
Thank you for the helpful answer! Guess I'll have to figure out how to connect pump #3 to one of my two 16-channel dimmer expansions. Hmmm.

Re: Newbie questionnaire

Posted: Sun May 03, 2015 9:13 am
by rimai
You could also use one of the ATO ports.
There is going to be a modification on the Jebao cable needed for either the ATO or 16ch dimming ports as they are 0-5V.

Re: Newbie questionnaire

Posted: Sun May 03, 2015 2:10 pm
by joshlawless
So, how about using the 16 channel PWM expansion board I have then (v1.1)?

The Wizard generates code for the regular 6-channel expansion board as

Code: Select all

ReefAngel.DCPump.ExpansionChannel[0] = Sync;
What would the correct syntax be for the 16-channel board (especially if I have two different 16-channel boards running?

Also, since Roberto made my 16-channel boards 0-5v PWM (for use with LDD drivers), what is the modification to the Jebao cable that I keep reading about?

Roberto -- there are six pairs of jumper pins on my 16-channel dimmer boards, with a jumper across the first pair. I'm not sure if these correspond to the 0-5 and 0-10v jumpers (and the PWM/analog) jumpers on the standard 6-channel board; is this jumper appropriately located for my intended use?

Re: Newbie questionnaire

Posted: Sun May 03, 2015 5:02 pm
by rimai
If you do that, I think you would loose the rest of the 10 channels.
You need to remove R2 from the Jebao cable to be able to use it with 0-5V.
The jumpers are for address changes. You must set them to different positions to be able to control them independently.
I can't remember now how I set them at the time, but if you use the I2CScanner code, I can tell you.
http://forum.reefangel.com/viewtopic.php?p=18831#p18831
The libraries are set to use these:
0x40 is the 6 channel
0x41 is the 16 channel
You can use 0x42 for your 2nd 16ch. Custom code is required to use it though. The libraries don't have support for 2 16ch modules.

Re: Newbie questionnaire

Posted: Sun May 03, 2015 6:19 pm
by joshlawless
Using the I2CScanner code, it looks like the dimmer with the jumper on JP1-1 is 0x41 and with the jumper on JP1-2 is 0x42.

Any hint on the syntax, for dimming from the 16 channel board, either with the built-in code or the custom code you emailed a (long) while back?

Re: Newbie questionnaire

Posted: Mon May 04, 2015 10:11 am
by rimai
This is what I use to test:

Code: Select all

#include <Salinity.h>
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <rtc_clock.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <Humidity.h>
#include <DCPump.h>
#include <ReefAngel.h>

void setup()
{
  ReefAngel.Init();    

}

void loop()
{
  for (int a=0;a<16;a++)
  {
    CustomExpansion(0x41,a,0);
  }
  CustomExpansion(0x41,now()%16,100);
  
  ReefAngel.ShowInterface();
}

void CustomExpansion(byte id, byte channel, byte percentage)
{
  Wire.beginTransmission(id);
  Wire.write(0);
  Wire.write(0xa1);
  Wire.endTransmission();
  int newdata=(int)(percentage*40.95);
  Wire.beginTransmission(id);
  Wire.write(0x8+(4*channel));
  Wire.write(newdata&0xff);
  Wire.write(newdata>>8);
  Wire.endTransmission();
}

Re: Newbie questionnaire

Posted: Mon May 04, 2015 12:36 pm
by joshlawless
Roberto,

Can you help me to better understand the code you've posted? I'll annotate it with what I think I get, and what stumps me.

for (int a=0;a<16;a++) // this iterates through all sixteen channels in turn
{
CustomExpansion(0x41,a,0); // this sends a 0% signal to each selected channel, ensuring that all 16 channels are off
}
CustomExpansion(0x41,now()%16,100); // now that all the channels have been turned off, this turns on one channel (based on the modulo 16) to 100%,

The effect of this loop() being to turn one channel on at a time, based on the now()%16 (every second, I would guess?)


The part I have a harder time parsing is the custom function:

void CustomExpansion(byte id, byte channel, byte percentage)
{
Wire.beginTransmission(id); // this begins a transmission on the 0x41 channel (the second 16-channel expansion)
Wire.write(0); // not sure what's happening here
Wire.write(0xa1); // or here -- what's the 0xa1? Is this initializing the communication with the device so it knows to expect subsequent communications in a format it is designed to parse
Wire.endTransmission();
int newdata=(int)(percentage*40.95); // this takes the percentage variable passed to the function and translates it to a 12bit integer
Wire.beginTransmission(id);
Wire.write(0x8+(4*channel)); // no idea whats happening here, guess I don't understand the Wire.write function. Sending the channel information to the expansion board in a format it understands? What's the 0x8 and why is channel multiplied by 4?
Wire.write(newdata&0xff); // I assume the 0xff that's appended indicates to the receiving device that the value is finished transmitting?
Wire.write(newdata>>8); // don't get this one at all. Why the bitwise shift? Does this shift by 8 places, essentially setting the newdata integer to 0?
Wire.endTransmission();
}

For my purposes, can I safely ignore the definition CustomExpansion() function, and simply focus my efforts on passing the correct variables to the function when called in the loop? It would seem so (the way I ignore what goes on in DCPump.h and just focus on understanding the variables).

Re: Newbie questionnaire

Posted: Mon May 04, 2015 2:55 pm
by rimai
Correct. Don't worry about what CustomExpansion() is doing. Focus on the use of it. You got exactly right what the test code is doing :)

Re: Newbie questionnaire

Posted: Mon May 04, 2015 4:00 pm
by joshlawless
Before I unhook everything to upload the test code, can I double check that the custom function should be using 0x42 instead of 0x41 (based on 0x41 being the primary 16-channel PWM, that should be operable via the standard code)?

Also, forgive my asking again, but what is the syntax for the first 16-channel PWM, if this CustomExpansion() function is what I need for the second 16-channel PWM?

Re: Newbie questionnaire

Posted: Mon May 04, 2015 5:00 pm
by rimai
You can copy the function and call it CustomExpansion1 and change the address to 0x42.

Re: Newbie questionnaire

Posted: Mon May 04, 2015 5:01 pm
by joshlawless
So use the custom code for both, instead of custom code for one and the library support for the other?

Re: Newbie questionnaire

Posted: Mon May 04, 2015 5:02 pm
by rimai
Yeah, you could do that.
The library already supports the 0x41.

Re: Newbie questionnaire

Posted: Mon May 04, 2015 5:04 pm
by joshlawless
Should I want to use the library version, what would the function name and syntax be?

And do I need to change the name of the function if I only include one copy in my code?

Sorry for all the serial questions.

Re: Newbie questionnaire

Posted: Mon May 04, 2015 5:11 pm
by rimai
You need to add this to setup to enable the feature:

Code: Select all

ReefAngel.Add16ChPWM();
Then you can use a function like:

Code: Select all

ReefAngel.PWM.Set16Channel(0,PWMSlope(9,0,20,0,15,100,60,15));

Re: Newbie questionnaire

Posted: Mon May 04, 2015 5:18 pm
by joshlawless
Thanks much! This is enough to get me started, but I have a feeling I'll want to replicate the Set16ChannelRaw functionality from RA_PWM.h eventually. Hopefully by the time I'm ready to try that, I'll understand how to do it without so much hand-holding.

Re: Newbie questionnaire

Posted: Mon May 04, 2015 8:32 pm
by joshlawless
On further consideration, is it necessary to have two copies of the named function? Since the CustomExpansion() function takes the address of the expansion board as its first variable (byte id), doesn't this mean I could simply pass 0x41 when I wanted to access the first expansion module, and 0x42 when I wanted to access the second?

Re: Newbie questionnaire

Posted: Mon May 04, 2015 8:36 pm
by rimai
Yes, that is the best solution :)
I just didn't want to confuse too much, but it seems you are on top of things :)

Re: Newbie questionnaire

Posted: Mon May 04, 2015 9:08 pm
by joshlawless
And if I wanted to rely on my custom function, I could change it up a bit:

Code: Select all

void CustomExpansion1(byte id, byte channel, int level)
{
  Wire.beginTransmission(id);
  Wire.write(0);
  Wire.write(0xa1);
  Wire.endTransmission();
  Wire.beginTransmission(id);
  Wire.write(0x8+(4*channel));
  Wire.write(level&0xff);
  Wire.write(level>>8);
  Wire.endTransmission();
}
To allow the function to accept a 12-bit integer, instead of a percentage. That way I could pass a high-definition value from one of the smooth slope functions, yes? (Assuming I haven't broken some variable naming rule with "level")

Re: Newbie questionnaire

Posted: Mon May 04, 2015 9:40 pm
by rimai
Right on :)

Re: Newbie questionnaire

Posted: Tue May 05, 2015 11:04 am
by joshlawless
Since I've taken out the line that maps the percentage byte onto a 12-bit number, do I still need to have lines four and five in my CustomExpansion function:

Code: Select all

  Wire.endTransmission();
  Wire.beginTransmission(id);
It seems like there's no need to end then immediately start the transmission, but I don't know the Wire functions at all.

Re: Newbie questionnaire

Posted: Tue May 05, 2015 11:11 am
by rimai
Not sure. Try it :)

Re: Newbie questionnaire

Posted: Tue May 05, 2015 11:12 am
by joshlawless
Living dangerously! Will let you know what happens when I get it connected. :-)