Show Posts
Pages: [1] 2 3 ... 14
1  Using Arduino / Programming Questions / Re: Improving SD card logger script on: November 29, 2012, 08:23:31 am
I found my earlier post: http://arduino.cc/forum/index.php/topic,79551.0.html#msg682829
Mr. fat16lib shares some good information:

Quote
I am amazed your setup works at all.  You need to clean up your wiring so the SD is close to the CPU and use very short wires for SPI.

The version of SD.h included with 0022 opens files with the O_SYNC flag so there is an incredible amount of I/O to the card.

Also opening and closing the file for each data point causes more I/O as the file grows since open does a seek to the end-of-file.

I/O to the card is done in 512 byte blocks and a sync call requires at least 2048 byte of I/O.  I suspect you are doing over 50,000 bytes of I/O to the SD for each data point.



Now I must puzzle out the meaning of:
I suspect you are doing over 50,000 bytes of I/O to the SD for each data point.
2  Using Arduino / Programming Questions / Re: Improving SD card logger script on: November 29, 2012, 04:56:37 am
Quote
The problem is that when i add a clock module to my project, it stops logging when the log-file is about 100 kb (although the memory card is 2 Gb).
Does it stop logging, or does it simply take longer to log the data?

Why not create a new file before the old one gets that big? One file per day, or week, or month, or whatever.

Is the temperature really changing that much? Logging once every 5 minutes is probably good enough, isn't it?

Thank you both for reply..
It simply stops logging. I connected LED to indicate the pauses between recordings. LED works SD-card recoring doesnt.
Last time i started the logger in the evening and in the morning i noticed that it had stopped 3.00 AM.
Logging frequency was about 1 recording in 5 min.
3  Using Arduino / Programming Questions / Improving SD card logger script on: November 28, 2012, 06:47:34 pm
Hello!
I have a simple SD card logging script that reads temperature value from LM-35 sensor and writes it to SD card.

Code:
#include <SD.h>
File file;
const int pin = 0;
int tempc = 0;

void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
}

void loop() {
file = SD.open("TEST_SD.TXT", FILE_WRITE);
for(int i = 0; i < 8; i++) {tempc += analogRead(pin);}
tempc = (5.0 * tempc * 100.0) / (8.0 * 1024.0);
file.println(tempc,DEC);
file.close();
}

How can i do this without the "FILE CLOSE" in loop?
The problem is that when i add a clock module to my project, it stops logging when the log-file is about 100 kb (although the memory card is 2 Gb).
I think it is because Arduino Duemilanove saves something into its memory (RAM ?) and it just gets full... also it might be because of the clock module - arduino keeps the time values in memory?

The code for SD + CLOCK + TEMP:
Code:
#include <SD.h>
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
File file;
const int pin = 0;
int tempc = 0;
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}
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.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.send(0);
   Wire.send(decToBcd(second)); 
   Wire.send(decToBcd(minute));
   Wire.send(decToBcd(hour)); 
   Wire.send(decToBcd(dayOfWeek));
   Wire.send(decToBcd(dayOfMonth));
   Wire.send(decToBcd(month));
   Wire.send(decToBcd(year));
   Wire.endTransmission();
}
void getDateDs1307(byte *second,
          byte *minute,
          byte *hour,
          byte *dayOfWeek,
          byte *dayOfMonth,
          byte *month,
          byte *year)
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
  *second     = bcdToDec(Wire.receive() & 0x7f);
  *minute     = bcdToDec(Wire.receive());
  *hour       = bcdToDec(Wire.receive() & 0x3f);
  *dayOfWeek  = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month      = bcdToDec(Wire.receive());
  *year       = bcdToDec(Wire.receive());
}

void setup() {
 pinMode(13, OUTPUT);
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
  Serial.begin(9600);

  second = 00;
  minute = 39;
  hour = 00;
  dayOfWeek = 6;
  dayOfMonth = 19;
  month = 11;
  year = 11;

 if (!SD.begin()) {
   Serial.println("begin failed");
   return;
 }}

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

  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

file = SD.open("TEST_SD.TXT", FILE_WRITE);

for(int i = 0; i < 8; i++) {tempc += analogRead(pin);}
tempc = (5.0 * tempc * 100.0) / (8.0 * 1024.0);

