Show Posts
Pages: [1] 2
1  Using Arduino / Project Guidance / Re: Conflict I2C on: June 11, 2014, 03:44:07 pm
I'm really sorry,

I had a flash of genius... In fact I made the same error than in the past.

The SHT15 is not designed to run with the i2c protocol. However, the specification explain that is also possible to put the sensor over this bus without interference, but they specify that the system need to switch... So that confirmed throughout my mistake is running correctly with the i2c if there is no other component.

I'm going to use two specifical pins for SDA & SCK of the SHT15, but is anyone know how keep the both DS1307 & SHT1x over the i2c and manage the switch??
2  Using Arduino / Project Guidance / Conflict I2C on: June 11, 2014, 02:43:01 pm
Hello All,

Like a lot of previous projects, i'm trying to build a weather station.
I made a prototype with several single shields (SD card + Barometric Pressure + Humidity & Temperature sensor + RTC)

Now, I gathered all of us with more intelligence. I'm using a MEGA, with a prototype shield and an Adafruit Datalogger shield.
I can run each components, but when I decided to add RTC(i2C) and SHT(i2c) sensor, it's finish.
I configured the square wave from the DS1307 to manage the interrupt int.0 over the mega. It's always running, but it begin impossible to read date and humidity or temperature from the i2c protocol.
The pull-up resistors are present.

If someone have the solution, it would be great...

thanks
3  Using Arduino / Project Guidance / Re: External Interrupt for MEGA 2560 with SQW from DS1307 on: March 22, 2014, 01:42:06 pm
Thanks so much, (again) smiley

Static definition: I knew it, but I forgot it. I agree, now the sketch is more ... correct.

I need some lessons, I try to learn by myself, step by step, sorry if I was a little bit academic.

Now, I'm going to gather my SPI sensors (barometric pressure and humidity & temperature) and SD shield. I'll probably open another topic...

Best regards

4  Using Arduino / Project Guidance / Re: External Interrupt for MEGA 2560 with SQW from DS1307 on: March 22, 2014, 06:37:56 am
OK, sprintf is running perfectly, thanks so much

About your previous comment about volatile state which is just need to be used for count... in fact it was not possible for me to manage correctly my different tests... At the beginning I declared my variables in the main loop, classic not in volatile state, and it's not possible to make turns the maximum calculation for exemple...

In this following sketch, Average, Min and Max values are not running...
Perhaps the problem of this declaration is just the location within the sketch??

Code:
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68
#define THERM_PIN   0 
volatile int count;

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val) //--------------------------------------------------------------------------------------------
{
  return ( (val/16*10) + (val%16) );
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,byte *minute,byte *hour,byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year) //---
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *second     = bcdToDec(Wire.read() & 0x7f);
  *minute     = bcdToDec(Wire.read());
  *hour       = bcdToDec(Wire.read() & 0x3f);  // Need to change this if 12 hour am/pm
  *dayOfWeek  = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month      = bcdToDec(Wire.read());
  *year       = bcdToDec(Wire.read());
}

void setup() //-------------------------------------------------------------------------------------------------------
{
  Wire.begin();
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0x07);
  Wire.write(0x10);
  Wire.endTransmission();
  attachInterrupt(0, compteur , RISING);
  Serial.begin(9600);
}

void compteur() //----------------------------------------------------------------------------------------------------
{
  count = count + 1;
  if (count == 60)
  {
  count = 0; 
  }
}

void loop() //--------------------------------------------------------------------------------------------------------
{
  int c = count;
  int therm;
  int MN_therm;
  int MX_therm;
  int INT_therm;
  int AV_therm;
  while (c == count);
 
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
 
  therm = analogRead(THERM_PIN);
  INT_therm = INT_therm + therm;
  AV_therm = INT_therm / 60;
   
      if (therm > MX_therm)
      {
      MX_therm = therm;
      }
      else if (therm < MN_therm)
      {
      MN_therm = therm;
      }
      else
      {
      therm = therm;
      }
 

  if (second == 0)
  {

char buffer[70];
sprintf (buffer, "Date:%d/%d/%d , Heure:%d:%d:%d , Ana0:%d , Max:%d , Min:%d , Moy:%d", dayOfMonth, month, year,hour,minute,second,therm,MX_therm,MN_therm,AV_therm);
Serial.println(buffer);

    INT_therm = therm;
    AV_therm = therm;
    MN_therm = therm;
    MX_therm = therm;
     
  }
}
5  Using Arduino / Project Guidance / Re: External Interrupt for MEGA 2560 with SQW from DS1307 on: March 21, 2014, 02:58:21 pm
Thanks,

I added the library Printf.h and try to use it with this following sentence:
 Serial.Printf("%d , %d", therm,MX_therm);

But it's not running and the error topic say:"class HardwareSerial" has not member named 'printf'...

