Example #1
0
void setup() {

  // Init display
  mySerial.begin(9600); // set up serial port for 9600 baud
  delay(500); // wait for display to boot up
  


  // Setup DS1820 temp sensor

  sensors.begin();
  sensors.setResolution(Sensor1, 11);
  sensors.setResolution(Sensor2, 11);
  sensors.setWaitForConversion(false);
  sensors.requestTemperatures();
  delayInMillis = 750 / (1 << (12 - 11)); //750 for 12bit, 400 for 11bit, 220 for 10bit, 100 for 9bit
                        // calc by   delayInMillis = 750 / (1 << (12 - resolution)); 
  lastTempRequest = millis(); 


  // Set next state i FSM
  menu_FSM = M_PAGE1;
  menu_last_state = M_PAGE1;
  system_FSM = S_IDLE;
 
 
   // **************** Set up display *******************
  DisplayClear();
  MenuShowTime = millis();
 
  
  // **************** Set up RTC ***********************
  Wire.begin();
  rtc.begin();
  //TimeDate(rtc.now(),dateTimeString,1);

  //DateTime now = rtc.now();

 // write on display
  DisplayGoto(2,0);
  mySerial.print("Version 0.9B");

  
  // **************** Set up SD card *******************
  pinMode(10, OUTPUT);
  DisplayGoto(1,0);
  mySerial.write("Init SD -> "); // clear display + legends
 
  DisplayGoto(1,11);
  // see if the card is present and can be initialized:
  if (!SD.begin())
    mySerial.write("Fail");
  else
    mySerial.write("OK");
  delay(2000);
  
  // ***************** Clear display ********************
  DisplayClear();
   
  }
Example #2
0
Cron::Cron(TimedCommand *iTimedCommands, int iTimedCommandsSize) {
	timedCommands = iTimedCommands;
	timedCommandsSize = iTimedCommandsSize;

	Wire.begin();
    RTC.begin();
}
Example #3
0
void ClockTime::setup(){
    RTC.begin();   // begin clock
    if (! RTC.isrunning()) {
        Serial.println("RTC is NOT running!");
        // following line sets the RTC to the date & time this sketch was compiled
        RTC.adjust(DateTime(__DATE__, __TIME__));
    }
}
bool setRTC()
{
  Wire.begin();
  RTC.begin();
  // Sets RTC to the date & time sketch was compiled
  RTC.adjust(DateTime(__DATE__, __TIME__));
  return true;
}
Example #5
0
static int modbus_after_write_table(struct modbus_instance *instance, enum modbus_table table, uint16_t address, uint16_t count)
{
	if (table == MODBUS_TABLE_HOLDING_REGISTERS)
	{
		uint16_t offset = ELEMENT_OFFSET(common_values, now);
		if (ELEMENT_IN(0x0000, offset, address * 2, count * 2))
		{
			// SYNC CLOCK
			DateTime dt(common_values.now.year, common_values.now.month, common_values.now.day,
					common_values.now.hours, common_values.now.minutes, common_values.now.seconds);

			OS::TSysTimerLocker lock;
			RTC_DS1307 rtc;
			rtc.begin();
			rtc.adjust(dt);
		}

		offset = ELEMENT_OFFSET(common_values, modbus_address);
		if (ELEMENT_IN(0x0000, offset, address * 2, count * 2))
		{
			config_lock();
			config_set_address(common_values.modbus_address & 0xFF);
			config_unlock();

			// instance->address = common_values.modbus_address;
		}
	}
	
	if (table == MODBUS_TABLE_COILS)
	{
		uint16_t offset = ELEMENT_OFFSET(controls, restart_programs);
		if (ELEMENT_IN(0x0000, offset, address, count))
		{
			if (controls.restart_programs == 0x01)
			{
				controls.restart_programs = 0x00;
				controls.pause_flag = 0x00;
				
				program_reset();
				config_set_pause_flag(controls.pause_flag);
			}
		}

		offset = ELEMENT_OFFSET(controls, pause_flag);
		if (ELEMENT_IN(0x0000, offset, address, count))
		{
			config_set_pause_flag(controls.pause_flag);
		}
	}

	MODBUS_RETURN(instance, MODBUS_SUCCESS);
}
/*
 * @brief Helper function to get current time from RTC & Arduino.
 *
 * @return 0 on success, -1 on failure
 */
