Go Down

Topic: 64 yr old newby would like some help (Read 13786 times) previous topic - next topic

RayJorgensen

My parts haven't come yet but I've been working with Fritzing and learning quite a bit.  I've attached the file if someone can take a look.  I think I have most everything hooked up right.  The clock has one post I don't know where to connect. Don't worry about criticism this is my first venture into anything like this.

Second question:  Next I'll start on on coding. Where can I find a list of functions that are available.  My searches haven't yielded much. (wrong wording I'm sure)

Thanks

RayJorgensen

Hopefully this is the file.

terryking228

#32
Dec 08, 2017, 02:52 am Last Edit: Dec 08, 2017, 02:54 am by terryking228
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

RayJorgensen

Part are to be here Friday.  I'm like a kid a Christmas - can't wait.

I'm going to end up with 15 sensors at least.  8 of them will just be straight temp  sensors. So I've got test code for all diff sensors as separate sketches. I'll test one at a time.  How am I doing so far?

After all test out I'll hook all of them up and test.  If I pass then on to controlling with all of the "if statements". 

I see no reason to sample the senors more that every minute.  Can I put a delay ahead of the block that will control all of them?

The exception will be the soil moisture sensor, I'm thinking every 30 minutes is more than enough.  (Save the sensor).  How do I handle that?  Won't a delay statement cause the program to just sit at that spot?

All this data will be collected by an excel macro.  I hope to see "cause and effect" which will help tweek the values in the sensors or the control statements.

Thanks in advance!!!!!   I can't wait to get going!!

DrAzzy

I see no reason to sample the senors more that every minute.  Can I put a delay ahead of the block that will control all of them?

The exception will be the soil moisture sensor, I'm thinking every 30 minutes is more than enough.  (Save the sensor).  How do I handle that?  Won't a delay statement cause the program to just sit at that spot?

Yes, that's exactly what delay would do; that's why you shouldn't use delay for that sort of thing.

See this thread - this is one of the most common questions people have once they get over the basics with Arduino (really, it's one that basically everyone doing anything with Arduino soon runs into). The solution is to do the timing with millis() and check those times, rather than using blocking delays.  http://forum.arduino.cc/index.php?topic=223286.0

If you're ever making a delay longer than a few hundred milliseconds, you should stop and ask yourself if you should be using millis()
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

larryd

I like the enthusiasm you youngsters have!

If you want to schedule things to happen, this example shows some ways of doing so.

Code: [Select]

//Simple BWD BlinkWithoutDelay examples
//
//Timer variables used
unsigned long currentMillis;
unsigned long pin13Millis;
unsigned long pin12Millis;
unsigned long SwitchMillis;
 
//if these are not changed in the sketch, they can be const
unsigned long debounceMillis = 50UL;  //50ms
unsigned long ledOnTime      = 500UL; //500ms seconds
 
byte lastSwitchState = HIGH;
byte buttonState     = HIGH;
 
//enable/disable flags
boolean flag13 = true;
boolean flag12 = false;
 
const byte Switch = 2; //pushed = LOW
 
//**********************************************************************
 
void setup()
{
  Serial.begin(9600);
 
  digitalWrite(13,LOW);
  pinMode(13, OUTPUT);
 
  digitalWrite(12,LOW);
  pinMode(12, OUTPUT);
 
  pinMode(Switch, INPUT_PULLUP); //pushed = LOW
 
} //  >>>>>>>>>>>>>> E N D  O F  s e t u p ( ) <<<<<<<<<<<<<<<<<
 
void loop()
{
  //save the current time
  currentMillis = millis();
 
  //*************************************
  //Heartbeat LED
  //Toggle LED on and off. Helps show if there is blocking code
  if (flag13 == true && currentMillis - pin13Millis >= ledOnTime)
  {
    pin13Millis = millis();            //re-initialize Timer
    digitalWrite(13,!digitalRead(13)); //toggle LED condition
  }
 
  //*************************************
  if (flag12 == true && currentMillis - pin12Millis >= 5*1000UL)
  {
    //Turn off pin 12
    digitalWrite(12,LOW); //Turn off LED
    flag12 = false;       //disable timing
  }
 
//*************************************
//is it time to check the switches?
if (currentMillis - SwitchMillis >= debounceMillis)
{
//code here runs every debounceMillis ms
SwitchMillis = millis(); //re-initilize Timer
//go and check the switches
checkSwitches();   
}
 
  //*********************************
  //put other non-blocking stuff here
  //*********************************
 
} //  >>>>>>>>>>>>>> E N D  O F  l o o p ( ) <<<<<<<<<<<<<<<<<
 
 
//======================================================================
//                      F U N C T I O N S
//======================================================================
 
 
//****************** c h e c k S w i t c h e s ( ) *********************
//switches are checked every debounceValue milli seconds
//no minimum switch press time is validated with this code (i.e. No glitch filter)
void checkSwitches()
{
  //re-usable for all the switches
  boolean thisState;   
 
  //check if this switch has changed state
  thisState = digitalRead(Switch);
  if (thisState != lastSwitchState)
  {
    //update the switch state
    lastSwitchState = thisState;
 
    //this switch position has changed so do some stuff
    //"LOW condition code"
    //has switch gone from HIGH to LOW?
    if(thisState == LOW)                         
    {
      //Do some LOW switch stuff here
      flag12 = true;          //allow timing
      digitalWrite(12, HIGH); //turn on LED
      pin12Millis = millis(); //initialize Timer
    }
 
  } //END of Switch code
 
  //*****************************************
  // similar code for other switches goes here
  //*****************************************
 
} //END of checkSwitches()
 
//**********************************************************************
 
//======================================================================
//                      E N D  O F  C O D E
//======================================================================
     
No technical PMs.
The last thing you did is where you should start looking.

RayJorgensen

Thanks for the link and the sample code.  I'll take a while for me to understand, I'm sure!!

Parts just came - Chistmas early!!!!!!!!

justjohn

Thanks for the link and the sample code.  I'll take a while for me to understand, I'm sure!!

Parts just came - Chistmas early!!!!!!!!
Great to see this kind of enthusiasm and excitement over this kind of thing. :-)

RayJorgensen

I've got 2 sensors up and working.  I'm just started on a RTC and it works but I need to reset the time. The code to do this is as follows but I'm confused.  Any help will be appreciated!!

/*----( SET the date and time.  Comment OUT these lines after setting )----*/
  // Put these "//" in front of the line you do NOT want to use
  // following line sets the RTC to the date & time this sketch was compiled
     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  // This line sets the RTC with an explicit date & time, for example to set
  // May 21, 2015 at 6pm you would call: (use 24 hour time)
  //    rtc.adjust(DateTime(2015, 5, 21, 18, 0, 0));

Also, 2nd line from the bottom - it says "you would call" - in my past life - I would "call" a sub program. Can I do this in this platform?  It would greatly simplify the whole process if that is possible as I move forward.

Thanks in advance.

larryd

#39
Dec 17, 2017, 02:28 am Last Edit: Dec 17, 2017, 05:18 pm by larryd
rtc.adjust(DateTime(2015, 5, 21, 18, 0, 0));

The above line of code calls the rtc.adjust() function, similar to a subroutine.


.
No technical PMs.
The last thing you did is where you should start looking.

terryking228

Hi Ray,

Code: [Select]

  // This line sets the RTC with an explicit date & time, for example to set
  // May 21, 2015 at 6pm you would call: (use 24 hour time)
  //    rtc.adjust(DateTime(2015, 5, 21, 18, 0, 0));



Oh, my bad; I must have copied some of that from "The Internet".. :-(  

Invoking / executing / (Yes you're right we used to say "call" a subroutine (Now usually called a function).

So:

rtc.adjust(DateTime(<4-digit year>, <month>, <day>, <24-hour hour>, <minutes>, <seconds>);

.. is how this works.  

(This example is from this page):

http://arduino-info.wikispaces.com/DS1307_RealTime_Clock_Brick

I will update that example to be clearer.

Also it may not be clear: You would UPLOAD/RUN this sketch to SET the time.  THEN you would write your own code, or comment OUT those lines to come back and run this sketch later to check how the RTC is doing...

Glad to see you are exhibiting the primary Engineering skill: Persistence!
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

larryd

#41
Dec 17, 2017, 02:41 am Last Edit: Dec 17, 2017, 02:41 am by larryd
By the way, get into the habit of commenting your lines of code.
Reason, when you are 65, it will remind you what is happening.

Example:

  //To set the RTC time:
  //uncomment the third line down, as needed make changes to: SS,MM,HH,DD,DT,MM,YY  
  //upload this sketch, comment the line again, upload this sketch again!!!
  //DS3231         SS,MM,HH,DD,DT,MM,YY
  //setDS3231time (45,14,18, 1, 8, 5,16); //uncomment to set the RTC time


No technical PMs.
The last thing you did is where you should start looking.

larryd

No technical PMs.
The last thing you did is where you should start looking.

terryking228

Amazin' how some of Larry's lines creep into my code...


Just happened again...
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

larryd

No technical PMs.
The last thing you did is where you should start looking.

Go Up