Arduino Reset Button

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
NoDelta
 
Posts: 25
Joined: Sun Sep 22, 2013 7:05 pm

Arduino Reset Button

Post by NoDelta »

I started with Arduino a couple months ago - trying to build a binary clock. At this point - the code is complete, final building is ~50% done, and I`m having 2 weird problems.
Here's the first.

When I go to upload a file (via USB, of course), I often have to upload it several times before the seconds start ticking. Sometimes I`ll see the xmit LED on the arduino ticking, sometimes absolutely nothing.
If I want to run the serial monitor, I have to close it, reupload the file, reopen the serial monitor, and cross my fingers.

I built the first prototype on a battery pack. (refer to weird problem number two, in my next post). I had the arduino plugged in and powered via USB. I would plug in the battery back, unplug the USB, and everything was great.

Until the batteries died. Or I tried to plug it into the wall. If it lost power for even a split second the program would stop. I'd hit the reset button (thinking this would re-run the program) but I could never get the clock to start working again without plugging it into the USB and trying a couple times until the program stuck.

These two things, the power & the reset button, feel like the same problem to me, but I`m not sure.
The code is only 8 megs of the 32 available, so I don't think that's the problem.

I`m not sure if this is a general problem or directly related to my code, so here it is in it's entirety:

Code: Select all

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

int  FaderPin     =  6;                       //To control brightness of LEDs
int  latchPin     =  7;                       //Turn on and off shift registers
int  clockPin     =  8;                       //Shift register clock
int  dataPin      =  9;                       //To send data to shift registers
int  potPin       = A0;                       //Read potentiometer
int  HourButton   =  10;
int  MinButton    =  11;

byte secLEDs      =  0;                       //Bytes to send second data
byte minLEDs      =  0;                       //Bytes to send min data
byte hourLEDs     =  0;                       //Bytes to send hour data
int  Hour1;                                   //Checks for hour button press
int  Hour2;                                   //Checks for hour button bounce
int  HourCheck;                               //Reads hour button
int  Min1;                                    //Checks for minute button press
int  Min2;                                    //Checks for minute button bounce
int  MinCheck;                                //Reads minute button

int s1           =  0;
int s10          =  0;
int m1           =  0;
int m10          =  0;
int hours        =  1;
int h1           =  0;
int h10          =  0;
int timecheck    =  0;
int AMPM         =  0;
int pot          =  0;

RTC_DS1307 RTC;

void setup() {
  Serial.begin(9600);                   //Set up serial communication at 9600bps
  Wire.begin();
  RTC.begin();
  RTC.adjust(DateTime(__DATE__, __TIME__));     // following line sets the RTC to the date & time this sketch was compiled

  DateTime now = RTC.now();
  timecheck = now.second();
  
  pinMode(dataPin,   OUTPUT);
  pinMode(latchPin,  OUTPUT);
  pinMode(clockPin,  OUTPUT);
  pinMode(HourButton,INPUT );
  pinMode(MinButton, INPUT );
  pinMode(A2,OUTPUT);
  digitalWrite(A2, LOW);
  pinMode(A3, OUTPUT);
  digitalWrite(A3, HIGH);
  HourCheck = digitalRead(HourButton);       // read the initial state
  MinCheck  = digitalRead(MinButton) ;  }