int _getCurrentTime( DateTime *now, unsigned long *curr_millis )
{
  // Try to get the current time from the RTC, if available. This will be prepended to the log file
  // to be used to convert relative timestamps to real time values.
  Wire.begin();
  RTC.begin();
  if (RTC.isrunning()) {
    *now = RTC.now();
    *curr_millis = millis();
    return 0;
  }
  return -1;
}
Example #7
0
// Init the RTC
void ClockMaster::initRTC(){
  //Wire.pins(2, 14); // SDA an SCL (comment on this, source is RTCLib::ds1307
  // Start RTC, print error if it's not found
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (!rtc.isrunning()) {
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    Serial.println("RTC time set to compile-date");
  }
}
Example #8
0
void setup () {
  Serial.begin(9600);

  Wire.begin();

  rtc.begin();

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    rtc.adjust(DateTime(2014,02,16,14,45,00));
    // following line sets the RTC to the date & time this sketch was compiled
    //rtc.adjust(DateTime(__DATE__, __TIME__));
  }
}
Example #9
0
void AgroShield::setDateTime(){
Wire.begin();
  RTC.begin();
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running...");
  }
  // This section grabs the current datetime and compares it to
  // the compilation time.  If necessary, the RTC is updated.
  DateTime now = RTC.now();
  DateTime compiled = DateTime(__DATE__, __TIME__);
  if (now.unixtime() < compiled.unixtime() || now.unixtime() > compiled.unixtime()) {
    Serial.println("RTC is older than compile time! Updating");
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }

  Serial.println("Setup complete.");
  delay(100);

}
 void setup () {
   strip_h.begin();
   strip_d.begin();
   strip_s.begin();
   strip_h.show();
   strip_d.show();
   strip_s.show();
   Serial.begin(57600);
   Wire.begin();
   RTC.begin();
   strip_h.setBrightness(100);
   strip_d.setBrightness(100);
   strip_s.setBrightness(100);
 
   // if (! RTC.isrunning()) {
   // Serial.println("RTC is NOT running!");
   // following line sets the RTC to the date & time this sketch was compiled
   //   RTC.adjust(DateTime(__DATE__, __TIME__));
 }