file.print(tempc,DEC);
file.print(" deg C ");
  file.print(hour, DEC);
  file.print(":");
  file.print(minute, DEC);
  file.print(":");
  file.print(second, DEC);
  file.print(" ");
  file.print(dayOfMonth, DEC);
  file.print("/");
  file.print(month, DEC);
  file.print("/");
  file.print(year, DEC);
  file.print(" Day_of_week:");
  file.println(dayOfWeek, DEC);

file.close();

}
4  Using Arduino / Storage / Re: Logging to SD file size limit? on: February 08, 2012, 01:15:08 pm
thank you for sharing your knowledge!
The main reason must be the open-close thing. Maybe making new file after 200 kb will solve the problem.
Or i can add a push-button that makes the file close.

ps. sorry for being so stupid.. but im playing with Arduino just for hobby
5  Using Arduino / Storage / Re: Logging to SD file size limit? on: February 08, 2012, 04:17:29 am
ok thanks! I will do it when i get back home.
6  Using Arduino / Storage / Re: Logging to SD file size limit? on: February 05, 2012, 10:41:35 am
Thank you for your ideas..
When i just make a LOOP for saving some text - it works well (DOES NOT stop after 300 kb).
I am using the default SD library that comes with Arduino IDE 022.

One solution could be to use another SD lib... although i dont think it is the problem, because TEXT saving worked..

Saving to separate file might be the best solution so far - for example after 300 kb new file is created...
7  Using Arduino / Storage / Re: Logging to SD file size limit? on: February 05, 2012, 06:08:38 am
I still have the same problem - temperature logger stops saving to SD card after 200 - 300 kb. Arduino shows that it is working but nothing goes to SD card.

Maybe there is something with formatting the SD card... cant be any other limits

really really sad, that it doesnt work smiley-sad
8  Using Arduino / LEDs and Multiplexing / Re: Programmable LED on: January 18, 2012, 12:37:39 am
.. or is there any code that can demonstrate the Arduino is able to learn something and then playing it back
9  Using Arduino / LEDs and Multiplexing / Programmable LED on: January 17, 2012, 01:23:38 pm
Hi!
I found a tutorial from Instructables.com that teaches how to make a programmable blinking led by using ATtiny13v + led + LDR (Light Dependent Resistor).
http://www.instructables.com/id/Programmable-LED/



You wave some thing in front of LDR and ATtiny saves the pattern and starts to blink like that.

So now im looking for a way to implement that code to Arduino (ATMega 328).

Can anyone help me?

here is the code from Instructables:

Code:
/* -----------------------------------------------------------------------
 * Title:    flick led
 * Author:   Alexander Weber <alexander.weber.0 at gmail.com>
 * Date:     21.02.2007
 * Hardware: ATtiny13v
 * Software: WinAVR 20060421
 */

// define as -D switch
//#define F_CPU 1200000 // Taktfrequenz: 1.2MHz, internal oscillator


#include <avr/io.h>
#include <util/delay.h>

#define TRUE 1
#define FALSE 0
#define ON 1
#define OFF 0

// use PB2 for led, pin 7
#define LED_BIT 2
// use PB3 to enable ldr, pin 2
#define ADC_ENA_BIT 3
// pause
#define PAUSE 25
// select ADC2, PB4, pin 3
#define CHANNEL 2
// values over threshold are recorded as "on"
#define THRESHOLD 800
// storage for recorded values
#define MAX 400
static uint8_t values[MAX / 8];


/*
 * get_adc
 * Return the 10bit value of the selected adc channel.
 */
uint16_t get_adc(uint8_t channel) {

// enable voltage for adc
PORTB |= (1 << ADC_ENA_BIT);

// ADC setup
ADCSRA =
(1 << ADEN) | // enable ADC
(1 << ADPS1) | (1 << ADPS0); // set prescaler to 8

// select channel
ADMUX = channel;

// select reference voltage
// ADMUX |= (1 << REFS0); // use internal reference

// warm up the ADC, discard the first conversion
ADCSRA |= (1 << ADSC);
while (ADCSRA & (1 << ADSC));

ADCSRA |= (1 << ADSC); // start single conversion
while (ADCSRA & (1 << ADSC)); // wait until conversion is done

PORTB &= ~(1 << ADC_ENA_BIT); // disable voltage for adc

return ADCW;
}



