Show Posts
Pages: 1 ... 31 32 [33] 34 35 ... 139
481  Development / Other Software Development / Re: SerialPort.h and "Serial" on: September 19, 2013, 11:21:07 am
It helped, thanks!
482  Using Arduino / Project Guidance / Re: Is it okay to read RTC continuosly? on: September 19, 2013, 07:35:31 am
An RTC shall not loose time when being read. Some RTCs loose a second when there is more than 1 second between starting I2C transaction and the finish of the I2C transaction (as the internal time counters increments are stopped when I2C bus is in action). Such RTCs include an 1bit register where a 1second transition, if any, is stored and processed afterwards (when the second tick occurred during I2C transaction). So unless "the act of reading via I2C" does not last for more than 1 second it is safe (for reading time and date from an I2C RTC you do not need more than 0.5msecs).

There is Time.h library however, which includes a mechanism, where the RTC is used for the syncing of the "system time" at specific periods only, ie. every 10minutes.
483  Development / Other Software Development / SerialPort.h and "Serial" on: September 18, 2013, 12:56:02 pm
What should be done in order to be able to name the new SerialPort (by fat16lib) class "Serial" (thus replace the old Serial automatically)?
SerialPort<0, 63, 63> Serial;

I've been trying to replace the standard Serial.print() with ie. NewSerial.print()
SerialPort<0, 63, 63> NewSerial;

but it seems to me it is almost impossible in practice. When replacing it in main I am getting zillion vector errors as it messes with all possible includes where the standard "Serial." is used..  smiley-roll
484  Using Arduino / Programming Questions / Re: RTC and time alarms on: September 16, 2013, 07:39:19 pm
I do not know the RTClib, never used it.
What you need is an "" function which returns time_t unix time number (uint32_t).

With this library:
#include <DS1307RTC.h>
the function calls RTC.get()
Reads the current date & time as a 32 bit "time_t" number. Zero is returned if the DS1307 is not running or does not respond.
485  Using Arduino / Programming Questions / Re: RTC and time alarms on: September 16, 2013, 07:28:27 pm
I would set the system time (from which the Alarms take the actual time) at the very beginning (in the setup()) with:
// SYNC the RTC and systime at boot
setSyncProvider(RTC.get());   // RTC.get() - the function to get the time from an RTC in unix format (uint32_t)
if(timeStatus()!= timeSet)
Serial.println("Unable to sync with the RTC");
Serial.println("RTC has set the system time");  
setSyncInterval(600); // set the number of seconds between re-sync of time

Then the now() returns the actual time without a need to read an external RTC each time you need to know the actual time.
Do not use setTime() for conversion of your alarm dates and times into unixtimes then, there are functions in Time.h which do it.

Edit: RTC.get()
486  Using Arduino / Programming Questions / Re: RTC and time alarms on: September 16, 2013, 06:59:40 pm
I would not mix the Time.h and the RTClib functions within the code. That might be an issue.

The setTime() is meant to be used once to set the internal system time, and now() for syncing with an external RTC (when required). See also setSyncProvider(getTimeFunction) which does the sync for you at specific intervals (min at 300secs by default).

I would not use each time I need to know the actual time, because the time is provided by the Time.h function now(), which returns current system time.

Does this set the current system time?
void loop ()
  DateTime now =;

If does not, your system time (from which the Alarms get the info on the actual time) comes from:
 // Use RTC time to set the end time {PUMP1}
  setTime(pump1offhour1, pump1offmin1, pump1offsec1,, current.month(), current.year());  
487  Topics / Science and Measurement / Re: O Scope recomendation on: September 16, 2013, 05:43:14 pm
Oscope below 200MHz is wasting the money, imho..

You cannot give blanket opinions without considering the application.
It does not matter what your today's application is. An oscope purchase is for majority of people considered an investment, which shall last for many years. What would be your applications in 4 years look like?
488  Topics / Science and Measurement / Re: How to treat SERIAL INTERRUPTS, while recording to SD CARD on SPI. on: September 16, 2013, 04:39:43 pm
Now I understand the NilRTOS is sort of a non-preemtive Operating System
It is a preemptive RTOS..

But even with a better structure, what exactly in that RTOS helps me deal with the Serial interrupt whilre writing to SD
Based on your problem description above - I do not understand why you think you have problems with Serial interrupt.
Serial is a subsystem which includes interrupt processing and buffering. You do not need to touch it.

You are missing your serial data you want sniff because your approach is not optimal. You need "something" which is able to work "in parallel":

a) receiving the data via serial, and

b) writing the data to the sdcard, and

c) to buffer the data somehow because of sporadic sdcard's write latencies, and

d) the above a), b), c) done in parallel.

No busy-wait operation (waiting while "something else" happens), asynchronous operation with a buffering mechanism to avoid latencies.

200bytes from serial to catch and write to an SDcard is easily doable with NilRtos and 2-3 simple tasks I think. You have to provide some additional info on your problem however - ie. how often the 200bytes data package needs to be written to the SDcard. Based on my experience with Nilrtos, you can easily write a continual data stream (ie. text data) up to 20kB/sec to the sdcard without loosing a single byte.