Example #11
0
/**
  If we declare an instance on the stack
  and put this into the constructor it will
  bug out, hence we need this init method.
*/
void Clock::Init(){
  if(!rtc.begin()){
    Serial.println("Could not find RTC");
  }
  startRtc();
}
Example #12
0
void setup()
{
	// debugging channel

	Serial1.begin(57600);
	while (!Serial1)
	{
	  delay(100);
	}

	Serial1.print( "RAM at setup " );
	Serial1.println( freeRam() );

	// ALRAM
	pinMode(ALARM_LED_PIN, OUTPUT);
	digitalWrite( ALARM_LED_PIN, LOW );

	// must "begin" the button to get proper pin assignment/muxing
	b.begin();

	// initializing ADC channels. The channels 0...7 are assigned to the
	// pins A0...A7. Note that the display and the config.txt files, as well as
	// the shield's silk layer use enumeration 1 to 8

	ADCs[0] = AdcChannel(A0);
	ADCs[1] = AdcChannel(A1);
	ADCs[2] = AdcChannel(A2);
	ADCs[3] = AdcChannel(A3);
	ADCs[4] = AdcChannel(A4);
	ADCs[5] = AdcChannel(A5);
	ADCs[6] = AdcChannel(A6);
	ADCs[7] = AdcChannel(A7);

	// initializing actuators. The Id is 0 to 7, a bit number in
	// actuator byte of the ADC channel. The mapping to the pin is
	// pin = A8 + Id

	Actuators[0] = Actuator(0, true);
	Actuators[1] = Actuator(1, true);
	Actuators[2] = Actuator(2, true);
	Actuators[3] = Actuator(3, true);
	Actuators[4] = Actuator(4, true);
	Actuators[5] = Actuator(5, true);
	Actuators[6] = Actuator(6, true);
	Actuators[7] = Actuator(7, false);		// the last actuator is not connected through ULN2003 but directly

	// The Real Time Clock

	rtc.begin();			// returns bool, but is never false

	Serial1.print( "RAM after rtc.begin " );
	Serial1.println( freeRam() );

	if(rtc.isrunning())
		Serial1.println("RTC is running");
	else
	{
		Serial1.println("RTC is NOT running");
		rtc.adjust(DateTime(__DATE__, __TIME__));		// setup the current date and time initially
	}

    DateTime now = rtc.now();

    Serial1.print(now.year(), DEC);
    Serial1.print('/');
    Serial1.print(now.month(), DEC);
    Serial1.print('/');
    Serial1.print(now.day(), DEC);
    Serial1.print(" (");
    Serial1.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial1.print(") ");
    Serial1.print(now.hour(), DEC);
    Serial1.print(':');
    Serial1.print(now.minute(), DEC);
    Serial1.print(':');
    Serial1.print(now.second(), DEC);
    Serial1.println();

	// activate LCD module
	lcd.begin (16,2); // for 16 x 2 LCD module
	lcd.setBacklightPin(3,POSITIVE);
	lcd.setBacklight(HIGH);

	Serial1.print( "RAM after lcd.begin " );
	Serial1.println( freeRam() );


	if(!Store.begin())
	{
		Serial1.println("Error initializing the storage");
		digitalWrite( ALARM_LED_PIN, HIGH );
	}
	Serial1.print( "RAM after Storage.begin " );
	Serial1.println( freeRam() );


	// the below makes sure the 1st active item is displayed upon start up. Otherwise
	// the item 0 is displayed, even if inactive
	Store.mIndex = CHANNEL_COUNT-1;
	Store.Advance();
}
Example #13
0
//RTC functions:
void OpenGardenClass::initRTC(void){
  Wire.begin();
  RTC.begin();
}
Example #14
0
void AgroShield::getDateTime(){
boolean run = true;
  Wire.begin();
  RTC.begin();
  if (! RTC.isrunning()) {
    Serial.print("RTC is NOT running  | ");
	run = false;
  }
  if(run){
  // This section grabs the current datetime and compares it to
  // the compilation time.  If necessary, the RTC is updated.
  DateTime now = RTC.now();
  DateTime compiled = DateTime(__DATE__, __TIME__);
  //if (now.unixtime() < compiled.unixtime() || now.unixtime() > compiled.unixtime()) {
  if (now.unixtime() < compiled.unixtime() ) {
    //Serial.println("RTC is older than compile time! Updating");
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }

  //Serial.println("Setup complete.");
  delay(100);
  
  
  // Get the current time
   now = RTC.now();   

  // Display the current time
  //Serial.print("Current time: ");
  if (now.day() <= 9)
  {
    Serial.print("0");
    Serial.print(now.day(), DEC);
  }
  else{
    Serial.print(now.day(), DEC);
  }
  Serial.print('/');
  if (now.month() <= 9)
  {
    Serial.print("0");
    Serial.print(now.month(), DEC);
  }
  else{
    Serial.print(now.month(), DEC);
  }
  Serial.print('/');
  Serial.print(now.year(), DEC);

  Serial.print(' ');

  if (now.hour() <= 9)
  {
    Serial.print("0");
    Serial.print(now.hour(), DEC);
  }
  else{
    Serial.print(now.hour(), DEC);
  }
  Serial.print(':');
  if (now.minute() <= 9)
  {
    Serial.print("0");
    Serial.print(now.minute(), DEC);
  }
  else{
    Serial.print(now.minute(), DEC);
  }
  Serial.print(':');
  if (now.second() <= 9)
  {
    Serial.print("0");
    Serial.print(now.second(), DEC);
	Serial.print(" | ");
  }
  else{
    Serial.print(now.second(), DEC);
	Serial.print(" | ");
  }

  delay(100);
  }
}
  void init() {
	  Wire.begin();
	  RTC.begin();
  }
