Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: RTC help on: March 21, 2012, 11:06:30 am
So i finally managed to work out how to set the time using the following code and the serial monitor input:-

Code:
/*
 * TimeSerial.pde
 * example code illustrating Time library set through serial port messages.
 *
 * Messages consist of the letter T followed by ten digit time (as seconds since Jan 1 1970)
 * you can send the text on the next line using Serial Monitor to set the clock to noon Jan 1 2010
 T1262347200 
 T1332509000 T13:23:20 23 3 2012
 T1332272300 19:38:20 20 3 2012
 *
 * A Processing example sketch to automatically send the messages is inclided in the download
 */
 
#include <Time.h> 

#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER  'T'   // Header tag for serial time sync message
#define TIME_REQUEST  7    // ASCII bell character requests a time sync message

void setup()  {
  Serial.begin(9600);
  setSyncProvider( requestSync);  //set function to call when sync required
  Serial.println("Waiting for sync message");
}

void loop(){   
  if(Serial.available() )
  {
    processSyncMessage();
  }
  if(timeStatus()!= timeNotSet)   
  {
    digitalWrite(13,timeStatus() == timeSet); // on if synced, off if needs refresh 
    digitalClockDisplay(); 
  }
  delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void processSyncMessage() {
  // if time sync available from serial port, update time and return true
  while(Serial.available() >=  TIME_MSG_LEN ){  // time message consists of a header and ten ascii digits
    char c = Serial.read() ;
    Serial.print(c); 
    if( c == TIME_HEADER ) {       
      time_t pctime = 0;
      for(int i=0; i < TIME_MSG_LEN -1; i++){   
        c = Serial.read();         
        if( c >= '0' && c <= '9'){   
          pctime = (10 * pctime) + (c - '0') ; // convert digits to a number   
        }
      }   
      setTime(pctime);   // Sync Arduino clock to the time received on the serial port
    } 
  }
}

time_t requestSync()
{
  Serial.print(TIME_REQUEST); 
  return 0; // the time will be sent later in response to serial mesg
}

The problem now is that the time goes tits......as shown below.....

19:43:16 20 3 2012
19:43:17 20 3 2012
19:43:18 20 3 2012
19:43:19 20 3 2012
7197:437:20 720 73 72012
7197:437:21 720 73 72012
7197:437:22 720 73 72012
7197:437:23 720 73 72012
7197:437:24 720 73 72012

After 5 mins or 300 seconds exactly! is there a problem with my dodgy ebay RTC? or am i missing something?

do i need to input the time in to memory or something?

Thanks

Dan
2  Using Arduino / Project Guidance / Re: RTC help on: March 20, 2012, 02:11:01 pm
using the following code i get this:-

Code:
/*
 * TimeRTCSet.pde
 * example code illustrating Time library with Real Time Clock.
 *
 * RTC clock is set in response to serial port time message
 * A Processing example sketch to set the time is inclided in the download
 */

#include <Time.h> 
#include <Wire.h> 
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t


void setup()  {
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet)
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");     
}

