Can´t set Pin

Hi,
I´ve got a strange problem with digitalWrite.
I set the latch named pin to HIGH using digitalWrite, but it stays LOW.
Here´s the code:

#include <Wire.h>
#include "RTClib.h"

int hourplus = 12;
int minplus = 11;

int mrshiftreset = 4;
int datapin = 5;
int clockpin = 6;
int latch = 7;

int onboardled = 13;

RTC_DS1307 RTC;

void setup () {
  Serial.begin(57600);
  Wire.begin();
  RTC.begin();
  pinMode(hourplus, INPUT);
  digitalWrite(hourplus, HIGH);
  pinMode(minplus, INPUT);
  digitalWrite(minplus, HIGH);
  
  pinMode(mrshiftreset, OUTPUT);
  digitalWrite(mrshiftreset, LOW);
  digitalWrite(mrshiftreset, HIGH);
  pinMode(datapin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  pinMode(latch, OUTPUT);
  
  pinMode(onboardled, OUTPUT);

  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__));
  }

}

void loop () {
    
  DateTime now = RTC.now();
  
  
  Serial.print(digitalRead(mrshiftreset));
  Serial.print(digitalRead(datapin));
  Serial.print(digitalRead(clockpin));
  Serial.print(digitalRead(latch));
  Serial.println();
  
  digitalWrite(latch, HIGH);
  
  Serial.print(digitalRead(hourplus));
  Serial.print(digitalRead(minplus));
  Serial.println();
  
  if(!digitalRead(hourplus))
  {
    RTC.adjust(DateTime(now.year(),now.month(),now.day(),now.hour()+1,now.minute(),0));
    delay(300);
    if(now.hour() >= 24)
    {
      RTC.adjust(DateTime(now.year(),now.month(),now.day(),0,now.minute(),0));
    }
  }
  
  if(!digitalRead(minplus))
  {
    RTC.adjust(DateTime(now.year(),now.month(),now.day(),now.hour(),now.minute()+1,0));
    delay(300);
    if(now.minute() >= 60)
    {
      RTC.adjust(DateTime(now.year(),now.month(),now.day(),now.hour(),0,0));
    }
  }
  
  if(now.second()%5 == 0)
  {
    digitalWrite(onboardled, HIGH);
  }
  else
  {
    digitalWrite(onboardled, LOW);
  }
 

  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();

  Serial.println();
  delay(500);
}

And here is the Serial Output:

1000
11
4:45:41

1000
11
4:45:42

1000
11
4:45:42

1000
11
4:45:43

DigitalWrite with the onboard Led works fine.

Has anyone an idea?

greetings
Alex

Whats is this?
pinMode(hourplus, INPUT);
digitalWrite(hourplus, HIGH);

This is for activating the pullup resistor.
But i dont think it has to do with the latch problem.

Right, thats the old way.

New way:
pinMode(hourplus, INPUT_PULLUP);

Ah OK.
But this shouldnt affect the latch variable.

What happens if you do a Serial.print right after the digitalWrite.

Serial.print(digitalRead(latch));
Serial.println();

digitalWrite(latch, HIGH);

Serial.print(digitalRead(latch));
Serial.println();

Woe do you know it stays low, you hecked with a scope or are you just guessing?

Mark

@larry: the same, already tried this.

@holmes: i checked it with the digitalread and printed it out in the SM

When you did a digitalRead you printed a LOW on the SM?
Can you show us an image of your cctry?
Do you have a DMM?

@holmes: i checked it with the digitalread and printed it out in the SM

Not in the code you posted - so any thing you did is meaning less.

And as there is nothing wrong with the design of the micro, and nothing wrong with digitalWrite() then we know that the problem is something YOU have done!.

Show your circuit diagram!

Mark

Problem solved.
There was an error in the circuit. :roll_eyes:
Thank you for your help