Add RTClock to arduino, mpr121 and openlog

Hi,

ya maybe u can help me.

I am trying the bildr tutorial. But it doesnt work. Not even my RTClock does blink up.

http://bildr.org/2011/03/ds1307-arduino/

the pins scl and sda of the rtc i connected with the pin 4 and 5 of the arduino, although pin 4 and 5 are already connected with the mpr121 capacitive touch sensor.

Then i have these two codes on bildr and i try to upload them one by one i just copy the code and put it in a new sketch and try to upload, it upload, but what should work there then?

When i upload the code for the mpr121 again then the mpr121 works correctly but the time from the rtclock doesnt show up at all.

How can i activate the rtc?

You will need to understand what the various programs do, in detail, and then combine the useful pieces of each program into one program that does what you want it to do. I suggest that you start learning how to program with much simpler projects, beginning with blinking an LED. There are lots of tutorials on line for beginning Arduino users.

i want to stick to the bildr Tutorial http://bildr.org/2011/03/ds1307-arduino/

I want to put the very simple code in my mpr121 code, but it does never compile. The simple code is actually mostly the void loop, but i dont know how to put that into the other one.

I want to put this code:

//Arduino 1.0+ Only
//Arduino 1.0+ Only
#include "Wire.h"
#define DS1307_ADDRESS 0x68
void setup(){
  Wire.begin();
  Serial.begin(9600);
}
void loop(){
  printDate();
  delay(1000);
}
byte bcdToDec(byte val)  {
// Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}
void printDate(){
  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);
  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);
  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());
  //print the date EG   3/1/11 23:59:59
  Serial.print(month);
  Serial.print("/");
  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);
}

into this one:

#include "mpr121.h"
#include <Wire.h>
int irqpin = 2;  // Digital 2
boolean touchStates[12]; //to keep track of the previous touch states
void setup(){
  pinMode(irqpin, INPUT);
  digitalWrite(irqpin, HIGH); //enable pullup resistor
  
  Serial.begin(9600);
  Wire.begin();
  mpr121_setup();
}
void loop(){
  readTouchInputs();
}

void readTouchInputs(){
  if(!checkInterrupt()){
    
    //read the touch state from the MPR121
    Wire.requestFrom(0x5A,2); 
    
    byte LSB = Wire.read();
    byte MSB = Wire.read();
    
    uint16_t touched = ((MSB << 8) | LSB); //16bits that make up the touch states
    
    for (int i=0; i < 12; i++){  // Check what electrodes were pressed
      if(touched & (1<<i)){
      
        if(touchStates[i] == 0){
          //pin i was just touched
          Serial.print("pin ");
          Serial.print(i);
          Serial.println(" was just touched");
        
        }else if(touchStates[i] == 1){
          //pin i is still being touched
        }  
      
        touchStates[i] = 1;      
      }else{
        if(touchStates[i] == 1){
          Serial.print("pin ");
          Serial.print(i);
          Serial.println(" is no longer being touched");
          
          //pin i is no longer being touched
       }
        
        touchStates[i] = 0;
      }
    
    }
    
  }
}
 