void loop()
{
  if(Serial.available())
  {
     time_t t = processSyncMessage();
     if(t >0)
     {
        RTC.set(t);   // set the RTC and the system time to the received value
        setTime(t);         
     }
  }
   digitalClockDisplay(); 
   delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

/*  code to process time sync messages from the serial port   */
#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER  'T'   // Header tag for serial time sync message

time_t processSyncMessage() {
  // return the time if a valid sync message is received on the serial port.
  while(Serial.available() >=  TIME_MSG_LEN ){  // time message consists of a header and ten ascii digits
    char c = Serial.read() ;
    Serial.print(c); 
    if( c == TIME_HEADER ) {       
      time_t pctime = 0;
      for(int i=0; i < TIME_MSG_LEN -1; i++){   
        c = Serial.read();         
        if( c >= '0' && c <= '9'){   
          pctime = (10 * pctime) + (c - '0') ; // convert digits to a number   
        }
      }   
      return pctime;
    } 
  }
  return 0;
}



17:23:02 20 8 2035
17:23:03 20 8 2035
17:23:04 20 8 2035
17:23:05 20 8 2035
17:23:06 20 8 2035
17:23:07 20 8 2035
17:23:08 20 8 2035
17:18:09 12 6 2041
17:18:10 12 6 2041
17:18:11 12 6 2041
17:18:12 12 6 2041
17:18:13 12 6 2041
17:18:14 12 6 2041
17:18:15 12 6 2041
17:18:16 12 6 2041
17:18:17 12 6 2041

It counts up in seconds with the wrong time and then resets for some reason?
3  Using Arduino / Project Guidance / Re: RTC help on: March 20, 2012, 01:21:09 pm
http://www.ebay.co.uk/itm/Arduino-Tiny-I2C-RTC-DS1307-AT24C32-Real-Time-Clock-module-board-AVR-ARM-PIC-/250913326552?pt=LH_DefaultDomain_0&hash=item3a6b9985d8
4  Using Arduino / Project Guidance / Re: RTC help on: March 20, 2012, 11:22:52 am
ok ill give the temp change a go, have removed the delay with no affect.

I have 3 other wires coming out of the RTC PCB, these are:-

 SQU
Ds
Batt

What is SQU and DS, and do i have to connect these three to the Arduino?

Thanks
5  Using Arduino / Project Guidance / Re: RTC help on: March 19, 2012, 04:32:47 pm
10 second delay was for the temperature control, i have a relay that cuts in if the temp gets below 25 degrees, if it is fluctuating between 25/24.9 the heater will cut in and out every second. i normally set this to a higher value.

How do i set the RTC up first?

I have tested the battery and it is fine.

RTC is plugged into comms pin 20/21 which are SDA/SCL. supply is from gnd and 3.3v on the arduino.
6  Using Arduino / Project Guidance / RTC help on: March 19, 2012, 03:01:26 pm
Im having problems with my RTC.

I have copied the code into my sketch and it compiles without any errors. but when the time displays on the serial monitor it goes from 17:18 - 17:20 and then back again. any ides what im doing wrong?

Code:
/*
  Digital out 38 is connected to a pump. If the temperature changes the pump stops.
  
    
  created 14 March. 2012
  modified ............
  by   
  This example code is in the public domain.
  
  */
 
// These constants won't change.  They're used to give names
 // to the pins used:
 #include <Time.h>  
 #include <Wire.h>  
 #include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t
 #include <math.h>
 #define ThermistorPIN 0  
 const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
 const int analogOutPin = 9; // Analog output pin that the LED is attached to
 const int OutPin = 38;

 int sensorValue = 0;        // value read from the pot
 int outputValue = 0;        // value output to the PWM (analog out)
 float vcc = 4.99;                       // only used for display purposes, if used
                                        // set to the measured Vcc.
float pad = 4703;                       // balance/pad resistor value, set this to
                                        // the measured resistance of your pad resistor
float thermr = 4400;                   // thermistor nominal resistance

float Thermistor(int RawADC) {
  long Resistance;  
  float Temp;  // Dual-Purpose variable to save space.

  Resistance=((1024 * pad / RawADC) - pad);
  Temp = log(Resistance); // Saving the Log(resistance) so not to calculate  it 4 times later
  Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
  Temp = Temp - 290.2;  // Convert Kelvin to Celsius                      
  
  // BEGIN- Remove these lines for the function not to display anything
  //Serial.print("ADC: ");
  //Serial.print(RawADC);
  //Serial.print("/1024");                           // Print out RAW ADC Number
  //Serial.print(", vcc: ");
  //Serial.print(vcc,2);
  //Serial.print(", pad: ");
  //Serial.print(pad/1000,3);
  //Serial.print(" Kohms, Volts: ");
  //Serial.print(((RawADC*vcc)/1024.0),3);  
 // Serial.print(", Resistance: ");
  //Serial.print(Resistance);
  //Serial.print(" ohms, ");
  
 
  // END- Remove these lines for the function not to display anything

  // Uncomment this line for the function to return Fahrenheit instead.
  //temp = (Temp * 9.0)/ 5.0 + 32.0;                  // Convert to Fahrenheit
  return Temp;                                      // Return the Temperature
}




void setup() {
  
   Serial.begin(9600);          // initialize serial communications at 9600 bps:
   setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet)
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");    
  

   pinMode(OutPin, OUTPUT);     // Set up the digital pin 7 to an OUTPUT
  
}
 


void loop() {
   // read the analog in value:
  // sensorValue = analogRead(analogInPin);            
   // map it to the range of the analog out:
  // outputValue = map(sensorValue, 0, 1023, 0, 255);  
   // change the analog out value:
  // analogWrite(analogOutPin, outputValue);          
 digitalClockDisplay();  
   delay(10000);
}
void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}
  void printDigits(int digits){
 
  Serial.print(":");  // utility function for digital clock display: prints preceding colon and leading 0
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);


float temp;
  temp=Thermistor(analogRead(ThermistorPIN));       // read ADC and  convert it to Celsius
 
  // print the results to the serial monitor:
  // Serial.print("sensor = " );                      
  // Serial.print(sensorValue);      
   Serial.print("\t output = ");      
   Serial.println(outputValue);  
   Serial.print("Celsius: ");
   Serial.print(temp,2);
 // if the analog value is high enough, turn heater off:
   if (temp > 25
   ) {
     digitalWrite( OutPin, LOW);
   }
  else {
     digitalWrite( OutPin,HIGH) ;
  }    
      if (temp > 25
   ) {
     digitalWrite( analogOutPin, 0);
   }
  else {
     digitalWrite( analogOutPin, 255) ;
}
  
  
  //temp = (temp * 9.0)/ 5.0 + 32.0;                  // converts to  Fahrenheit
  //Serial.print(", Fahrenheit: ");
  //Serial.print(temp,1);                             // display  Fahrenheit
  // wait 10 milliseconds before the next loop
   // for the analog-to-digital converter to settle
   // after the last reading:
   delay(10000);                    
}


