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)?
Code:
SerialPort<0, 63, 63> Serial;

I've been trying to replace the standard Serial.print() with ie. NewSerial.print()
Code:
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 "RTC.now()" function which returns time_t unix time number (uint32_t).

With this library:
#include <DS1307RTC.h>
the function calls RTC.get()
Quote
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:
Code:
// 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");
else
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).
See http://playground.arduino.cc/Code/Time

I would not use RTC.now() 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?
Code:
void loop ()
{
  DateTime now = RTC.now();
  Alarm.delay(1000);
}

If does not, your system time (from which the Alarms get the info on the actual time) comes from:
Code:
 // Use RTC time to set the end time {PUMP1}
  setTime(pump1offhour1, pump1offmin1, pump1offsec1, current.day(), current.month(), current.year());  
487  Topics / Science and Measurement / Re: O Scope recomendation on: September 16, 2013, 05:43:14 pm
Quote
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
Quote
Now I understand the NilRTOS is sort of a non-preemtive Operating System
It is a preemptive RTOS..

Quote
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.

Code:
,1379355276,104,0.049,85.71,92.24,95.10,96.13,96.61,96.12,96.17,89.31,-1,149,0,149,1864
,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
,1379355276,112,0.049,84.25,90.40,93.20,94.21,94.68,94.20,94.25,87.56,0,148,3,146,1864
,1379355276,116,0.049,84.03,90.35,93.26,94.38,94.99,94.62,94.25,87.56,1,147,3,146,2608
,1379355276,120,0.049,84.03,90.35,93.26,94.38,94.99,94.62,94.85,88.27,2,146,3,146,1936
,1379355276,123,0.049,85.45,92.00,94.91,96.02,96.59,96.14,96.33,89.51,3,145,2,147,1848
,1379355276,127,0.049,85.45,92.00,94.91,96.02,96.59,96.14,96.33,89.51,2,146,2,147,2232
,1379355276,131,0.049,83.88,90.16,93.01,94.10,94.66,94.22,94.40,87.84,2,146,1,148,1860
,1379355276,135,0.049,83.88,90.16,93.01,94.10,94.66,94.22,94.40,87.84,1,147,1,148,1936
,1379355276,140,0.049,84.64,91.32,94.33,95.55,96.24,95.88,96.15,89.40,0,148,1,148,3132
,1379355276,144,0.050,86.05,92.79,95.81,97.00,97.66,97.24,96.15,89.40,0,148,0,149,1804
,1379355276,148,0.050,86.05,92.79,95.81,97.00,97.66,97.24,97.45,90.49,-1,149,0,149,1764
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:
http://forum.arduino.cc/index.php?topic=178532.0

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:
http://forum.arduino.cc/index.php?topic=144715.30
491  Using Arduino / Project Guidance / Re: data collection and storage rates on: September 15, 2013, 05:05:55 pm
Quote
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
Quote
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
Quote
..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
Quote
tempC = commPort.read();

 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
..my 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:

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

or

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

when sent as a float.

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