void mpr121_setup(void){
  set_register(0x5A, ELE_CFG, 0x00); 
  
  // Section A - Controls filtering when data is > baseline.
  set_register(0x5A, MHD_R, 0x01);
  set_register(0x5A, NHD_R, 0x01);
  set_register(0x5A, NCL_R, 0x00);
  set_register(0x5A, FDL_R, 0x00);
  // Section B - Controls filtering when data is < baseline.
  set_register(0x5A, MHD_F, 0x01);
  set_register(0x5A, NHD_F, 0x01);
  set_register(0x5A, NCL_F, 0xFF);
  set_register(0x5A, FDL_F, 0x02);
  
  // Section C - Sets touch and release thresholds for each electrode
  set_register(0x5A, ELE0_T, TOU_THRESH);
  set_register(0x5A, ELE0_R, REL_THRESH);
 
  set_register(0x5A, ELE1_T, TOU_THRESH);
  set_register(0x5A, ELE1_R, REL_THRESH);
  
  set_register(0x5A, ELE2_T, TOU_THRESH);
  set_register(0x5A, ELE2_R, REL_THRESH);
  
  set_register(0x5A, ELE3_T, TOU_THRESH);
  set_register(0x5A, ELE3_R, REL_THRESH);
  
  set_register(0x5A, ELE4_T, TOU_THRESH);
  set_register(0x5A, ELE4_R, REL_THRESH);
  
  set_register(0x5A, ELE5_T, TOU_THRESH);
  set_register(0x5A, ELE5_R, REL_THRESH);
  
  set_register(0x5A, ELE6_T, TOU_THRESH);
  set_register(0x5A, ELE6_R, REL_THRESH);
  
  set_register(0x5A, ELE7_T, TOU_THRESH);
  set_register(0x5A, ELE7_R, REL_THRESH);
  
  set_register(0x5A, ELE8_T, TOU_THRESH);
  set_register(0x5A, ELE8_R, REL_THRESH);
  
  set_register(0x5A, ELE9_T, TOU_THRESH);
  set_register(0x5A, ELE9_R, REL_THRESH);
  
  set_register(0x5A, ELE10_T, TOU_THRESH);
  set_register(0x5A, ELE10_R, REL_THRESH);
  
  set_register(0x5A, ELE11_T, TOU_THRESH);
  set_register(0x5A, ELE11_R, REL_THRESH);
  
  // Section D
  // Set the Filter Configuration
  // Set ESI2
  set_register(0x5A, FIL_CFG, 0x04);
  
  // Section E
  // Electrode Configuration
  // Set ELE_CFG to 0x00 to return to standby mode
  set_register(0x5A, ELE_CFG, 0x0C);  // Enables all 12 Electrodes
  
  
  // Section F
  // Enable Auto Config and auto Reconfig
  /*set_register(0x5A, ATO_CFG0, 0x0B);
  set_register(0x5A, ATO_CFGU, 0xC9);  // USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V   set_register(0x5A, ATO_CFGL, 0x82);  // LSL = 0.65*USL = 0x82 @3.3V
  set_register(0x5A, ATO_CFGT, 0xB5);*/  // Target = 0.9*USL = 0xB5 @3.3V
  
  set_register(0x5A, ELE_CFG, 0x0C);
  
}

boolean checkInterrupt(void){
  return digitalRead(irqpin);
}

void set_register(int address, unsigned char r, unsigned char v){
    Wire.beginTransmission(address);
    Wire.write(r);
    Wire.write(v);
    Wire.endTransmission();
}

First let me advise you to stick to one thread per topic and not spread it over the half a dozen you have now.

Second I assume from this “pro mini, mpr121 and the openlog connected and everything is running perfect also with battery” (from the other thread) that all that’s left to do is add the RTC to the above.

You have a problem in that the DS1307 board needs 5V to run. Your single cell LiPo will output a max of 4.2V when fully charged and then discharge down to perhaps 3V (which is when you need to stop using it). So if you’re going to run the DS1307 in your system you will need to add a step-up voltage converter or another LiPo in series with the one you’ve got.

ps - are you using the 3.3V/8MHz pro-mini ? What FTDI adapter are you using to program it ?

Hi,

yes i am using the 3.3v pro mini actually. Isnt it that when the pro mini here is connected with ds1307 board then then everything should well right? ftdi adapter i use 3.3 breakout standard from sparkfun for programming.

jumbo9001:
Isnt it that when the pro mini here is connected with ds1307 board then then everything should well right?

Sorry your translation software muddled up the above line. I have no idea what you were trying to say.

The DS1307 is a 5V board. Where are you getting the 5V from ?

https://dlnmh9ip6v2uc.cloudfront.net/im … medium.jpg

(see the 5V input above)

Assuming you will get the 5V from someplace, you will be using the same I2C lines (SDA, SCL) that you use for the MPR121. These will be pulled up by some device to the 3.3V levels the Pro Mini and MPR121 can tolerate. These levels may work for the DS1307 as well but it’s not 100% guaranteed.

If you have 5V and want to proceed then disconnect the MPR121 and Openlog from the Pro Mini and connect (only) the DS1307. Connect the 5V to the DS1307 and make sure only the ground and I2C lines are connected between the DS1307 and Pro Mini. Use pull-up resistors on the I2C lines to 3.3V from the Pro Mini. Upload the test sketch and see if you can see the time and date being sent to the PC/serial monitor.

If this works we can then discuss how to integrate all the software.

oh ok, but i have a battery in the rtclock already, so i still need to connect the 5V pin also?

I thought when i connect the DS1307 with the pro mini then this should not be a problem, because the pro mini can accept 5V also which comes from DS1307 battery

is there no realtimeclock which runs predominantly on 3.3 volt only?

jumbo9001:
oh ok, but i have a battery in the rtclock already, so i still need to connect the 5V pin also?

I thought when i connect the DS1307 with the pro mini then this should not be a problem, because the pro mini can accept 5V also which comes from DS1307 battery

The battery is there to provide backup power (3V). I don't know that you can set the DS1307 time and date with only backup power. So are you saying you have another (?5V?) battery to run the DS1307 off of ? A different battery than the LiPo used in your other threads ? Like I said you can use 2 LiPo cells in series to get 7+V. This could be input to the RAW input of the Pro Mini but you'll also need another voltage regulator to make 5V for the DS1307.