What's wrong??
6  Using Arduino / Project Guidance / Re: External Interrupt for MEGA 2560 with SQW from DS1307 on: March 20, 2014, 01:29:02 pm
Hello all, I'm back.

This is in the following my sketch which is managing the measurements steps.
If someone have some time to take a look and help me to improve it...
I'm not a programmer, and I think some improvements are possible...

The idea is to build a weather station. I know it's a frequent subject, but I don't want a simple data logger, because a significant period of recording is one hour, but during this delay, some parameters like wind, or sun, can change a lot...
So, In this sketch, I'm just manage a writing event for each minute with a calculation of average value, minimum & maximum.
The measurement is just a CTN sensor put on the Analog pin A0, without translation.

For exemple, I'm using volatile value, is it necessary?
I'm wondering if it's not possible to create a sub function to calculate Average/Min/Max...??

Best regards

Code:
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68
#define THERM_PIN   0 

volatile int count;
volatile int therm;
volatile int MN_therm;
volatile int MX_therm;
volatile int INT_therm;
volatile int AV_therm;

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val) //--------------------------------------------------------------------------------------------
{
  return ( (val/16*10) + (val%16) );
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,byte *minute,byte *hour,byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year) //---
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *second     = bcdToDec(Wire.read() & 0x7f);
  *minute     = bcdToDec(Wire.read());
  *hour       = bcdToDec(Wire.read() & 0x3f);  // Need to change this if 12 hour am/pm
  *dayOfWeek  = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month      = bcdToDec(Wire.read());
  *year       = bcdToDec(Wire.read());
}

void setup() //-------------------------------------------------------------------------------------------------------
{
  Wire.begin();
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0x07);
  Wire.write(0x10);
  Wire.endTransmission();
  attachInterrupt(0, compteur , RISING);
  Serial.begin(9600);
  Serial.print("Ana  Max  Min  Moy  __:__:__  __/__/__");
}

void compteur() //----------------------------------------------------------------------------------------------------
{
  count = count + 1;
  if (count == 60)
  {
  count = 0; 
  }
}

void loop() //--------------------------------------------------------------------------------------------------------
{
  int c = count;
 
  while (c == count);
 
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
 
  therm = analogRead(THERM_PIN);
  INT_therm = INT_therm + therm;
  AV_therm = INT_therm / 60;
   
      if (therm > MX_therm)
      {
      MX_therm = therm;
      }
      else if (therm < MN_therm)
      {
      MN_therm = therm;
      }
      else
      {
      therm = therm;
      }
 
  if (second == 0)
    {
    Serial.print(therm);
    Serial.print("  ");
    Serial.print(MX_therm); 
    Serial.print("  ");
    Serial.print(MN_therm);
    Serial.print("  ");
    Serial.print(AV_therm);
    Serial.print("  ");
    Serial.print(hour);
    Serial.print(":");
    Serial.print(minute);
    Serial.print(":");
    Serial.print(second);
    Serial.print("  ");
    Serial.print(month);
    Serial.print("/");
    Serial.print(dayOfMonth);
    Serial.print("/");
    Serial.println(year);
    INT_therm = therm;
    AV_therm = therm;
    MN_therm = therm;
    MX_therm = therm;
    }

}
7  Using Arduino / Project Guidance / Re: External Interrupt for MEGA 2560 with SQW from DS1307 on: March 18, 2014, 01:59:16 pm
Thanks so much.

I'm going to test my sketch to control measurement and recording, I'll come back probably to share about it with you perhaps to try to simplify it.

.
8  Using Arduino / Project Guidance / Re: External Interrupt for MEGA 2560 with SQW from DS1307 on: March 17, 2014, 12:58:39 pm
You are probably right.

I withdrew my 2kOhm for a 10 and finally a 4,7 and it's running correctly.
In the following you would find the link where I found this levels of resistors, but it's also talking about pull up for SDA and SCL, it's probably not the same for a SQW signal...??
http://fr.wikipedia.org/wiki/I2C

Could you give me more details about the level of resistor pull-up? If we are agree about the level used for SDA & SCL, what is the risk for the SQW with a using of a weak level of pull up??

Thank you in advance
9  Using Arduino / Project Guidance / Re: External Interrupt for MEGA 2560 with SQW from DS1307 on: March 16, 2014, 01:44:37 pm
It's RUNNING....Thanks Paul

The pull-up resistor was the solution.
I added a resistor at 2kOhm, I found some written which advice an Rp resistor between 1,5 and 3 kOhm, it's a classical value for i2c communication for a standard mode.

Just an additional precision: the DS1307 data sheet from DALLAS semiconductor is more detailed than Maxim Integrated especially about the need of pull-up resistor.

I'll begin my sketch for measurement and recording and I'll share about it we you.

