Go Down

Topic: Uno hanging (Read 1 time) previous topic - next topic


Apr 16, 2011, 09:05 pm Last Edit: Apr 17, 2011, 04:29 pm by buteman Reason: 1
When I uploaded this code it locked up the arduino in that the TX light stays on.  
The sketch does continue to output to the serial monitor but
the output is not correct as it does not set the time correctly on the RTC
Also when I attempt to upload a different sketch the LED marked as L on the board flashes for
a few seconds just before the upload fails with the message:

processing.app.SerialNotFoundException: Serial port '/dev/ttyACM0' not
found.  Did you select the right one from the Tools > Serial Port
       at processing.app.Serial.<init>(Serial.java:153)
       at processing.app.Serial.<init>(Serial.java:76)
       at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:75)
       at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:93)
       at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:56)
       at processing.app.Sketch.upload(Sketch.java:1603)
       at processing.app.Sketch.exportApplet(Sketch.java:1568)
       at processing.app.Sketch.exportApplet(Sketch.java:1524)
       at processing.app.Editor$DefaultExportHandler.run(Editor.java:2293)
       at java.lang.Thread.run(Thread.java:636)

It is ok if I comment out the part in the loop so date/time setup part
seems to work.
I also uncommented the part which reads date/time from the DS1307 and
just prints the hour and minutes  and these are correct!
Can anyone spot what is wrong?

Here is the code:
Code: [Select]
Example 7.3
reading and writing to the Maxim DS1307 real time clock IC
based on code by Maurice Ribble
17-4-2008 - http://www.glacialwanderer.com/hobbyrobotics


#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
 return ( (val/10*16) + (val%10) );


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


// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock

// Assumes you're passing in valid numbers

void setDateDs1307(byte second,        // 0-59
byte minute,        // 0-59
byte hour,          // 1-23
byte dayOfWeek,     // 1-7
byte dayOfMonth,    // 1-28/29/30/31
byte month,         // 1-12
byte year)          // 0-99
 Wire.send(decToBcd(second));    // 0 to bit 7 starts the clock
 Wire.send(00010000); // sends 0x10 (hex) 00010000 (binary) to
control register - turns on square wave


// 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.requestFrom(DS1307_I2C_ADDRESS, 7);

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


void setup()
 byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

 // Change these values to what you want to set your clock to.
 // You probably only want to set your clock once and then remove
 // the setDateDs1307 call.

 second = 0;
 minute = 40;
 hour = 22;
 dayOfWeek = 5;
 dayOfMonth = 14;
 month = 5;
 year = 11;
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month,


void loop()
 byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

 getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth,
&month, &year);
 Serial.print(hour, DEC);// convert the byte variable to a decimal
number when being displayed
 if (minute<10)
 Serial.print(minute, DEC);
 if (second<10)
 Serial.print(second, DEC);
 Serial.print("  ");
 Serial.print(dayOfMonth, DEC);
 Serial.print(month, DEC);
 Serial.print(year, DEC);
 Serial.print("  Day of week:");
 case 1:
 case 2:
 case 3:
 case 4:
 case 5:
 case 6:
 case 7:
 //  Serial.println(dayOfWeek, DEC);


If anyone tries this code and doesn't know what to do to reset the arduino then look here:
I had to get the timing of the upload just right. and it took about a dozen tries before I succeeded.

I am running Ubuntu 10.10

Go Up