| Arduino Forum ::  Members :: dafes
 Show Posts Pages: [1] 2
 1 Topics / Home Automation and Networked Objects / Re: YATC - Yet Another Terrarium Controller on: February 07, 2013, 04:59:55 am Quote from: robtillaart on January 07, 2013, 01:39:55 pmQuoteI have two Terrariums so i need a Modular Controller to inependently Controll both.Why not two UNO's in stead of one MEGA?  Modular is modular Quote and simulate Sun Rising/ FallingI discussed an algorithm here - http://arduino.cc/forum/index.php/topic,66426.0.html - might be useful(you can also connect an LDR to the window and "read the local sunset/rise" Hi,i have read the Post and created a function according to this Post. the Location is Sydney (Because of UpsideDown i switched December with June to match the local Time.Lat:-33,52,0Long:-151,13,0Sunries @23 June = 7:00 = 60 * 7 + 0 =420Sunrise @23 dec = 4:42 = 60*4 + 42 = = 282average = (=420+282)/2 = 351delta = =420- 282= 138 => divide by 2 makes 69Sunset @23 Dec 7:06PM = 60 * 19 + 6 = 1146Sunset @23 June 4:54PM = 60*16 + 54 = 1014average = (1146+1014)/2 = 1080delta = 1146 - 1014= 132 => divide by 2 makes 66Code:void getRiseSet(){  float common = 69 * cos( ((month-1)*30.5+dayOfMonth + 8 ) * 0.017214206) ;  // replace division with faster multiplication  sunrise = 351 + common;  sunset = 1080 - common;    }
 2 Topics / Home Automation and Networked Objects / Re: YATC - Yet Another Terrarium Controller on: February 06, 2013, 04:40:50 pm Quote from: wildbill on January 29, 2013, 06:29:37 pmThese names are a clue that you can refactor: TemperatureControlT1, TemperatureControlT2. Consider making these a single function and pass the specific terrarium parameters, either as individual arguments or as a struct (or pointer to one) so that the same code can serve many terrarium instances. Alternatively, you could go full OO and just build a class that controls a terrarium - never thought I'd use that word so many times in a single post  Yes i thought about it. I thought also about a Struct Terrarium object with its Sensors. In the first step i want to build it as simple as possible to get the job done I have replaced the RTC with an GPS Clock and added some additional "timers"Code:long Seconds30Interval = 30000;  //30 Secons //Intervall in milisecondslong previous30SecondsMillis = 0;        // will store last time CheckForSomethingtoDo was runninglong Minute1Interval = 60000;  //1min //Intervall in milisecondslong previous1MinuteMillis = 0;        // will store last time CheckForSomethingtoDo was runninglong Minute5Interval = 300000;  //5min //Intervall in milisecondslong previous5MinuteMillis = 0;        // will store last time CheckForSomethingtoDo was runninglong Hour1Interval = 3600000;  //1hour //Intervall in milisecondslong previous1HourMillis = 0;        // will store last time CheckForSomethingtoDo was runningThis will give mne some freedom. At the moment i stuck at the Day Night things:I created a function which Adjusts the DayNightRhythm according the month:Code:void SetDayRhythm_T2(){  if(GPS.month == 0){    if(DEBUG) {Serial.println("Debug:SetDayRhythm_T2 GPS.month == 0");}    return;  }    if(DEBUG) {Serial.print("DEBUG: SetDayRhythm_T2 Month:");Serial.println(GPS.month,DEC); }    switch(GPS.month)  {    case 1:      T2_DayStart = 915; //09:15      T2_DayEnd = 2015; //20:15      T2_SpotStart = 140; //14:00      T2_SpotEnd = 200; //20:00    break;.............    case 12:      T2_DayStart = 100; //10:00      T2_DayEnd = 200; //20:15      T2_SpotStart = 1600; //16:00      T2_SpotEnd = 1700; //17:00    break;  }}This is a litle dirty but it does the job. In the 30seconds function i got an Verify if its time to Start/Stop a Lamp or SpotCode:void _CheckForSomethingtoDoTerrarium1_30Seconds(){  String time = String(GPS.hour)+=String(GPS.minute);  if(DEBUG) {Serial.println("Debug: _CheckForSomethingtoDoTerrarium1_30Seconds Time: ");Serial.println(time);  }    if(time == String(T2_DayStart))  {    if(DEBUG) {Serial.print("Debug: T2_DayStart Time: ");Serial.println(time);  }    return;  }  if(time == String(T2_DayEnd))  {    if(DEBUG) {Serial.println("Debug: T2_DayEnd Time: ");Serial.println(time); }    return;  }  if(time == String(T2_SpotStart))  {    if(DEBUG) {Serial.println("Debug: T2_SpotStart Time: ");Serial.println(time);  }    return;  }  if(time == String(T2_SpotEnd))  {    if(DEBUG) {Serial.println("Debug: T2_SpotEnd Time: ");Serial.println(time);  }    return;  }} Yes i use strings.. i will replace them a soon as possible this is just a habit from c#.Anyway has anybody a solution for a dynamic Terrarium struct which includes a "array" or "list" of sensors(a sensor is an 8 byte array)Code:byte sensor1[8] = { 0x10, 0xB2, 0xA0, 0x54, 0x2, 0x8, 0x0, 0x4E };How can i walk thorugh such a array of sensors?Edit: Is the String Problem still present? I have read some post that this was prior 1.0:http://code.google.com/p/arduino/issues/detail?id=468&q=string&sort=-idhttp://stackoverflow.com/questions/12930978/array-of-strings-char-array-in-c-arduino-how-do-i-accomplish-it
 3 Topics / Home Automation and Networked Objects / Re: YATC - Yet Another Terrarium Controller on: January 29, 2013, 02:37:05 pm Quote from: robtillaart on January 29, 2013, 01:36:28 pmKeep us informed of your progress!Sure Here is the loop Code:Code:void loop() {//Display if(SettingsScreen) { DisplaySettings(); } else { NormalView(); }  //Timing  unsigned long currentMillis = millis();    if(currentMillis - previousMillis > interval)   {    // save the last time you run the function     previousMillis = currentMillis;    CheckForSomethingtoDo();     }}and here is the "CheckForSomethingtoDo" function:Code:void CheckForSomethingtoDo(){  //DBEUG To Verify if Function runs  if(DEBUG) {Serial.println("DEBUG: CheckForSomethingtoDo"); }  _CheckForSomethingtoDoTerrarium1();  _CheckForSomethingtoDoTerrarium2();}void _CheckForSomethingtoDoTerrarium1(){  //Temperature  TemperatureControlT1();}void _CheckForSomethingtoDoTerrarium2(){  //Temperature  TemperatureControlT2();}//Snakesvoid TemperatureControlT1(){  DateTime now = RTC.now();  //Sommer  if(now.month() >= T1_SommerStart && now.month() <  T1_WinterStart)  {   if(DEBUG) { Serial.println("Debug: Sommer"); }   if(GetTemperature(sensor1) >= T1_TTS)   {       if(DEBUG) {Serial.print("Debug:T1 "); Serial.print(GetTemperature(sensor1)); Serial.println(" SwitchOff");}     SwitchOff(1, 1);   }   else   {     SwitchOn(1,1);   }     }  //Winter  else  {    if(DEBUG) { Serial.println("Debug: Winter"); }        if(GetTemperature(sensor1) >= T1_TTW)    {            if(DEBUG) {Serial.print("Debug:T1 "); Serial.print(GetTemperature(sensor1)); Serial.println(" SwitchOff");}      SwitchOff(1, 1);    }    else    {      SwitchOn(1,1);    }  }  }void TemperatureControlT2(){}In the main class i have the following "Configuration Section":Code://---------------------------------Configuration-------------------------------------------------const boolean DEBUG = true;//Terrarium 1 //Target Temperature Sommerconst int T1_TTS = 26;//Target Temperature Winterconst int T1_TTW = 26;//Sommerconst int T1_SommerStart = 5;//Winterconst int T1_WinterStart = 10;//Terrarium 2//---------------------------------End-Configuration---------------------------------------------In future i will configure this variables over a lcd and buttons and a config file on a sd card.
 4 Topics / Home Automation and Networked Objects / Re: YATC - Yet Another Terrarium Controller on: January 28, 2013, 04:26:41 pm Quote from: robtillaart on January 21, 2013, 03:26:11 pmQuoteString Name;Strong advice to remove the String usage form your sketch and replace it with a char array as the String class has "destructor" problems ..QuoteOr is it better to use a Timer based Interrupt?Don't use delay either => check the Blink without delay example how to schedule functionality in your codeThank you for the feedback. I wil avoid using String and try the millis thing. I have just finished the build up and everything is now connected. Now i can concentrate my time to programming a running beta.
 5 Topics / Home Automation and Networked Objects / Re: YATC - Yet Another Terrarium Controller on: January 21, 2013, 04:55:07 am Hello,On Hardware Side:i have rebuilded some Boards to replace Pin Headers with Connectors. I also ordered many Connectors to connect the additional Sensos to sthe Systems. I ordered some 3,5mm Audio Jacks to connect the sensors and 25m Shielded 4 lines Wire.On Software Side: I defined all IO Pins to match the Sensors and everything. At the moment i have only a small test setup to test all Boards and Sensors.In the next weeks i will write a small menu and the "scheduler". I think i will use 5m delay loop like:Code:void loop(){time = GetTime();switch(time){ case(12):  if(!Switch.Status(Terrarium1,Switch1)) {   Switch.On(Terrarium1,Switch1); } break;}delay(30000);}Or is it better to use a Timer based Interrupt?
 6 Topics / Home Automation and Networked Objects / Re: YATC - Yet Another Terrarium Controller on: January 21, 2013, 04:48:07 am Hi everybody,i rebuilded some Boards to be a litle more modular.I have created a new power board out of two pin connectors and changed the "normal" pin header to Connectors.I will post some pictures tonight. On Programming side there is not much progress. I have defined all Pins and at the moment i work on a small menu. I also try to find a good solution to switch the Lights timebased on and off.... I think i will create delay loop of 5 minutes in the main loop and call a function to verify if something to do on timer or temperature basis.Code:void loop{switch(Time){case "12:00": Light.On(T1.S2);break;}deleay(300000);}
 7 Topics / Home Automation and Networked Objects / Re: YATC - Yet Another Terrarium Controller on: January 10, 2013, 12:56:12 pm Quote from: robtillaart on January 10, 2013, 12:35:15 pmQuoteA big question at the moment is how to handle the 1Wire Sensor Adresses and assign them to the right Terrarium.your idea looks good but I see no code you have tried sofar ...Yes it is still pre Alpha But here is something:I created the following Object Code:/*Represents a Terrarium Object*/typedef struct{    String Name;    byte* Sensor;}Terrarium;Created an Array of itCode:const int NumTerrariums = 2;byte sensor1[8] = { 0x10, 0xB2, 0xA0, 0x54, 0x2, 0x8, 0x0, 0x4E };byte sensor2[8] = { 0x10, 0x3F, 0x7D, 0x54, 0x2, 0x8, 0x0, 0x5C };Terrarium Terrariums[NumTerrariums];Add initialize it with the following Data:Code:void updateTerrariums {  Terrariums[0].Name = "Terrarium1";  Terrariums[0].Sensor =&sensor1[0];  Terrariums[1].Name = "Terrarium2";  Terrariums[1].Sensor = &sensor2[0];}I use the sensor first in the following DS1820 libfunction:Code:float GetTemperature(byte sensor[8]){  //CRC Check  if (OneWire::crc8(sensor, 7) != sensor[7]) {      Serial.println("CRC is not valid!");      return 0;  }  // the first ROM byte indicates which chip  switch (sensor[0]) {    case 0x10:      //Serial.println("  Chip = DS18S20");  // or old DS1820      type_s = 1;      break;    case 0x28:      //Serial.println("  Chip = DS18B20");      type_s = 0;      break;    case 0x22:      //Serial.println("  Chip = DS1822");      type_s = 0;      break;    default:      Serial.println("Device is not a DS18x20 family device.");      return 0;  }   ds.reset();  ds.select(sensor);  ds.write(0x44,1);         // start conversion, with parasite power on at the end    delay(1000);     // maybe 750ms is enough, maybe not  // we might do a ds.depower() here, but the reset will take care of it.    present = ds.reset();  ds.select(sensor);      ds.write(0xBE);         // Read Scratchpad  //Serial.print("  Data = ");  //Serial.print(present,HEX);  //Serial.print(" ");  for ( i = 0; i < 9; i++) {           // we need 9 bytes    data[i] = ds.read();    //Serial.print(data[i], HEX);    //Serial.print(" ");  }  // convert the data to actual temperature  unsigned int raw = (data[1] << 8) | data[0];  if (type_s) {    raw = raw << 3; // 9 bit resolution default    if (data[7] == 0x10) {      // count remain gives full 12 bit resolution      raw = (raw & 0xFFF0) + 12 - data[6];    }  } else {    byte cfg = (data[4] & 0x60);    if (cfg == 0x00) raw = raw << 3;  // 9 bit resolution, 93.75 ms    else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms    else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms    // default is 12 bit resolution, 750 ms conversion time  }  celsius = (float)raw / 16.0;  return celsius;}But i think i missed something with the pointers... I come from the c# world so i dont know the point(er)...BTW: Look what i received from China And so nicely wrapped
 8 Topics / Home Automation and Networked Objects / Re: YATC - Yet Another Terrarium Controller on: January 10, 2013, 03:19:19 am Hello,today everything arrives and now i can start programming and soldering My Plan was to build up two additional Boards:- One Power Board to power the arduino and additional boards - One Sensor/LCD Board to connect everything with the ArduinoI will post Pictures when i´m finished. A big question at the moment is how to handle the 1Wire Sensor Adresses and assign them to the right Terrarium.My idea was to create an Terrarium Object(struct) and have a List of Byte[8] Sensors but i´ve got some problems with it...Has anybody another Idea?At the first start the Controller should ask how many Terrariums do you have and maybe then quide the user through the configuration process. All Settings will be saved on a SD Card since i´m a litle bit worry about the read/write cycle limits in eeprom.Feedback is desired...Kind Regardsdafes
 9 Topics / Home Automation and Networked Objects / Re: YATC - Yet Another Terrarium Controller on: January 08, 2013, 02:13:18 pm I have finished the button Pad to controll some basic settings... I´ve made it as small as possible so the bottom layer is a litle bit dirty soldered.
 10 Topics / Home Automation and Networked Objects / Re: YATC - Yet Another Terrarium Controller on: January 08, 2013, 01:43:25 pm Quote from: robtillaart on January 08, 2013, 01:34:44 pmQuoteYes thats true but one othe requirement was cheap as possiblecheap comes at a price ...Why not one uno, just count the number of lines you need to control. Note that the analog ports can be used as digital so an UNO has 19 IO lines You need input:- 1 line for all the DS18B20's- 2 lines water sensor- 2 lines moisture sensor- 2 I2C RTCoutput:- 4 SD card- 2 Serial- 3 lines for the relays (use a shift register!)-------16 lines so one UNO could do the jobYes thats right, but  i want a litle more space to expand. I have an 433MHZ Sender and some 433MHZ switches so maybe i expand the Board to controll Lights over this or i want to add some Wirelesse Solution to connect it to my Network.And just saw you forget the 5 Button pins Right, Left, Up, Down and my lovely select So i have to use 21 Lines and i beleive uno has only 17 ports because d0 and d1 are used for Serial Connection or do i miss something? Regarddafes
 11 Using Arduino / Displays / Re: LiquidCrystal_I2C Using LCD from Interrupt Function on: January 07, 2013, 04:28:31 pm At first thank you for your and detailed response This clears up some Questions.My first Idea was to create an Interrupt to call an Settings Dialog. This were an huge time consuming operation within an Interrupt. As i´m programming a Terrarium Controller i have no "space" for time consuming Operations blocking other Operations.So i think the solution over an Flag is good for this Problem. But now i´m a litle bit worry about my other Idea: I wanted to use Timer Interrupts to verify against a Table if something exist to switch. Like:Code:M D H Mi Command* * 08 00 Switch Light 1 on or should i use a waiting function in the "Main Loop" aswell? Like:Code:void loop(){VerifyIfSomethingToDo(currentTime);delay(1000);}RegardDafes
 12 Topics / Home Automation and Networked Objects / Re: YATC - Yet Another Terrarium Controller on: January 07, 2013, 04:16:54 pm Quote from: robtillaart on January 07, 2013, 01:39:55 pmQuoteI have two Terrariums so i need a Modular Controller to inependently Controll both.Why not two UNO's in stead of one MEGA?  Modular is modular Quote and simulate Sun Rising/ FallingI discussed an algorithm here - http://arduino.cc/forum/index.php/topic,66426.0.html - might be useful(you can also connect an LDR to the window and "read the local sunset/rise" Yes thats true but one othe requirement was cheap as possible Thanks for the Feedback i will take a look into the sunrise algorithm The next Part is the Programming Part... I want to use an SD Card to save the Settings and also to specify the "Switch Times" for each channel.(I updated the first Post with the new Hardware)Additional i want to implement the functionality to programm the Controller over a Serial Interface in Step 1 and in Step 2 i want to replace the Serial Interface with an Bluetooth mate to configure the Controller from an Device.Kind RegardsdafesEdit:I think i will add two additional Sensors. One Soil Moisture Sensor to verify if enough water in the watertank and one for the plant in the rainforest Terrarium. Has anybody a better idea for checking the water level in a Plastic Tank to prevent the pump for running dry? It should be cheap as possible The moisture sensor cost 5€.Edit2: I ordered a Watersensor to apply into the Watertank.
 13 Using Arduino / Displays / Re: LiquidCrystal_I2C Using LCD from Interrupt Function on: January 07, 2013, 10:34:39 am Quote from: floresta on January 07, 2013, 10:29:36 amQuoteIn my opinion it should be possible to write to the LCD within the interrupt ...It is possible to write to the LCD within the interrupt, just as it is also possible to drive 75 mph in a 55 mph speed zone.It is just something that you should not do since it 'interrupts' everything else that the processor is trying to do, such as keeping track of time.  When you interrupt the processor just long enough to set a flag it does not upset the timekeeping mechanism.  When you write to the LCD outside of the interrupt routine, a process that takes an enormous amount of time in the microprocessor world, the timekeeping mechanism can still function properly.Don Hello Don,ok that makes sense to me. So in my opinion setting a flag is a sulotion for my problem. dafes
 14 Using Arduino / Displays / Re: LiquidCrystal_I2C Using LCD from Interrupt Function on: January 07, 2013, 10:00:18 am Quote from: floresta on January 07, 2013, 09:18:37 amQuoteyes i want to display messages on an LCD from an Interrupt.You have to use the technique shown in the link you posted in reply #2.  You use the interrupt handler to set a 'flag' and you test the flag (and write to the LCD when required) outside of the interrupt handler.DonHello Don,yes thats the dirty solution. But why to use an interrupt to set an flag which i verify each run in the loop, i can also verify the state of the digital pin in the loop. In my opinion it should be possible to write to the LCD within the interrupt and it is an advantage of an interrupt to resolve the need of verify the pin state in the "main loop".Another question is it possible to write to an "normal connected" LCD within an Interrupt?Dafes
 15 Topics / Home Automation and Networked Objects / YATC - Yet Another Terrarium Controller on: January 07, 2013, 08:06:12 am Hi,I would like to start a small Terrarium Controll Project. I have two Terrariums so i need a Modular Controller to inependently Controll both.I need to switch several lamps, two heatlamps and one pump.The two heatlamps needs to be temperature controlled. In future i wanted to report the Temperature over Serial or Wifi to an Linux Device to create a Temperature Graph and simulate Sun Rising/ Falling by LED Lights and PWM.So lets start with the required Hardware i ordered so far Microcontroller:SparkFun Mega Pro 5V 41€Relays:Two Sainsmart 4-Channel 5V Relay Boards 8€ x 2 = 16€LCD:4 Line Normal LCD with I2C Adapter 21€Temperature SensorsSeveral DS1820 around 20€PowerSupply:At the Moment a Apple IPhone Power Adapter....Bits and pieces:Several Buttons and Resistors...MicroSD Card 7€SD/MICRO-SD Card Breakout Module 5€Two Seeedstudio Grove - Moisture Sensor 2x5€ = 10€Seeedstudio Grove - Watersensor 3€Adafruit Ultimate GPS 35€I will update this Topic with Code, Hardware Plans and Pictures. I hope anybody will find the information helpfull and or can give me suggestion to build a reliable and working solution.Kind RegardsDafes
 Pages: [1] 2