Thanks all.
10  Using Arduino / Project Guidance / Re: External Interrupt for MEGA 2560 with SQW from DS1307 on: March 16, 2014, 12:36:43 pm
This is my first mistake. In the following there is the extract from the data sheet

SQW/OUT (Square Wave/Output Driver) – When enabled, the SQWE bit set to 1, the SQW/OUT pin outputs one of four square wave frequencies (1Hz, 4kHz, 8kHz, 32kHz). The SQW/OUT pin is open drain and requires an external pull-up resistor. SQW/OUT will operate with either Vcc or Vbat applied.

The pull-up resistor, it's true, I forgot it, and it's not present over the shield...

11  Using Arduino / Project Guidance / Re: External Interrupt for MEGA 2560 with SQW from DS1307 on: March 16, 2014, 12:31:46 pm
You would find the datasheet of the DS1307 at this link:
https://www.sparkfun.com/products/99

The SQW is the square-wave signal which can be create by the DS1307, with the quartz component. It's possible to provide a square-wave signal at 1hz, 4096Hz, 8192Hz, or 32768Hz.
12  Using Arduino / Project Guidance / Re: External Interrupt for MEGA 2560 with SQW from DS1307 on: March 16, 2014, 12:07:17 pm
"Upset" wouldn't be the correct term... I'm more puzzled ... It's my French touch

In fact I'm using the RTC shield from Sparkfun, and, after control, there is no pull-up resistor on the SQW output... firs of all.
In a second time, I'am able to see the step over the board TX led, and it's clearly 1Hz, but we see also a lot of short times in relation with the 25 steps.
Finally, I'm really agree with you about interferences... I initially hesitated to talk about it but I need to put my fingers over the board edge to start the normal running. Currently I'm working with the USB link from an iMAC computer... previously I worked with a classical PC and I never saw this kind of problems. Do you think a power supply would improve this behavior ?

About the sketch I'm using the correction from kowalski:
Code:
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68

volatile int count;

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0x07);
  Wire.write(0x10);
  Wire.endTransmission();
  attachInterrupt(0, compteur , RISING);
}

void compteur()
{
  count = count + 1;
}

void loop()
{
  int c = count;
  while (c == count);
  Serial.println(count);
}
13  Using Arduino / Project Guidance / Re: External Interrupt for MEGA 2560 with SQW from DS1307 on: March 16, 2014, 02:36:58 am
I tested your corrections, but it's not very well...

At the SQW rising, compteur start, but there are 25 steps, then it freeze (I think during the low SQW level)
At the second rising, compteur start again and add 25 other steps...
In summary, for each SQW rising, compteur increase 25 times. (1s =1,2,3,...25 / 2s=25,26,27...50 / 3s=...75 / 4s=....100 ....)

I tried to play with the interrupt mode, but without success...

I'm upset...
14  Using Arduino / Project Guidance / External Interrupt for MEGA 2560 with SQW from DS1307 on: March 15, 2014, 11:53:37 am
Hello all,

I’m trying to control my Mega board 2560 with the SQW signal from an RTC DS1307 Shield.
I want to use this configuration to work with an interrupt (int.0 on pin 2) at 1hz. I made a first sketch but the result on the serial monitor is incomprehensible.
I just want to count the seconds… in this case it will be possible to make a measurement for each minutes and a recording for each hours.
You would find the sketch in the following, if somenone could help me to find and improve my understanding…

Thank you in advance

#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68

volatile int count;

void setup()
{
  Wire.begin();
  attachInterrupt(0, loop , RISING);
  Serial.begin(9600);
}

void compteur()
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0x07);
  Wire.write(0x10);
  count = count++;
  Serial.println(count);
  Wire.endTransmission();
}

void loop()
{
  compteur();   
}
15  Using Arduino / Programming Questions / How improve electric consumption ?(watchdog and sleep mode) on: November 23, 2012, 01:09:43 pm
Hi,

I'm building a weather station and I would like to imrpove my electric consumption.

>>Configuration: Arduino UNO SMD rev2 + Shield SD Sparkfun + SHT15 (Temp & Hygro )+ MLP115A1 (pressure) + 9V battery

In summary, I need to manage one measurment per minute. I would like to sleep the board during 55mn and wake up 5mn before a measurment, just to heat correctly the sensors. I know that, there are 6 kind of sleep modes, but, I refused to use an external counter.

I'm a recent user of Arduino and I need a lesson about this using...

I don't know exactly what sleep's level I can hope with a internal counter. I thought use the watchdog, I'm currently trying to understand how use it...
In a second time, I thought during my 5mn of heating make a choice to shutdown some board's compoments with this kind of command:   power_timer0_disable();
  power_timer1_disable();
  power_timer2_disable();
  power_twi_disable();
  ...
but I don't know if it's available...

Is there someone to teach me???
Pages: [1] 2