Coding Pwm module.

Do you have a question on how to do something.
Ask in here.
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Coding Pwm module.

Post by abhi_123 »

Hello Everyone.

which code should i use to make my pwm module to work.

i will be using 4 led drivers & two fans with parabola instead of slope with random cloud & lightning effect + moonlight phase on actinic channel on relay box.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

I vote for one thing at a time.
1st step is getting the base code from RAGen. Do you have that?
Roberto.
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

rimai wrote:I vote for one thing at a time.
1st step is getting the base code from RAGen. Do you have that?
here we go
// Autogenerated file by RAGen (v1.2.2.171), (05/04/2012 21:21)
// RA_050412_2121.ino
//
// This version designed for v0.9.0 or later

/* The following features are enabled for this File: 
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
#define PWMEXPANSION
*/


#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.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 <ReefAngel.h>

////// Place global variable code below here


////// Place global variable code above here


void setup()
{
    // This must be the first line
    ReefAngel.Init(); //Initialize controller

    // Ports that are always on
    ReefAngel.Relay.On(Port4);
    ReefAngel.Relay.On(Port7);
    ////// Place additional initialization code below here
    

    ////// Place additional initialization code above here
}

void loop()
{
    // Specific functions that use Internal Memory values
    ReefAngel.SingleATOLow(Port1);
    ReefAngel.StandardLights(Port2);
    ReefAngel.StandardLights(Port3);
    ReefAngel.Wavemaker1(Port5);
    ReefAngel.Wavemaker2(Port6);
    ReefAngel.StandardHeater(Port8);

    // PWMSlope based on Internal Memory values for Standard Lights
    ReefAngel.PWM.ActinicPWMSlope();
    ReefAngel.PWM.DaylightPWMSlope();
    ////// Place your custom code below here
    

    ////// Place your custom code above here
    // This sends all the data to the portal
    // Do not add any custom code that changes any relay status after this line
    // The only code after this line should be the ShowInterface function
    ReefAngel.Portal("abhi_123",);

    // This should always be the last line
    ReefAngel.ShowInterface();
}

Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

Ok, first thing we want to do is add the moonlight.
Replace this:

Code: Select all

    ReefAngel.PWM.ActinicPWMSlope();
With this:

Code: Select all

    ReefAngel.PWM.SetActinic(MoonPhase());
Roberto.
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

Done. now.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

Then, remove the daylight channel you are not using:

Code: Select all

    ReefAngel.PWM.DaylightPWMSlope();
Roberto.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

And add the code for the parabolas. Make sure to add them in the designated area for your custom code:

Code: Select all

    ReefAngel.PWM.SetChannel(0,PWMParabola(9,0,20,0,0,100,0)); 
    ReefAngel.PWM.SetChannel(1,PWMParabola(9,0,20,0,0,100,0)); 
    ReefAngel.PWM.SetChannel(2,PWMParabola(9,0,20,0,0,100,0)); 
    ReefAngel.PWM.SetChannel(3,PWMParabola(9,0,20,0,0,100,0)); 
Roberto.
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

updated.

now?
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

Is it working?
Roberto.
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

YES.
Image
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

// Autogenerated file by RAGen (v1.2.2.171), (05/04/2012 21:21)
// RA_050412_2121.ino
//
// This version designed for v0.9.0 or later

/* The following features are enabled for this File: 
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
#define PWMEXPANSION
*/


#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.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 <ReefAngel.h>

////// Place global variable code below here


////// Place global variable code above here


void setup()
{
    // This must be the first line
    ReefAngel.Init(); //Initialize controller

    // Ports that are always on
    ReefAngel.Relay.On(Port4);
    ReefAngel.Relay.On(Port7);
    ////// Place additional initialization code below here
    

    ////// Place additional initialization code above here
}

void loop()
{
    // Specific functions that use Internal Memory values
    ReefAngel.SingleATOLow(Port1);
    ReefAngel.StandardLights(Port2);
    ReefAngel.StandardLights(Port3);
    ReefAngel.Wavemaker1(Port5);
    ReefAngel.Wavemaker2(Port6);
    ReefAngel.StandardHeater(Port8);

    // PWMSlope based on Internal Memory values for Standard Lights
    ReefAngel.PWM.SetActinic(MoonPhase());
    ////// Place your custom code below here
    ReefAngel.PWM.SetChannel(0,PWMParabola(9,0,20,0,0,100,0));
    ReefAngel.PWM.SetChannel(1,PWMParabola(9,0,20,0,0,100,0));
    ReefAngel.PWM.SetChannel(2,PWMParabola(9,0,20,0,0,100,0));
    ReefAngel.PWM.SetChannel(3,PWMParabola(9,0,20,0,0,100,0));

    ////// Place your custom code above here
    // This sends all the data to the portal
    // Do not add any custom code that changes any relay status after this line
    // The only code after this line should be the ShowInterface function
    ReefAngel.Portal("abhi_123",);

    // This should always be the last line
    ReefAngel.ShowInterface();
}