Thanks

Dan
7  Using Arduino / Project Guidance / Re: Tinkerkit relay on: March 19, 2012, 02:09:16 pm
Also i am looking to drive up to 5 of these relay modules. will the 5v supply from the Arduino be ok? or should i use an external 5v supply?

Thanks

Dan
8  Using Arduino / Project Guidance / Re: Tinkerkit relay on: March 19, 2012, 02:07:34 pm
The middle pin on the Tinkerkit connector is the signal pin, that would hook up to the digital pin that you want to use on the Arduino.  The Tinkerkit relay is a module that has the necessary transistor for switching it, as well as status LED's.  Just hook the + and - pins up to 5V and ground, and the middle pin the digital output pin that you want to use.

Ok thanks, so i dont need to put a resistor in series with the digital output pin?
9  Using Arduino / Project Guidance / Tinkerkit relay on: March 16, 2012, 02:45:06 pm
Hi im fairly new to Arduino and im working on an aquarium controller project. At present i have made a temperature probe which appears to be reading quite accuratly. What i want to happen is this temperature probe to turn on and off the Heater. I have bought a tinkerkit relay (+5v switches to 240v) as i thought it would be easier to interface with the Arduino. which has the folling pins:-

-
+
middle pin which isnt labelled.

I have connected the 0 from my Arduino to -
and +5v from Arduino to +

My question is, can i connect the Digital output straight to the middle pin or do i need to go through a resistor?

I have checked the PDF files that i can find on the tinkerkit relay but they dont seem to provide and suggested circuits.

Thanks

Dan


10  Using Arduino / Installation & Troubleshooting / Re: is my board broken? on: March 08, 2012, 05:35:13 am
yeh sorry tried that, and neither rx/tx leds illuminated.

I decided it was the board so i have taken it back now. They didnt have any more in stock so i gotta wait for the new board to be delivered:(
11  Using Arduino / Installation & Troubleshooting / Re: Bad start to Arduino please help on: March 06, 2012, 01:15:53 pm
Had the same earlier, make sure you selected the correct board from the menu.
12  Community / Website and Forum / Re: Loop Back Test - Sticky? on: March 06, 2012, 11:02:26 am
I recently bought a Arduino Mega 2560.

Everything appeared to be working fine to start with, I managed to blink LED's and show temperature in the serial monitor etc.

The latest thing i have tried to do was to show text on an LCD. The Text was really dull even with the POT turned up and down.

Now when i connect my Arduino to the USB cable it does not show up in the Arduino software.

Mega 2560 is selected in the board options, but the port is blanked out, as if the pc cannot see the board.

I have tried different ports and the cable is brand new, and work to start with.

I have trioed pressing the Reset button which also does nto appear to work. I have tested the voltages on the power pins and they all seem fine. neither tx or rx LED illuminate but the power LED does.

PC does not see board during loop back test

Any ideas?

Thanks

Dan
13  Using Arduino / Installation & Troubleshooting / is my board broken? on: March 06, 2012, 10:49:58 am
I recently bought a Arduino Mega 2560.

Everything appeared to be working fine to start with, I managed to blink LED's and show temperature in the serial monitor etc.

The latest thing i have tried to do was to show text on an LCD. The Text was really dull even with the POT turned up and down.

Now when i connect my Arduino to the USB cable it does not show up in the Arduino software.

Mega 2560 is selected in the board options, but the port is blanked out, as if the pc cannot see the board.

I have tried different ports and the cable is brand new, and work to start with.

I have trioed pressing the Reset button which also does nto appear to work. I have tested the voltages on the power pins and they all seem fine. neither tx or rx LED illuminate but the power LED does.

Any ideas?

Thanks

Dan
14  Using Arduino / Installation & Troubleshooting / Re: LCD screen test on: March 06, 2012, 05:35:32 am
thats it  smiley-red
I had just worked that out:) it obviously resets to the default board each time?

thanks

Next problem is that the screen is very dull, maybe i need a smaller pot?
15  Using Arduino / Installation & Troubleshooting / LCD screen test on: March 06, 2012, 05:08:03 am
Hi im new to the arduino format and fairly new to coding.

I have connected up my Arduino MEGA 2560 to an LCD screen (http://www.aliexpress.com/store/600281/200598545-378126364/16x2-LCD.html) using the guide at http://arduino.cc/en/Tutorial/LiquidCrystalDisplay

i have used the following code:-

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}


And when this is uploaded it brings up the following error- avrdude: stk500_getsync(): not in sync: resp=0x00




Any ideas?

Thanks

Dan
Pages: [1]