Offline
Newbie
Karma: 0
Posts: 2
|
 |
« Reply #75 on: April 14, 2012, 04:56:40 am » |
I found the problem, the code on the website has a != where it should be a == The line: if(timeStatus()!= timeNotSet) Should read: if(timeStatus() == timeNotSet) Of course, reading it now, this makes way more sense.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 3
Get Excited and BUILD A ROBOT!!!!!!!!
|
 |
« Reply #76 on: April 17, 2012, 04:20:29 pm » |
I was wondering how to compensate for the lag as the display seems to always be a few seconds off but otherwise this seems to be a great work and library. I'm trying to make a project that would display the message bellow as such on a LED Matrix and need the time to display as accurate as possible any help with the small lag would be helpful or such
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 315
Posts: 35519
Seattle, WA USA
|
 |
« Reply #77 on: April 17, 2012, 06:28:13 pm » |
and need the time to display as accurate as possible The lag is likely in your matrix code. Make that faster, or compensate by setting the time a few seconds ahead.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 3
Get Excited and BUILD A ROBOT!!!!!!!!
|
 |
« Reply #78 on: April 18, 2012, 11:01:46 am » |
here is my code if you don't mind taking a look were using an arduino uno with one of these parts http://www.adafruit.com/products/555#include <Time.h>
#include "HT1632.h"
#define DATA 2 #define WR 3 #define CS 4 #define CS2 5 #define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits #define TIME_HEADER 'T' // Header tag for serial time sync message // use this line for single matrix HT1632LEDMatrix matrix = HT1632LEDMatrix(DATA, WR, CS);
void setup() { Serial.begin(9600); matrix.begin(HT1632_COMMON_16NMOS); matrix.fillScreen(); delay(500); matrix.clearScreen(); matrix.setTextSize(1); // size 1 == 8 pixels high matrix.setTextColor(1); // 'lit' LEDs }
void loop() { if(Serial.available() ) { processSyncMessage(); } if(timeStatus()!= timeNotSet) { scroll("Name"); } delay(500); } void scroll(String m) { String i = " " + m + " "; for(int r = 0; r<i.length() + 27 *5; r++) { String q = i + digitalClockDisplay(); matrix.setCursor((-r),0); matrix.print(q); matrix.writeScreen(); delay(500); matrix.clearScreen(); } } String digitalClockDisplay(){ // digital clock display of the time String a = " "; a = a + hour(); a = a + ":"; a = a + minute(); a = a + ":"; a = a + second(); a = a +(" "); a = a + (dayStr(weekday())); a = a +(" "); a = a + (day()); a = a + (" "); a = a + (monthShortStr(month())); a = a + (" "); a = a + (year()); Serial.println(a); return a; }
String printDigits(int digits){ String a = ""; if(digits < 10) { a = "0" + digits; } else { a = "" + digits; } return a; }
void processSyncMessage() { // if time sync available from serial port, update time and return true while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits char c = Serial.read() ; Serial.print(c); if( c == TIME_HEADER ) { time_t pctime = 0; for(int i=0; i < TIME_MSG_LEN -1; i++){ c = Serial.read(); if( c >= '0' && c <= '9'){ pctime = (10 * pctime) + (c - '0') ; // convert digits to a number } } setTime(pctime); // Sync Arduino clock to the time received on the serial port } } }
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 315
Posts: 35519
Seattle, WA USA
|
 |
« Reply #79 on: April 18, 2012, 12:58:54 pm » |
here is my code if you don't mind taking a look I looked. It's a wonder the code works at all. digitalClockDisplay makes extensive calls to the String constructor and copy constructor, wasting resources all over the place, to create what should be a fixed length string. A global char array and a single call to sprintf() to populate it would be faster, and waste no memory AND result in a smaller sketch. Presuming, of course, that you get rid of the String in scroll, too. Other than the delays caused by Serial.print() the time every 1/2 second, at just 9600 baud, I don't see any particular reason why the time on the matrix would be significantly behind.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 3
Get Excited and BUILD A ROBOT!!!!!!!!
|
 |
« Reply #80 on: April 18, 2012, 04:25:51 pm » |
Would you mind pointing out the corrections that need to be made to help it run faster and cleaner it would be very helpful Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 22
|
 |
« Reply #81 on: April 19, 2012, 04:45:15 am » |
I hope I'm not stepping over the line of crossposting, here, thanks for the Time library, I used it in my DCF77 library and significantly cleaned up the code. Also, I made it to work well with the setSyncProvider callback: I opened a thread about it here. Please let me know if you have suggestions for improvements! Thijs
|
|
|
|
|
Logged
|
|
|
|
|
Adelaide, South Australia
Offline
Full Member
Karma: 0
Posts: 135
Arduino rocks
|
 |
« Reply #82 on: April 19, 2012, 03:19:02 pm » |
Would you mind pointing out the corrections that need to be made to help it run faster and cleaner ... have a read through this thread where problems with String are discussed, and PaulS even provided an example of how to use sprintf() that may help you. it worked for me! and here's a full explanation of sprintf() works: http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 1
|
 |
« Reply #83 on: April 22, 2012, 09:22:39 am » |
Hi folks! I´m building a Garduino system!
every time i try to verify the code, the arduino says:
`error compiling!`
" C:\Users\9k\Desktop\arduino-1.0\libraries\DateTime\DateTime.cpp:15:20: error: wiring.h: No such file or directory C:\Users\9k\Desktop\arduino-1.0\libraries\DateTime\DateTime.cpp: In member function 'void DateTimeClass::setTime(time_t)': C:\Users\9k\Desktop\arduino-1.0\libraries\DateTime\DateTime.cpp:28: error: 'millis' was not declared in this scope C:\Users\9k\Desktop\arduino-1.0\libraries\DateTime\DateTime.cpp: In member function 'time_t DateTimeClass::now()': C:\Users\9k\Desktop\arduino-1.0\libraries\DateTime\DateTime.cpp:43: error: 'millis' was not declared in this scope e "
here is the code i use:
#include <DateTime.h>
//define analog inputs to which we have connected our sensors int moistureSensor = 0; int lightSensor = 1; int tempSensor = 2;
//define digital outputs to which we have connecte our relays (water and light) and LED (temperature) int waterPump = 7; int lightSwitch = 8; int tempLed = 2;
//define variables to store moisture, light, and temperature values int moisture_val; int light_val; int temp_val;
//decide how many hours of light your plants should get daily float hours_light_daily_desired = 14;
//calculate desired hours of light total and supplemental daily based on above values float proportion_to_light = hours_light_daily_desired / 24; float seconds_light = 0; float proportion_lit;
//setup a variable to store seconds since arduino switched on float start_time; float seconds_elapsed; float seconds_elapsed_total; float seconds_for_this_cycle;
void setup() { //open serial port Serial.begin(9600); //set the water, light, and temperature pins as outputs that are turned off pinMode (waterPump, OUTPUT); pinMode (lightSwitch, OUTPUT); pinMode (tempLed, OUTPUT); digitalWrite (waterPump, LOW); digitalWrite (lightSwitch, LOW); digitalWrite (tempLed, LOW);
//establish start time start_time = DateTime.now(); seconds_elapsed_total = 0;
} void loop() { // read the value from the moisture-sensing probes, print it to screen, and wait a second moisture_val = analogRead(moistureSensor); Serial.print("moisture sensor reads "); Serial.println( moisture_val ); delay(1000); // read the value from the photosensor, print it to screen, and wait a second light_val = analogRead(lightSensor); Serial.print("light sensor reads "); Serial.println( light_val ); delay(1000); // read the value from the temperature sensor, print it to screen, and wait a second temp_val = analogRead(tempSensor); Serial.print("temp sensor reads "); Serial.println( temp_val ); delay(1000); Serial.print("seconds total = "); Serial.println( seconds_elapsed_total ); delay(1000); Serial.print("seconds lit = "); Serial.println( seconds_light); delay(1000); Serial.print("proportion desired = "); Serial.println( proportion_to_light); delay(1000); Serial.print("proportion achieved = "); Serial.println( proportion_lit); delay(1000);
//turn water on when soil is dry, and delay until soil is wet if (moisture_val < 850) { digitalWrite(waterPump, HIGH); }
while (moisture_val < 850) { delay(10000); moisture_val = analogRead(moistureSensor); }
digitalWrite(waterPump, LOW);
//update time, and increment seconds_light if the lights are on seconds_for_this_cycle = DateTime.now() - seconds_elapsed_total; seconds_elapsed_total = DateTime.now() - start_time; if (light_val > 900) { seconds_light = seconds_light + seconds_for_this_cycle; }
//cloudy days that get sunny again: turn lights back off if light_val exceeds 900. this works b/c the supplemental lights aren't as bright as the sun:) if (light_val > 900) { digitalWrite (lightSwitch, LOW); }
//turn off lights if proportion_lit>proportion_to_light, and then wait 5 minutes if (proportion_lit > proportion_to_light) { digitalWrite (lightSwitch, LOW); delay (300000); }
//figure out what proportion of time lights have been on proportion_lit = seconds_light/seconds_elapsed_total;
//turn lights on if light_val is less than 900 and plants have light for less than desired proportion of time, then wait 10 seconds if (light_val < 900 and proportion_lit < proportion_to_light) { digitalWrite(lightSwitch, HIGH); delay(10000); }
//turn on temp alarm light if temp_val is less than 850 (approximately 50 degrees Fahrenheit) if (temp_val < 850) { digitalWrite(tempLed, HIGH); }
}
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 315
Posts: 35519
Seattle, WA USA
|
 |
« Reply #84 on: April 22, 2012, 10:17:23 am » |
Is there some part of: error: wiring.h: No such file or directory that is confusing, misleading, or does not apply to you? Have you made any attempt to search for this error message on the forum? The wiring.h file was renamed to wiring_private.h. This means that code should NOT have been directly including that file. The correct file to have included was WProgram.h, which was renamed to Arduino.h.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #85 on: May 06, 2012, 04:16:22 am » |
I'm trying to use this library but I get into some problems. I have the TimeNTP example and try to compile it. After setting the packet sizes I get these errors while compiling: In file included from TimeNTP.cpp:10: /home/maarten/arduino-1.0/libraries/Ethernet/UdpBytewise.h:70: error: conflicting return type specified for ?virtual void UdpBytewiseClass::write(uint8_t)? /home/maarten/arduino-1.0/hardware/arduino/cores/arduino/Print.h:48: error: overriding ?virtual size_t Print::write(uint8_t)? When I fix that by changing virtual void UdpBytewiseClass::write(uint8_t) to virtual size_t UdpBytewiseClass::write(uint8_t), the error is In file included from /home/maarten/arduino-1.0/libraries/Ethernet/EthernetClient.cpp:1: /home/maarten/arduino-1.0/libraries/Ethernet/utility/w5100.h:14:17: error: SPI.h: No such file or directory
I certainly have SPI.h.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 315
Posts: 35519
Seattle, WA USA
|
 |
« Reply #86 on: May 06, 2012, 08:59:15 am » |
My copy of Arduino 1.0 does not have a file called UdpBytewise.h or UdpBytewise.cpp in the Ethernet folder in the libraries directory. I'm wondering why yours does. Have you been adding files to the libraries/Ethernet folder?
If so, you need to delete the entire Arduino 1.0 folder and reinstall.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #87 on: May 06, 2012, 01:07:22 pm » |
On http://arduino.cc/playground/Code/Time it says To use all of the features in the library, you'll need the UDPbitewise library, found here. So that's why I have them.
|
|
|
|
|
Logged
|
|
|
|
|
jersey
Offline
Newbie
Karma: 0
Posts: 46
hack freely my friends
|
 |
« Reply #88 on: May 12, 2012, 09:00:09 pm » |
hey im having some issues with the processing side of the library, on a fresh install of this code it will give an error saying array index out of bounds exception 1 on line 47
it says at SyncArduinoClock.setup(SyncArduinoClock.java:47) at processing.core.PAplet.handledraw(Unknown Source) at processing.core.PApplet.run(Unknown Source) at java.lang.Thread.run(thread.java:662)
and in the code window it highlights
println(" Connecting to -> " + Serial.list()[portIndex]);
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 315
Posts: 35519
Seattle, WA USA
|
 |
« Reply #89 on: May 13, 2012, 09:34:08 am » |
Serial.list()[portIndex] is an array access. If the array index, portIndex, is less than 0 or greater than or equal the length of the list, which could be 0, then, there is an array index out of bounds problem. We can't tell from what you posted how long the list is that the Serial.list() method returns, or what the value in portIndex is. You will need to make sure that the value in portIndex is legal.
|
|
|
|
|
Logged
|
|
|
|
|
|