The assumption here is you have enough RAM for creating a sufficient fifo buffer to compensate the sporadic sdcard's outage. For 20kB/sec (eqv. ~230kbaud serial speed) and a worst case sdcard's write latency of 300ms you need ~7kBytes large fifo buffer..

489  Topics / Science and Measurement / Re: How to treat SERIAL INTERRUPTS, while recording to SD CARD on SPI. on: September 16, 2013, 01:23:49 pm
Here is an example - each csv record is sampled with 4ms period. The last five data are fifo's consumer/producer watermarks and the write latency. You may see when the sdcard's latency jumped to 17.472msecs the fifo buffered the records (the "0,149" means the fifo is empty, "4,145" means there are 4 records buffered in). The fifo then wrote the 4 buffered data records (and the new records) within 9 subsequent measurements onto the sdcard. No record was lost. The average time to write a record onto sdcard was ~2msecs. During this logging you may use Serial for communication with the system, as the Serial is also buffered.

,1379355276,108,0.049,85.71,92.24,95.10,96.13,96.61,96.12,96.17,89.31,-1,149,4,145,17472   <<< Write Latency
490  Topics / Science and Measurement / Re: How to treat SERIAL INTERRUPTS, while recording to SD CARD on SPI. on: September 16, 2013, 12:01:29 pm
Download and install NilRtos:

There is an example on data logging, a good point to start. Have a look on the NilRTOS.html documentation there - the fifo principle is explained there along with nice pictures ( see Examples in the html ). Also search forum for Nilrtos topics.

You have to get into the concept yourself, after that it might be easy. You need a periodic task which reads data (from internal/external ADCs for example) and writes the data (in form of a structure) into the fifo (when the fifo is not full), and then you need a second task which reads the fifo (when the fifo is not empty) and writes the data onto the sdcard. The synchronization is done via semaphores.

Thus when the sdcard is not ready for a longer period of time you fills in the fifo, when the card is ready again you writes the fifo content onto the card. Those two tasks are asynchronous - the first task is periodic (ie. 10ms sampling rate) and the second one is with "as fast as possible" timing.. You may print out the fifo statistic during the sampling, you may see how much of fifo the process consumes. You may log the fifo stats (consumer and producer sides) on the card along with each measurement record - you will see how the fifo fills/empties during your logging, based on the sdcard's latency (latency - the actual time the "write of a fifo record into sdcard" took - you can measure it with micros() and log on the card as well).

In parallel you may run many other tasks, for example a third task which does something via Serial.

See also:
491  Using Arduino / Project Guidance / Re: data collection and storage rates on: September 15, 2013, 05:05:55 pm
If I collect acceleration data WRT time and perform some integrations, I will be able to calculate velocity and position.
That might work, provided the accelerometer is mounted on a gyroscope stabilised platform. Wernher v.B. did it long time back, he needed such stabilized platform, even such his dead reckoning did not work well, fortunately..
492  Using Arduino / Project Guidance / Re: data collection and storage rates on: September 15, 2013, 04:49:39 pm
What is the best way to collect this data? Should I look at getting a SD card shield? How many samples per second can the arduino uno collect and transfer to a SD Card?
It depends.. I've been logging ~20kBytes/sec of .csv data (90bytes 250x per second), you need a FIFO however - to compensate sdcard's write latencies (typically 10-30ms, peaks up to 200ms). So based on data rate you need a sram space for FIFO - ie for 20kB/sec and 200ms latency you need up to 4kB deep FIFO.
493  Topics / Science and Measurement / Re: How to treat SERIAL INTERRUPTS, while recording to SD CARD on SPI. on: September 15, 2013, 04:04:37 pm
You have to use an FIFO in order to compensate the sdcard's write latencies. I've been using NilRtos with NilFIFO for that purpose - logging up to ~20kB/sec of text data, serial works during logging as well..
494  Using Arduino / Microcontrollers / Re: How to choose the chip I need? on: September 15, 2013, 10:25:26 am
..the sketch size is 6.5k.  Does that mean I need a chip with a flash memory of 6.5k or less?
You mean the size of sketch source (the text you see in the IDE), or the compiled binary size?
From the source size you cannot judge on the flash memory required, as a 6.5k source code may create binary of any size..
495  Using Arduino / Sensors / Re: LM35 problem on: September 15, 2013, 09:22:20 am
tempC =;

 read() returns a number between 0 and 255 for the next byte that's waiting in the buffer..

So you will not get your temperature in the integer or float format.. You will get the first byte coming from the serial only..

Quote temp returns as 50 degrees C

You got the number 50 - in the ASCII it means "2" - that is the first char (first byte) of your temperature sent as string "22"  smiley-wink

You may try (maybe it works with processing) provided your temperature has been sent as an integer:

if (commPort.available()>0) {
tempC = (float)(commPort.parseInt());


if (commPort.available()>0) {
tempC = commPort.parseFloat();

when sent as a float.

Pages: 1 ... 31 32 [33] 34 35 ... 139