void loop(){
  DateTime now = RTC.now();
  //////////     time keeping     //////////
  if (timecheck != now.second()) {
    s1++;
    secLEDs=0;
    timecheck = now.second();
    if (s1 == 10)  {
      s1=0;
      s10++;  }
    if (s1 <0 || s1>10)  {
      s1=0;   }
    if (s10 == 6 )  {
      s10 = 0;
      m1++;  }
    if (s10 <0 || s10>6)  {
      s10 = 0;  }
    if (m1 == 10)  {
      m1 = 0;
      m10++;  }
    if (m1 < 0 || m1 > 10)  {
      m1=0;  }
    if(m10 == 6)  {
      m10 = 0;
      hours++;  }
    if(m10<0 || m10>6 )  {
      m10=0;  }
    if(hours>=1 && hours<=9)  {
      h1 = hours;
      h10 = 0;
      AMPM=0;  }
    if(hours>=10 && hours<=11)  {
      h1 = hours-10;
      h10  = 1;
      AMPM = 0;  }
    if(hours==12)  {
      h1 = hours-10;
      h10  = 1;
      AMPM = 1;  }
    if(hours>=13 && hours<=21)  {
      h1 = hours-12;
      h10 = 0;
      AMPM = 1;  }
    if(hours>=22 && hours<=23)  {
      h1 = hours-22;
      h10 = 1;
      AMPM = 1;  }
    if(hours==24)  {
      h1 = hours-22;
      h10=1;
      AMPM=0;  }
    if(hours<1 || hours >24)  {
      hours=1;  }
    Serial.print(h10);
    Serial.print(h1);
    Serial.print(":");
    Serial.print(m10);
    Serial.print(m1);
    Serial.print(":");
    Serial.print(s10);
    Serial.print(s1);
    Serial.print(" ");
    if (AMPM==0)  {
      Serial.println("AM");  }
    else  {
      Serial.println("PM");  }

  //////////     LED Display     //////////
  secLEDs  = 0;
  minLEDs  = 0;
  hourLEDs = 0;
  updateShiftRegister();
  if (s1 == 1 || s1 == 3 || s1 == 5 || s1 == 7 || s1 == 9)  {
    bitSet(secLEDs,1);  }
  if (s1 == 2 || s1 == 3 || s1 == 6 || s1 == 7)  {
    bitSet(secLEDs,2);  }
  if (s1 == 4 || s1 == 5 || s1 == 6 || s1 == 7)  {
    bitSet(secLEDs,3);  }
  if (s1 == 8 || s1 == 9)  {
    bitSet(secLEDs,4);  }
    
  if (s10 == 1 || s10 == 3 || s10 == 5)  {
    bitSet(secLEDs,5);  }
  if (s10 == 2 || s10 == 3)  {
    bitSet(secLEDs,6);  }
  if (s10 == 4 || s10 == 5)  {
    bitSet(secLEDs,7);  }
    
  if (m1  == 1 || m1 == 3 || m1 == 5 || m1 == 7 || m1 == 9)  {
    bitSet(minLEDs,1);  }
  if (m1  == 2 || m1 == 3 || m1 == 6 || m1 == 7)  {
    bitSet(minLEDs,2);  }
  if (m1  == 4 || m1 == 5 || m1 == 6 || m1 == 7)  {
    bitSet(minLEDs,3);  }
  if (m1  == 8 || m1 == 9)  {
    bitSet(minLEDs,4);  }
    
  if (m10 == 1 || m10 == 3 || m10 == 5)  {
    bitSet(minLEDs,5);  }
  if (m10 == 2 || m10 == 3)  {
    bitSet(minLEDs,6);  }
  if (m10 == 4 || m10 == 5)  {
    bitSet(minLEDs,7);  }   

  if (h1 == 1 || h1 == 3 || h1 == 5 || h1 == 7 || h1 == 9)  {
    bitSet(hourLEDs,1);  }
  if (h1 == 2 || h1 == 3 || h1 == 6 || h1 == 7)  {
    bitSet(hourLEDs,2);  }
  if (h1 == 4 || h1 == 5 || h1 == 6 || h1 == 7)  {
    bitSet(hourLEDs,3);  }
  if (h1 == 8 || h1 == 9)  {
    bitSet(hourLEDs,4);  }

  if (h10 == 1)  {
    bitSet(hourLEDs,5);  }

  if (AMPM == 1)  {
    bitSet(hourLEDs,6);  }

  updateShiftRegister();  }

  //////////     LED Fader      //////////
  pot =  255-analogRead(potPin)/4;
  analogWrite(FaderPin, pot);

  //////////     Hours Button     //////////
  Hour1 = digitalRead(HourButton);     // read input value and store it in val
  delay(10);
  Hour2 = digitalRead(HourButton);
  if (Hour1 == Hour2)  {
    if (Hour1 != HourCheck)  {                // the button state has changed!
      if (Hour1 == HIGH)  {                               // check if the button is pressed
        hours++;  
        s1=0;
        s10=0;  }  }
  HourCheck = Hour1;  }                 // save the new state in our variable
  
  //////////     Minutes Button     //////////
  Min1 = digitalRead(MinButton);     // read input value and store it in val
  delay(10);
  Min2 = digitalRead(MinButton);
  if (Min1 == Min2)  {
    if (Min1 != MinCheck)  {                // the button state has changed!
      if (Min1 == HIGH)  {                               // check if the button is pressed
        m1++; 
        s1=0;
        s10=0;  }  }
  MinCheck = Min1;  }                 // save the new state in our variable
}                                                   

void updateShiftRegister()  {
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, hourLEDs);
  shiftOut(dataPin, clockPin, MSBFIRST, minLEDs);
  shiftOut(dataPin, clockPin, MSBFIRST, secLEDs);
  digitalWrite(latchPin, HIGH);  }