Example #16
0
void setup(void)
{
	status.reset();

	/// Discrete & Analog IO
	pinMode(13, OUTPUT);	// Arduino on-board LED
	pinMode(A0, OUTPUT);	// Buzzer

	/// Comm. Channels
	// UART
	Serial.begin(115200); 	Serial.flush();
	Serial.println("Starting up greenOmatic Duemilanove Testbed...");
	Serial.print("Program compiled on ");
	Serial.print(__DATE__);
	Serial.print(" at ");
	Serial.println(__TIME__);
	Serial.println();

	// RF
#ifdef INTERFACE_ASK_RX
	pinMode(RF_RX_PIN, INPUT);
	vw_set_rx_pin(RF_RX_PIN);
    vw_setup(RF_BAUD);
    vw_rx_start  ();
	Serial.print  ("ASK RF Receiver configured on PIN ");
	Serial.print  (RF_RX_PIN);
	Serial.print  (" @ ");
	Serial.print  (RF_BAUD, DEC);
	Serial.println(" baud.");
#endif //INTERFACE_ASK_RX

	// Ethernet
#ifdef INTERFACE_ETHERNET
	Serial.print("Starting Ethernet... ");

#ifdef ETHERNET_DYNAMIC_IP
	int eth_stat = Ethernet.begin(mac);
	if (0 == eth_stat)
	{
		Serial.println(" Problem starting ethernet !");
		status.ethernet_valid = status.ERROR;
	}
	else
	{
		Serial.print("Ethernet started, IP = ");
		Serial.println( Ethernet.localIP() );
		status.ethernet_valid = status.VALID;
	}
#else
	Ethernet.begin(mac, IPaddr);
	Serial.print("Ethernet started, IP = ");
	Serial.println( Ethernet.localIP() );
	status.ethernet_valid = status.VALID;
#endif //ETHERNET_DYNAMIC_IP

#ifdef ETHERNET_WEBSERVER
		server.begin();
#endif //ETHERNET_WEBSERVER

#ifdef ETHERNET_UDPCLIENT
		Udp.begin(localPort);
#endif //ETHERNET_UDPCLIENT

#endif

	/// Peripherals
	// I2C RTC
#ifdef PERIPHERAL_RTCC
	Wire.begin();
	rtc.begin();
	if (rtc.isrunning())
	{
		status.time_valid = status.VALID;
		GetDatetimeString(rtc.now());
	    Serial.print("RTCC configured on I2C.  Time is currently ");
	    Serial.println(currentTime);

#ifdef ETHERNET_UDPCLIENT
		//TODO: Get NTP Time
#else
	    // Compare RTC time to this programs compile time
	    DateTime rtcTime = rtc.now();
	    DateTime compileTime(F(__DATE__), F(__TIME__));

	    // If the compile-time is later (more recent) than the current RTC time, update the RTC
	    if (compileTime.secondstime() > rtcTime.secondstime())
	    {
	    	Serial.println("Program compile-time is later than RTC time; updating RTC.");
	    	rtc.adjust( DateTime(F(__DATE__), F(__TIME__)) );
	    }
#endif //ETHERNET_UDPCLIENT
	}
	else
	{
		status.time_valid = status.ERROR;
		// TODO, can we narrow this down further like with the DS1307RTC library?
	}
#endif

	Serial.println("\nInitialization complete!\n\n");
}