int main(void) {

uint16_t i = 0;
uint16_t count = 0;
uint8_t light = OFF;
uint8_t last_light = OFF;
uint16_t last_time = 0;
uint8_t programming = TRUE;

// define LED and ADC enable as outputs
DDRB |= (1 << LED_BIT) |
(1 <<ADC_ENA_BIT);

// intro
for (i = 0; i < 5; i++) {
PORTB |= (1 << LED_BIT);
_delay_ms(200);
PORTB &= ~(1 << LED_BIT);
_delay_ms(200);
}
for (i = 0; i < 5; i++) {
_delay_ms(100);
}

while (1) {

if (programming) {
// signal that we are ready to program
for (i = 0; i < 5; i++) {
PORTB |= (1 << LED_BIT);
_delay_ms(40);
PORTB &= ~(1 << LED_BIT);
_delay_ms(40);
}
// now read the ldr and store it
for (i = 0; i < MAX; i++) {
if (get_adc(CHANNEL) > THRESHOLD) {
values[i / 8] |= (1 << (i % 8));
PORTB |= (1 << LED_BIT);
}
else {
values[i / 8] &= ~(1 << (i % 8));
PORTB &= ~(1 << LED_BIT);
}
_delay_ms(PAUSE);
}
// signal that we are finished with programming
for (i = 0; i < 5; i++) {
PORTB |= (1 << LED_BIT);
_delay_ms(40);
PORTB &= ~(1 << LED_BIT);
_delay_ms(40);
}
// switch to playback
programming = FALSE;
count = 0;
}
else {
// have we detected a change?
light = (get_adc(CHANNEL) > THRESHOLD) ? ON : OFF;
if (light != last_light) {
// when was the last change?
if ((count - last_time) == 10) {
programming = TRUE; // switch to programming mode
}
else {
last_time = count;
}
}
last_light = light;

// replay recorded lights
if (values[count / 8] & (1 << (count % 8))) {
PORTB |= (1 << LED_BIT);
}
else {
PORTB &= ~(1 << LED_BIT);
}
_delay_ms(PAUSE);
count++;
if (count == MAX) {
count = 0;
}
}

}

return 0;

}



Also this code compiles under Arduino IDE but i dont know how to connect the led and LDR using that code.
10  Community / Bar Sport / Re: Anyone doing money with Arduino? on: December 04, 2011, 09:06:13 am
Cool...
 as I am a student I have one lesson about making Business Plan and we have a chance to make a small student company... it lasts 1 year and we don't have to pay any taxes. So I was thinking to do something with Arduino, maybe some custom led clocks or someting... also we have an alternative - laptop tables.. but im not so into woodwork
11  Using Arduino / Programming Questions / Re: RealTimeClock code - change PINs numbers on: December 03, 2011, 06:31:48 pm
Thanks!
So i just use those pins (ATTiny85 SCL (PB2) & SDA (PB0) ) instead of Analog 4, 5.
12  Community / Bar Sport / Anyone doing money with Arduino? on: December 03, 2011, 05:48:48 pm
HI!
I'd be interested to know if anyone is earning money with something they built using Arduino..?
13  Community / Bar Sport / Re: Any idea what this is? on: December 03, 2011, 05:45:50 pm
I think it's a part of Arduino Time Machine!
14  Using Arduino / Programming Questions / Re: RealTimeClock code - change PINs numbers on: December 03, 2011, 05:39:42 pm
I found out that the problem is with Arduino Wire Library:
http://arduino.cc/en/Reference/Wire

"This library allows you to communicate with I2C / TWI devices. On most Arduino boards, SDA (data line) is on analog input pin 4, and SCL (clock line) is on analog input pin 5"

So there is no way to use this RTC module with ATTiny ?
15  Using Arduino / Programming Questions / RealTimeClock code - change PINs numbers on: December 03, 2011, 05:21:31 pm
Hello!
I recently bought RealTimeClock Module and followed example from:
http://www.glacialwanderer.com/hobbyrobotics/?p=12

Everything works great but I can only use it with ATMEGA328 microcontroller,
because THE CODE WORKS ONLY WITH ANALOG PINS 4 and 5.
but what i want is to use RTC module with ATTiny microcontroller which doesn't have analog pins 4 & 5.

has anyone tried to change the pins? Or does anyone have another RTC code to offer?
Pages: [1] 2 3 ... 14