Any help (or general comments on the code) would be appreciated.
Thanks in advance.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino Reset Button

Post by adafruit_support_mike »

I don't see anything in the code that would cause the kinds of problems you described. Post a photo of your hardware and we'll see if that gives us any clues.

NoDelta
 
Posts: 25
Joined: Sun Sep 22, 2013 7:05 pm

Re: Arduino Reset Button

Post by NoDelta »

Any specific shots of the hardware that would be helpful? I`m new to this.

There are 20 LEDs laid out on a piece of plexi and connected to a common ground that goes to the arduino.
The positive LEDs run to a resistor and then into the 3 serial registers (?).
There's a common ground and common power for the 3 registers, the 2 buttons, and the 1 pot. Each of these is super glued to a piece of plexi.
Time keeping is via chronodot.

Total wires into the arduino are:
4 data wires from the registers,
1 power to the register/buttons/pot
1 ground to the register/buttons/pot
1 ground to the LEDs
2 digital reads from the buttons
1 analog read from the pot
4 wires from the chronodot.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino Reset Button

Post by adafruit_support_mike »

An overall shot will let us see how things hook together in general. A down shot on the Arduino will let us see which wires are connected to which pins. Then get a few shots at the other ends of the connections if the details aren't obvious from the previous photos. If we need more, we'll know what to ask for.

Make sure there's plenty of light, and that the photos are clear enough for us to see the details. You can upload images directly to the forum, but there's a size limit.. 800x600 will usually work, and is still large enough to let us see what we need to.

NoDelta
 
Posts: 25
Joined: Sun Sep 22, 2013 7:05 pm

Re: Arduino Reset Button

Post by NoDelta »


User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino Reset Button

Post by adafruit_support_mike »

Good photos.. thank you.

The wiring for the shift registers and LEDs looks okay. I can't see all the pin connections, but the overall structure makes sense.

I assume the ChronoDot is off to one side, connected to the wires in the Analog header. I assume your wire colors obey the same red=vcc, black=gnd, yellow=data convention as the ones to the display (and thank you for doing that.. it makes reading a circuit *so* much simpler).

That wiring actually raises a warning flag for me, because it looks like you have the VCC and GND wires for the ChronoDot connected to a couple of the analog pins.

Technically that shouldn't cause any trouble since the ChronoDot draws very little power, but the ATmega328's analog input pins are all tied to a common multiplexer that lets the chip's ADC decide which pin it wants to read. It's possible that your analog reads of the potentiometer are having some kind of effect on the ChronoDot's power.

Try moving the Chronodot's supply lines over to the Arduino's 5v and GND pins and see if that helps.

NoDelta
 
Posts: 25
Joined: Sun Sep 22, 2013 7:05 pm

Re: Arduino Reset Button

Post by NoDelta »

Correct - Chronodot is off to the side with the same wiring convention.
VCC and Ground were wired to analog pins. In the code one was set high and one low. This was based on the chronodot tutorial:
http://learn.adafruit.com/ds1307-real-t ... t?view=all

When they have the pins out of the chronodot instead of the wires, they plugged it directly into the arduino, so I`m surprised this creates an issue.

I moved the lines over to the dedicated power and ground spots, and it looks like it solved the problem. I reset 5 times and 5 times it came right back on.
I assume that it won't be a problem to wire the chrono dot into the "communal" power and ground lines. Any concerns with that?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino Reset Button

Post by adafruit_support_mike »

NoDelta wrote:When they have the pins out of the chronodot instead of the wires, they plugged it directly into the arduino, so I`m surprised this creates an issue.
The tutorial shows a DS1307 taking power from the analog pins, but that's a different chip than the one in the ChronoDot. The tutorial also doesn't take analog readings with the ADC, and pins provide a short connection that isn't as sensitive to noise. Any of those factors might have combined to give you trouble.
NoDelta wrote:I moved the lines over to the dedicated power and ground spots, and it looks like it solved the problem. I reset 5 times and 5 times it came right back on.
Glad to hear it worked.
NoDelta wrote:I assume that it won't be a problem to wire the chrono dot into the "communal" power and ground lines. Any concerns with that?
That's actually the best way to do it. In general, you want to get power from the strongest source available, and the Arduino's power header connects directly to the regulator.

NoDelta
 
Posts: 25
Joined: Sun Sep 22, 2013 7:05 pm

Re: Arduino Reset Button

Post by NoDelta »

Thanks for your help.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”