Or you could run this off the 3.3V provided by the Pro Mini but be aware it communicates with the Pro Mini via SPI, not I2C like the DS1307 and MPR121.

https://www.sparkfun.com/products/10160

These 2 run off 3.3V and use I2C.

http://www.loveelectronics.co.uk/produc … ock-module

http://www.adafruit.com/products/255#Description

(it pays to read the comments on the product page)

https://www.sparkfun.com/products/99

oh ok i understand. U mean to set the time i should connect pro mini only with the RTClock. But for standard operation i can connect arduino pro mini + openlog + mpr121 and the rtclock connected with arduino pro mini right?

From the DS1307 datasheet …

OPERATION
The DS1307 operates as a slave device on the serial bus. Access is obtained by implementing a START
condition and providing a device identification code followed by a register address. Subsequent registers
can be accessed sequentially until a STOP condition is executed. When VCC falls below 1.25 x VBAT the
device terminates an access in progress and resets the device address counter. Inputs to the device will
not be recognized at this time to prevent erroneous data from being written to the device from an out of
tolerance system. When VCC falls below VBAT the device switches into a low-current battery backup
mode. Upon power-up, the device switches from battery to VCC when VCC is greater than VBAT + 0.2V
and recognizes inputs when VCC is greater than 1.25 x VBAT. The block diagram in Figure 1 shows the
main elements of the serial RTC.

https://www.sparkfun.com/datasheets/Com … DS1307.pdf

So I will GUESS you can run it off the backup battery and have it send time to the Pro Mini, you can certainly test it this way … just don’t connect 5V to the 5V input, connect Vbatt to that 5V input (or connect 3.3V from the Pro Mini to that 5V input) and see if it works. Be aware you won’t get the 9 years of battery life when run this way.

I would still start by getting the DS1307 to work all by itself (no MPR121, no Openlog) with just the example code. Then reconnect the other 2 and rerun the example code. You might want to read the datasheets to make sure the MPR121 and DS1307 don’t share the same I2C addresses.

To set the time on the DS1307 you will need to power it with it’s own separate 5V power supply.

Thinking some more about it …

Also from the datasheet …

SIGNAL DESCRIPTIONS
VCC, GND – DC power is provided to the device on these pins. VCC is the +5V input. When 5V is
applied within normal limits, the device is fully accessible and data can be written and read. When a 3V
battery is connected to the device and VCC is below 1.25 x VBAT, reads and writes are inhibited. However,
the timekeeping function continues unaffected by the lower input voltage. As VCC falls below VBAT the
RAM and timekeeper are switched over to the external power supply (nominal 3.0V DC) at VBAT.

This would seem to say the ProMini can’t even read time from the DS1307 when the voltage at the 5V input falls below 3.75V.

So to figure out what will and won’t work, try this process. Connect the DS1307 I2C lines and ground to the Pro Mini only (disconnect the other devices). With a fresh fully charged LiPo, connect it to the ProMini as you have been and also to the 5V input on the DS1307. When fully charged it should be > 3.75V and the DS1307 should work normally. Load and run your DS1307 example code. See if you can see the time and date on the serial monitor. If this works then go to the next step.

The next step is to disconnect the LiPo from the 5V input on the DS1307 and instead run it off the 3.3V from the Pro Mini. Again run the example code and see if the time and date can be seen. If this works, then that’s the way I’d run the DS1307. You won’t be able to set the time but maybe you can read the time. OTOH, if the above description is true, you won’t be able to see the time because the DS1307 won’t “talk” to the Pro Mini. If this is the case then you’ll need to find a 5V source to run the DS1307 off of … or get another RTC.

Ok thanks i will try to experiment on that. So you mean make a connection from the lipo battery one for the pro mini and one seperately to the ds1307 right? Will check that out.

Btw there is no realtime clock which is run usually on 3.3V isnt there?

tks

jumbo9001:
Ok thanks i will try to experiment on that. So you mean make a connection from the lipo battery one for the pro mini and one seperately to the ds1307 right? Will check that out.

Correct. Since you won't be using the Openlog, you can use the LiPo connection that normally goes there. The LiPo will start out at about 4.2V and then decrease from that. But it should stay high enough for long enough to do the testing. The initial test is just to show the example code and connections all work and that the DS1307 can talk to the Pro Mini.

The next step is to see if it all still works when using a 3.3V (< 3.75V) supply. If it doesn’t work when it used to, then you’re semi-out-of-luck.

jumbo9001:
Btw there is no realtime clock which is run usually on 3.3V isnt there?

tks

Didn't bother to read my post 4 or so posts up did you ?

ok thks will try on that