Newbie questionnaire

New members questions
Post Reply
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Newbie questionnaire

Post 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
davaraj
Posts: 98
Joined: Sun Jul 21, 2013 8:18 am

Re: Newbie questionnaire

Post 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.
Image
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post 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.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post 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.
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post 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?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post 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.
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post 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?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post 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();
}
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post 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).
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post 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 :)
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post 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?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post by rimai »

You can copy the function and call it CustomExpansion1 and change the address to 0x42.
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post by joshlawless »

So use the custom code for both, instead of custom code for one and the library support for the other?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post by rimai »

Yeah, you could do that.
The library already supports the 0x41.
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post 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.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post 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));
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post 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.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post 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?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post 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 :)
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post 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")
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post by rimai »

Right on :)
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post 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.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post by rimai »

Not sure. Try it :)
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post by joshlawless »

Living dangerously! Will let you know what happens when I get it connected. :-)
Post Reply