Need custom code for custom expansion

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

Re: Need custom code for custom expansion

Post by rimai »

Code: Select all

ReefAngel.PWM.SetChannel( 0, now()%3600<15?:100:0);
Roberto.
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Re: Need custom code for custom expansion

Post by AquaO »

it does not work,
when I try to uploaded I got this message.

expected `)' before ':' token

The following features were automatically added:
Watchdog Timer
Version Menu

The following features were detected:
Dimming Expansion Module
Dimming Signal
Custom Main Screen
Standard Menu
RA_OSAKA_test_ino.cpp: In function 'void loop()':
RA_OSAKA_test_ino:74: error: expected `)' before ':' token
RA_OSAKA_test_ino:75: error: expected `)' before ':' token
RA_OSAKA_test_ino:76: error: expected `)' before ':' token
RA_OSAKA_test_ino:77: error: expected `)' before ':' token


And I realized that I did not need the PWM signal in uno I need as digital signals to activate my relay board.
Like this testing code

Code: Select all

// Basic 4 Realy board connection
 
// Each relay is turned on for 2 seconds and then off.
 
// You can here them click as there state changes from off to on and on to
 
// off.
 
// You will also see the corresponding Red LED on the 4 Relay board 

// light up when the relay is on.
 
 
 
 //  define names for the 4 Digital pins On the Arduino 7,8,9,10
 
 //  These data pins link to 4 Relay board pins IN1, IN2, IN3, IN4
 
#define RELAY1  7                         

#define RELAY2  8                         

#define RELAY3  9
 
#define RELAY4  10
 
 
 
void setup()
 
{    
 
// Initialise the Arduino data pins for OUTPUT
 
  pinMode(RELAY1, OUTPUT);        

  pinMode(RELAY2, OUTPUT);
 
  pinMode(RELAY3, OUTPUT);
 
  pinMode(RELAY4, OUTPUT);
 
}
 
 
 
 void loop()
 
{
 
   digitalWrite(RELAY1,LOW);           // Turns ON Relays 1
 
   delay(2000);                                      // Wait 2 seconds
 
   digitalWrite(RELAY1,HIGH);          // Turns Relay Off
 
 
 
   digitalWrite(RELAY2,LOW);           // Turns ON Relays 2
 
   delay(2000);                                      // Wait 2 seconds
 
   digitalWrite(RELAY2,HIGH);          // Turns Relay Off
 
 
 
   digitalWrite(RELAY3,LOW);           // Turns ON Relays 3
 
   delay(2000);                                      // Wait 2 seconds
 
   digitalWrite(RELAY3,HIGH);          // Turns Relay Off
 
 
 
   digitalWrite(RELAY4,LOW);           // Turns ON Relays 4
 
   delay(2000);                                      // Wait 2 seconds
 
   digitalWrite(RELAY4,HIGH);          // Turns Relay Off        
 
 }
I try to change the code of the PWM module to change the analog signals into digital but without success. I change analogRead and analogWrite to digitalRead and digitalWrite.
Here is my attempt.

Code: Select all

#include <Wire.h>
#include <avr/wdt.h>

byte PWMports[] ={
  3,5,6,9,10,11};
byte ChannelValue[] = {
  0,0,0,0,0,0};

byte cmdnum=255;
byte datanum=255;
void setup()
{
  Serial.begin(57600);
  Wire.begin(8);
  Wire.onReceive(receiveEvent);
  randomSeed(digitalRead(0));
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  wdt_enable(WDTO_1S);
}

void loop()
{
  wdt_reset();
  //Serial.println(ChannelValue[0],DEC);
  if (cmdnum!=255)
  {
    ProcessCMD(cmdnum,datanum);    
    cmdnum=255;
    datanum=255;
  }
}

void receiveEvent(int howMany) {
  wdt_reset();
  if (howMany==5)
  {
    byte cmd1, cmd2, cmd3, cmd4, cmd5;
    cmd1=Wire.read();
    cmd2=Wire.read();
    cmd3=Wire.read();
    cmd4=Wire.read();
    cmd5=Wire.read();
    if (cmd1=='$' && cmd2=='$' && cmd3=='$')
    {
      cmdnum=cmd4;
      datanum=cmd5;
      //Serial.println(cmd4,DEC);
      //Serial.println(cmd5,DEC);
    }
  }
  else
  {
    for (int a=0;a<howMany;a++)
    {
      Wire.read();
    }
  }  
}

void ProcessCMD(byte cmd, byte data)
{
  wdt_reset();
  // Individual Channel
  if (cmd>=0 && cmd<=5)
  {
    ChannelValue[cmd]=data;
    digitalWrite(PWMports[cmd],data);
  }

  //Clouds
  if (cmd==6) 
  {
    //Serial.println(data,DEC);
    for (int b=0;b<7;b++)
    {
      if (b<6)
      {
        for (int a=ChannelValue[b];a>0;a--)
        {
          analogWrite(PWMports[b],a);
          wdt_reset();
          delay(data);
        }
      }
      if (b>0)
      {
        for (int a=0;a<ChannelValue[b-1];a++)
        {
          analogWrite(PWMports[b-1],a);
          wdt_reset();
          delay(data);
        }
      }
    }
  }

  //Thnderstorm
  if (cmd==7)
  {
    wdt_reset();
    for(int a=0;a<6;a++)
    {
      analogWrite(PWMports[a],255);
    }
    delay(30);
    for(int a=0;a<6;a++)
    {
      analogWrite(PWMports[a],0);
    }
    delay(10);
    analogWrite(PWMports[0],255);
    delay(100);
    analogWrite(PWMports[4],0);
    analogWrite(PWMports[3],0);
    delay(10);
    analogWrite(PWMports[0],0);
    analogWrite(PWMports[3],ChannelValue[3]);
    analogWrite(PWMports[1],0);
    delay(60);
    analogWrite(PWMports[3],0);
    delay(90);
    analogWrite(PWMports[4],ChannelValue[4]);
    analogWrite(PWMports[1],ChannelValue[1]);
    analogWrite(PWMports[2],0);
    wdt_reset();
    delay(100);
    analogWrite(PWMports[2],255);
    analogWrite(PWMports[5],255);
    analogWrite(PWMports[4],0);
    delay(30);
    analogWrite(PWMports[5],0);
    analogWrite(PWMports[0],255);
    wdt_reset();
    delay(300);
    analogWrite(PWMports[4],ChannelValue[4]);
    for(int a=0;a<6;a++)
    {
      analogWrite(PWMports[a],ChannelValue[a]);
    }

  }

  //Thnderstorm Random
  if (cmd==8)
  {
    for(int a=0;a<10;a++)
    {
      analogWrite(PWMports[random(6)],random(256));
      analogWrite(PWMports[random(6)],0);
      analogWrite(PWMports[random(6)],255);
      wdt_reset();
      delay(random(200));
    }
    delay(30);
    for(int a=0;a<6;a++)
    {
      analogWrite(PWMports[a],ChannelValue[a]);
    }
  }

}








I want to operate 4 dosing pump with the Uno and send the order to Uno with RA. In the future I want purchase the wifi module.

I think if you have the knowledge in programing thing is possible, but for me it's really complicated.

I think I'm going to take lessons on arduino language

thank you very much and I am so sorry for my weakness programing.
Eric
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
phrusher
Posts: 65
Joined: Fri May 25, 2012 12:22 am

Re: Need custom code for custom expansion

Post by phrusher »

rimai wrote:

Code: Select all

ReefAngel.PWM.SetChannel( 0, now()%3600<15?:100:0);
Minor typo. Try this:

Code: Select all

ReefAngel.PWM.SetChannel( 0, now()%3600<15?100:0);
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Re: Need custom code for custom expansion

Post by AquaO »

Yeah this code works in the Reef Angel and I see in the screen when the port it is opened and closed. But I think the Uno does not receive the order of ReefAngel, cause I have no signal on the UNO pin.

I wonder if I correctly connect the Uno to RA. I connect the Uno with Usb port of the relay box. Do I need to put a jumper on the UNO?

Thank you so much
Eric
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Need custom code for custom expansion

Post by rimai »

Oh no... You will need to hard wire and create your own cable.
The USB port of the relay box has I2C SDA and SCL signals.
If I remember correctly, Arduino uses A4 and A5 for SDA and SCL.
Goggle for connecting 2 arduinos as master/slave
Roberto.
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Re: Need custom code for custom expansion

Post by AquaO »

Ok now I understand why it does not work.

After my Google search I know how to connect the UNO for use I2C protocol with pins A4 and A5 for SDA and SCL.
But with the RA I dont know what pins it should be use.
Can I use the USB cable supplied with the RA and plug in to the relay box?
If I can use this cable, What is the color of which indicates the 5v, GN, SDA and SCL ?

Thank Eric
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Need custom code for custom expansion

Post by AquaO »

This is the cable
ImageUploadedByTapatalk1350953336.699684.jpg
ImageUploadedByTapatalk1350953336.699684.jpg (42.63 KiB) Viewed 5133 times
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Need custom code for custom expansion

Post by rimai »

no, you need to create your own cable.
Just buy a regular USB cable and strip it.
Google for USB pinout.
D- goes to A4
D+ goes to A5
Roberto.
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Re: Need custom code for custom expansion

Post by AquaO »

YES YES YES YES YES YES
:D :D :D :D :D :D :D

It works!

I had an old USB cable and 2k resistors that I used to make my own cable.

Thank you very much for your patience Roberto (I know I'm an idiot programing :oops: ) and for your help it was very appreciated.

You're very helpful

I love the Reef Angel
Thank
Eric

next step purchase and install wifi module :shock: :lol:
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Need custom code for custom expansion

Post by rimai »

Cool :)
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Need custom code for custom expansion

Post by DrewPalmer04 »

Let's see some pics of what you've accomplished AuqaO
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Re: Need custom code for custom expansion

Post by AquaO »

Yes I will post pictures later I need to fix some detail.

Thank you for your interest.

Eric
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Need custom code for custom expansion

Post by lnevo »

Yeah, very interested to see what you did with the dosing pumps... what pumps are you using.

I'm currently investigating how to dose, and not thrilled with the idea of wasting outlets (want to do triple channel) and having to waste all those relay ports. I like the standalone controllers like Bubble Magus, but sooo expensive. Considering the chinese knock-off Marine Magic which looks good, but I feel like it's such a waste having the RA that could do all that...

The RA dosing pump should connect to the PWM ports and have a PWM driver. If it was controllable like that or directlyw ithout the dimming module, I'd be snatching it up in a heartbeat. So very curious on the details here...

Edit: From the store-front, the previosly out-of-stock dosing pump looks like it's been replaced.. any details? It looks like the slave pump from another dosing pump i've seen...
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Need custom code for custom expansion

Post by DrewPalmer04 »

I have a triple magic dosing set up and to be honest it sucks. Every doser gives out different amounts. So you have to do some serious math for two part dosing. And they like to wear down and dose less and less and then you have to adjust the speed settings/recalculate again and the cycle repeats. Just FYI
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Need custom code for custom expansion

Post by AquaO »

Because a picture is worth a thousand words ;)

Do not forget is in progress.

Here is the dosing pump I use
(purchased on eBay)

Image
Image

Here is my DiY case

Image
Image
Image

And Video
http://youtu.be/oV4HXv71SxQ
Last edited by AquaO on Wed Oct 30, 2013 4:30 pm, edited 8 times in total.
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Need custom code for custom expansion

Post by rimai »

no pics :(
Roberto.
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Need custom code for custom expansion

Post by DrewPalmer04 »

Where'd you get the bare doser motor? 12v I'm assuming?
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Re: Need custom code for custom expansion

Post by AquaO »

I corrected the link of the pics, sorry

I bought the motor on ebay, I believe that it is the same as Profilux.
Yes they are 12v

I was also working to change the speed of the motor manually, for avoided programming all the time.
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Need custom code for custom expansion

Post by DrewPalmer04 »

So jealous...I need an Uno now...:(

Good DIY!!!
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Need custom code for custom expansion

Post by lnevo »

AquaO,

That is awesome! I just bought a few of those pumps, actually I bought the $30 ones that are already in an encosure with a potentiometer. I would love to convert it at some point to do what you did and control them individually with PWM instead of relays on my outlet strip...

Do you think you could do a more comprehensive post on what you did to setup the UNO? Do you know what would be needed if I wanted to just integrate with the RA Dimming module?

Thanks in advance and again awesome job!

Edit: Wow, the UNO is only $35... I'd gladly purchase one of these if I knew what to do with it!
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Need custom code for custom expansion

Post by rimai »

I'm also interested on seeing how you are powering the motors. Did you use a mosfet transistor?
Roberto.
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Need custom code for custom expansion

Post by AquaO »

rimai wrote:I'm also interested on seeing how you are powering the motors. Did you use a mosfet transistor?
No I use a NPN transistor TIP-122

Here is the wiring I did

Image

Image

Image

Image

Image

Thank you very much for your comment
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Need custom code for custom expansion

Post by AquaO »

For control motor speed with PWM you need:

1x NPN transistor TIP-122
1x Capacitor 1uf
1x Diode
1x Resistor 1k ohm

And the diagram

Image

Image

Image

Image

Image

For make your own USB cable for communication RA/Uno
You need:

1x Regular USB cable and strip it
2x Resistor 1.5k ohm

And the diagram

Image
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Need custom code for custom expansion

Post by AquaO »

Hi guys, I did some experiment for you. And the good news, you can use the dimming ports of Reef Angel to control the motor speed. You do not need an Arduino Uno. The Reef Angel and pwm expansion module is ready for this use.

Here the diagram

Image

Image

Image

Image

Image

And the video
http://youtu.be/Zo3RXFuEGlI

I think if would be great for an update of RA dosing pump ;)
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Need custom code for custom expansion

Post by lnevo »

There you go roberto! Wire that into the circuit for of the ra dosing pump add a switch for controlled or independent mode and done deal!!!
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Re: Need custom code for custom expansion

Post by AquaO »

I need your help, I'm not very good with the RA code.

I would like to know if it's possible to add to the menu PWM port and change the name in the menu?
Ex: instead of Ch 0, Ch 1, Ch 2 and Ch 3
I would like Alk, Ca, Mg and Carb and to modify the duration and %
Ex: Alk 15sec at 100% or Ca 20sec at 60%

Thank you in advance
Eric

This is my RA code

Code: Select all

#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 <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.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
    ReefAngel.AddStandardMenu();  // Add Standard Menu

    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port6Bit | Port7Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = 0;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = 0;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 869 );


    // Ports that are always on
    ReefAngel.Relay.On( Port1 );
    ReefAngel.Relay.On( Port2 );
    ReefAngel.Relay.On( Port3 );
    ReefAngel.Relay.On( Port4 );
    ReefAngel.Relay.On( Port5 );
    ReefAngel.Relay.On( Port6 );
    ReefAngel.Relay.On( Port7 );

    ////// Place additional initialization code below here
    

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

void loop()
{
    ReefAngel.DosingPumpRepeat( Port8,0,60,60 );
    ReefAngel.PWM.SetChannel( 0, now()%3600<15?80:0);
    ReefAngel.PWM.SetChannel( 1, now()%3600<25?50:0);
    ReefAngel.PWM.SetChannel( 2, now()%3600<35?95:0);
    ReefAngel.PWM.SetChannel( 3, now()%3600<10?100:0);

    ////// Place your custom code below here
    

    ////// Place your custom code above here

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

void DrawCustomMain()
{
    int x,y;
    char text[10];
    // Dimming Expansion
    x = 15;
    y = 2;
    for ( int a=0;a<6;a++ )
    {
      if ( a>2 ) x = 75;
      if ( a==3 ) y = 2;
      ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x,y,"Ch :" );
      ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+12,y,a );
      ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+24,y,ReefAngel.PWM.GetChannelValue(a) );
      y += 10;
    }
    pingSerial();

    // Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor( 15, 43, ReefAngel.Params,
    ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor( 15, 43, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
    pingSerial();

    // Main Relay Box
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox( 12, 84, TempRelay );
    pingSerial();

    // Date and Time
    ReefAngel.LCD.DrawDate( 6, 122 );
    pingSerial();
}

void DrawCustomGraph()
{
}
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Need custom code for custom expansion

Post by rimai »

I'm assuming you are talking about changing the main screen, right?
http://forum.reefangel.com/viewtopic.php?f=14&t=109
Roberto.
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Need custom code for custom expansion

Post by AquaO »

Yeah and change the value of PWM expansion, on ch0, ch1, ch2, ch3 directly on PDE.
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
AquaO
Posts: 61
Joined: Sun May 27, 2012 11:22 am

Need custom code for custom expansion

Post by AquaO »

rimai wrote:I'm assuming you are talking about changing the main screen, right?
http://forum.reefangel.com/viewtopic.php?f=14&t=109
thank you I'll try to make my own main screen and menu.
Image

Osaka 40g with 55g sump
Radion, 2X Tunze 6045, Swc-160 mini cone
Post Reply