Problem displaying time via SPI


hi all, first post hope appropriate area.

i new c programming build environment controller. have bought arduino micro started.

the setup having trouble @ moment sparkfun dt1307 rtc module , 16x2 lcd fitted adafruit backpack works in spi mode i'm afraid (adafruit sending replacement) have had lcd correctly displaying temperature tmp36 cannot rtc , running.

i noticed rtclib include black in ide installed in user libraries only.

the lcd wired spi in adafruit tutorial: http://learn.adafruit.com/i2c-spi-lcd-backpack/connect-to-spi

the dt1307 wired in bildr tutorial: http://bildr.org/2011/03/ds1307-arduino/

the code below compiles, uploads, lcd blinks , turns off -

code: [select]
#include <liquidcrystal.h>
#include <wire.h>
#include <rtclib.h>

rtc_ds1307 rtc;
liquidcrystal lcd(3, 2, 4);

void setup() {
 serial.begin(9600);
 wire.begin();
 rtc.begin();  
 lcd.begin(16, 2);
 lcd.print("lcd started..");
 //lcd.noautoscroll();

 if (! rtc.isrunning()) {
   serial.println("rtc not running!");
   // following line sets rtc date & time sketch compiled
   rtc.adjust(datetime(__date__, __time__));
 }
 
 delay(2000);
}

void loop() {
 datetime = rtc.now();    
 lcd.clear();
 lcd.setcursor(0,0);
 lcd.print("testing..");
 lcd.setcursor(0,1);
 lcd.print(now.month(), dec);
 lcd.print("/");
 lcd.print(now.day(), dec);
 lcd.print("/");  
 lcd.print(now.year(), dec);
 lcd.print(" ");
 lcd.print(now.hour(), dec);
 lcd.print(":");
 lcd.print(now.minute(), dec);
 delay(1000);
}



this working code displays tmp36 correctly - integrate working rtc code.

code: [select]

// example of displaying temperature on lcd.
// temp sensor tmp36.
// tmp36 --- arduino --- lcd.
// mhlab
// 5/2012
//
// references
// http://arduino.cc/en/tutorial/liquidcrystal
// http://www.ladyada.net/learn/sensors/tmp36.html

#include <liquidcrystal.h>
#include <wire.h>

#define aref_voltage 3.30 // set aref ~3.3v

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


// connect via spi. data pin #3, clock #2 , latch #4
liquidcrystal lcd(3, 2, 4);

// variables control reading time interval , average reading:
int index = 0; // index of current reading
int readings = 0; // readings analog input
unsigned long total = 0; // sum of total readings
float average = 0.0; // average of readings
float temp1 = 0.0; // temp oc of sensor 1

unsigned long time1 = 0; // timing 1
unsigned long time2 = 0; // timing 2

// constants won't change
const int numreadings = 1000; // sampling numbers analog readings
const unsigned long timeinterval = 1000; // setting interval of output

// pin numbers asignment tmp36 sensors
int inputpin1 = a1; // read voltage of sensor tmp36

void setup()
{
  analogreference(external); // set aref other 5v
  // set lcd's number of columns , rows:
  lcd.begin(16, 2);
  // print message lcd starting @ [0,0]
    lcd.setcursor(1, 0);      // move cursor our second line

  lcd.print("temp:");
}

void loop() {
  // time millis()
  time1 = millis();

  // reading average adc of sensor 1
  average = averagetempad(inputpin1);
  // convert adc , convert celsius
  temp1 = temperaturesensortmp35(average);

  // print out lcd
  // set cursor column 0, line 1
  // (note: line 1 second row, since counting begins 0):
  lcd.setcursor(7, 0);
  // print number of seconds since reset:
  lcd.print(temp1);
  lcd.print(char(223));
  lcd.print("c");
  //lcd.print("/");

  // print out lcd (of)
  // set cursor column 8, line 1
  //lcd.setcursor(8, 1);
  //lcd.print(temp1*9/5+32.0);
  //lcd.print(char(223));
  //lcd.print("f");

  // controll data output timing: using millis()
  while(time1 + timeinterval > millis()){
    // nothing
  }
}

// average temp function
float averagetempad(int pinnumber){
  int aveadc;
  while (index < numreadings){
    readings = analogread(pinnumber);
    // add reading total:
    total= total + readings;
    // advance next position in array:
    index = index + 1;
  }

  // average ad number of temp
  aveadc = total / numreadings;

  // ...reset, wrap around beginning:
  index = 0;
  total = 0;

  return aveadc;
}

// --- convert digit number temp oc ---
// tmp35 temperature sensor calculation
// rawadc (10bit = 1024) temp (oc)
// schematic:
// [arduino] -- {tmp35}
// [vcc (5 or 3.3v)] -- {pin#1}
// [a1] -- {pin#2}
// [ground] -- {pin#3}
// converting 10 mv per degree wit 500 mv offset
// degrees ((volatge - 500mv) times 100)

float temperaturesensortmp35(float rawadc) {
  float temp; // dual-purpose variable save space
  temp = rawadc*aref_voltage/1024.0; // convert digital voltage.
  temp = (temp - 0.5) * 100.0 ; // convert oc
  return temp;
}

check connections of ds1307 module again. have tried module without display, sending time values serial interface?

check voltage have between gnd pin , 5v pin when sketch running. get?


Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Problem displaying time via SPI


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62