Here is what i had uploaded. pwm expansion channel rating is still zero.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

So, we don't know if it is working, right?
I guess you will need to wait until tomorrow to test?
Roberto.
rufessor
Posts: 291
Joined: Tue Oct 25, 2011 7:39 am

Re: Coding Pwm module.

Post by rufessor »

I hate waiting for the sun to rise! :lol:

Seems like that's all I do lately!

Have fun-
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

An update. Pwm expansion module is working fine but have some issue with actinic moonphase it is still on 59% although it is 9:30am here with sun shinning high.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

Good.
From what time to what time do you want moonlights to be on?
Roberto.
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

Just opposite to my daylight schedule.j
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

Replace this:

Code: Select all

    ReefAngel.PWM.SetActinic(MoonPhase());
With this:

Code: Select all

    if (ReefAngel.Relay.Status(Port2)) ReefAngel.PWM.SetActinic(0); else ReefAngel.PWM.SetActinic(MoonPhase());
Roberto.
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

Alright. My standard light are assigned on relay 3 so i have to make it 3 instead of 2?

After that now comes the fan portion. I like to install pwm fans on channel 4& 5 to control the temp of my heat sink & tank respectively.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

For Fan, use this:

Code: Select all

  byte Fan1Speed;
  Fan1Speed=map(ReefAngel.Params.Temp[1],772,800,30,100); // Calculate Fan 1 speed
  Fan1Speed=constrain(Fan1Speed,0,100);
  ReefAngel.PWM.SetChannel(4,Fan1Speed);

  byte Fan2Speed;
  Fan2Speed=map(ReefAngel.Params.Temp[1],772,800,30,100); // Calculate Fan 2 speed
  Fan2Speed=constrain(Fan2Speed,0,100);
  ReefAngel.PWM.SetChannel(5,Fan2Speed);
You can change the temperatures and % on the map function.
I thought I had already posted this for you... :?:
Roberto.
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

Sorry Roberto i missed that post that's why i asked again.

All my code is working great. Now i want to add lightning , cloud & thunderstorm effect to my lights.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

Cool.
How are you with memory space?
Roberto.
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

rimai wrote:Cool.
How are you with memory space?
Upto now no issue.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

I mean, how much free space do you have?
Roberto.
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

How to check that?
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

Hit the checkmark icon to compile and it will show you.
Roberto.
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

31698 of 32256 bytes total.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

That's getting pretty close to full.
I don't think we'll be able to fit.
Roberto.
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

any modification in my existing code is possible to include the desired function?
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Pwm module.

Post by rimai »

If we hard code some of the settings and use a custom screen and custom menu, we will be able to squeeze it.
This would mean that you will loose the pH calibration on the menu and the graph on the main screen.
The other alternative is to modify the code in your PWM module itself and shift all the code for your lights to the module.
Take a look at these threads:
http://forum.reefangel.com/viewtopic.php?f=11&t=535
http://forum.reefangel.com/viewtopic.php?f=11&t=1069
http://forum.reefangel.com/viewtopic.php?f=11&t=923
Roberto.
abhi_123
Posts: 216
Joined: Tue Mar 20, 2012 8:34 am

Re: Coding Pwm module.

Post by abhi_123 »

this is what i have to include in my code to shift light setting to my module?


//Start of PWM Expansion Code Header

// This is just how we are going to reference the PWM expansion ports within the code.
// You can change the labels if you would like, just as long as they are changed all throughout the code too.
#define LEDPWM0 0
#define LEDPWM1 1
#define LEDPWM2 2
#define LEDPWM3 3
#define LEDPWM4 4
#define LEDPWM5 5

// Initial values to all 6 channels at startup. They will always be 0.
byte PWMChannel[]={
0,0,0,0,0,0};
//End of PWM Expansion Code Header
//*********************************************************************************************************************************
Image
Post Reply