ND, USA
Offline
Jr. Member
Karma: 0
Posts: 81
Arduino rocks
|
 |
« Reply #75 on: January 04, 2010, 02:11:24 am » |
Posted by: PaulS Re: FileLogger Reply #70 - 28.12.2009 at 00:29:29 Look at the sprintf function. It will convert all kinds of numbers, of various sizes, to strings, adding the appropriate null terminator. ]] [size=12]Where can I find information on the use of the sprintf function?[/size] I also need help with this code: byte buffer[5] = {seqn,32,65,13,10}; (32 = space, 65 = A, 13= carriage return, 10 = line feed)seqn is a variable that could be from 0-2000. It shows up on the SD card in ascii code. How can I get the filelogger system to load the values in variable seqn on the sd card as the actual value, whether the data is char or decimal, NOT in ascii. For instance: If the data loaded into the variable 'seqn' is a value of 1300, I want to have the value 1300 to show up on the sd card. At this time, if 'seqn' = 80 thru 85, and when I use this code: byte buffer[5] = {seqn,32,65,13,10}; byte result; result = FileLogger::append("data.txt", buffer, length);
the values in 'seqn' show up as P, Q, R, S, T, U Please help PO'T
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35483
Seattle, WA USA
|
 |
« Reply #76 on: January 04, 2010, 07:28:15 am » |
Where can I find information on the use of the sprintf function? Geez, I don't know. Google, maybe? Or a C programming manual. You're writing C code. You do have a book don't you. No? Well, I'll wait here while you go get one. You're back with the book? Good. How can I get the filelogger system to load the values in variable seqn on the sd card as the actual value, whether the data is char or decimal, NOT in ascii. You are creating a text file. That's what the .txt extension implies, anyway. Everything in the file will be ascii values. If seqn contains 80, and you write that as a byte to the SD card, you will get a "P". If you want to get "80", instead, you will need to use sprintf (or write the same code that sprintf implements) to convert 80 to "80" before writing the string to the card.
|
|
|
|
|
Logged
|
|
|
|
|
ND, USA
Offline
Jr. Member
Karma: 0
Posts: 81
Arduino rocks
|
 |
« Reply #77 on: January 04, 2010, 07:28:37 pm » |
PaulS
God Member
Online
Arduino rocks
Posts: 1282 Seattle, WA USA Gender: Re: FileLogger Reply #76 - Yesterday at 13:28:15 Quote:
Where can I find information on the use of the sprintf function?
Geez, I don't know. Google, maybe? Or a C programming manual. You're writing C code. You do have a book don't you. No? Well, I'll wait here while you go get one.
You're back with the book? Good. Well, gees, give an old man a break for getting this far.If you find my questions annoying, feel free to ignore them. :-? Due to the impenetrable thickness of my skull, :o and my lack of programming skills, :-[ I shall give up on the FileLogger and use another system that works for me, like sirmorris' ufat, (MMC/uFat2 and Deviceprint)Gee, I wonder how I was able to get that one into operation.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35483
Seattle, WA USA
|
 |
« Reply #78 on: January 04, 2010, 08:01:07 pm » |
The first thing shown in any programming class is some sort of hello world program. For the Arduino, that's blinking an LED. For a C programming class it's printing "Hello World", using the printf function. The sprintf function is a derivative of that function that places the output into a string buffer, instead of on an output stream.
If someone suggests that you use a function you are not familiar with, it takes 10 seconds to google the function. If you can't be bothered with doing that, why should I do it for you?
|
|
|
|
|
Logged
|
|
|
|
|
ND, USA
Offline
Jr. Member
Karma: 0
Posts: 81
Arduino rocks
|
 |
« Reply #79 on: January 04, 2010, 10:29:53 pm » |
If someone suggests that you use a function you are not familiar with, it takes 10 seconds to google the function. If you can't be bothered with doing that, why should I do it for you? A simple answer would have been: "You can find it by googleing such and such" I suppose having five stars over your name gives you the privilege of being impolite, but I didn't ask you in particular, and I didn't ask you to do anything in particular for me. You need not have replied in the first place. If dumb questioners annoy you, just ignore and move on.
|
|
|
|
|
Logged
|
|
|
|
|
ND, USA
Offline
Jr. Member
Karma: 0
Posts: 81
Arduino rocks
|
 |
« Reply #80 on: January 04, 2010, 11:02:47 pm » |
In case anyone else is interested, some information on an emulation of 'printf' can be found at the Arduino Playground: http://www.arduino.cc/playground/Main/PrintfAs stated in the playgroud"This function emulates the stdio.h printf() functionality in C and will send the output to the Serial connection using Serial.print()."
|
|
|
|
|
Logged
|
|
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 2
Arduino rocks
|
 |
« Reply #82 on: March 14, 2010, 07:07:11 pm » |
I am having a lot of trouble getting FileLogger to work on my arduino Mega. I changed the SPI settings to the ones mentioned in an earlier post. I have reformatted my card in more ways than I knew existed to get fat16. I have a file "data.log" and a file "data.txt", both with a single '1' in the file. It is giving me serial output on my computer, but all it will do is fail to initialize. I am not sure what I am missing. Can anyone help me? EDIT: I also forgot to mention, I get the same results when using the FileLoggerDemo as my own code. And I am using this microsd card slot: http://store.gravitech.us/micaad.html
|
|
|
|
« Last Edit: March 14, 2010, 07:12:40 pm by FlyMysticalDJ »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 5
Arduino rocks
|
 |
« Reply #83 on: June 17, 2010, 01:54:43 pm » |
Hi all,
I am new to Arduino and also new to this forum. Currently I got an Arduino Duemilanove (ATmega168) and got the Seeeduino sd shield. I downloaded the FileLogger library and I have sucessfully run the example code (that I have to create a file data.log and put a character there). For my project, I am planning to log data (say, temperature) every second, for about 6 months. I want to make a number of ".txt" files which contains the logged data for each day: eg. if in a txt file, each line contains a record for 1 sec. there will be 86400 lines in the txt file, for one day data. And there will be about 180 txt files stored in the SD card.
I wonder, if anyone has idea if that is possible? I read that I have to create a file beforehand b4 I append data to that specific file, can anyone tell me that if I can "create a file" within the "loop()", I just found that creating files beforehand is a hard code way and I want to avoid that. Also, if I stored all data in a single txt file for half year, the data will be huge and it seems to be dangerous for my project if something screwed up in between. Moreover, I would also like to learn about alternative solution.
Anyways, thanks for your help.
-klo
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 2
Arduino rocks
|
 |
« Reply #84 on: July 12, 2010, 10:13:11 pm » |
Hi to ALL!!! There is a way to read de SDCard with the filelogger library? If not, how can be done? Thank's!!
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 13
Arduino rocks
|
 |
« Reply #85 on: October 14, 2010, 04:50:21 am » |
Hi, i tried this with the microSD shield from sparkfun and an arduino duemilanove. I can't get it work. Do i have to do something special if i use the sparkfun shield? How do i have to wire it? Do i need to use a special digital pin to power up? I always get the error "Fail initializing" and sometimes "fail appending".
Need Help.
|
|
|
|
« Last Edit: October 14, 2010, 04:53:51 am by Crhiss »
|
Logged
|
|
|
|
|
Washington State, US
Offline
Newbie
Karma: 0
Posts: 29
|
 |
« Reply #86 on: October 29, 2010, 10:25:30 am » |
I have been working on a sketch to record my electrical power usage to a SD card and transmit the data via xBee using the Serial.print command. I have been using Seeeduino Stalker 168 and 328. The 328 works fine but the 168 will not work using both the Serial.print and the Filelogger statements. If I comment out the Serial.print statements, the filelogger works and if I comment out the filelogger statements, the Serial.print works. The problem is that the 168 does not have enough RAM to run the sketch. I adjusted the RX_BUFFER_SIZE to 8 to maximize RAM. Does anybody have any ideals about modifying the sketch to get it to run on the 168? The filelogger library seems to use a good size piece of RAM so I would like to know if there is a way to reduce its usage. Here is the sketch: /* * Meter reading program using Itron smart meter * * StalkerMeterLogger.pde * Sketch writes incoming data from IR detector * * CRS8291 - Arduino forum username * * Data output in following format with example * siteID, unixTime, watts, totalWatts, 15MinuteDemand, max15MinuteDemand, temperature degrees K * 14,1288310640,200,79859,12000,12236,29315 * */
#include "FileLogger.h" // http://code.google.com/p/arduino-filelogger/ #include <Time.h> #include <Wire.h> #include <DS1307RTC.h> // a basic DS1307 library - http://www.arduino.cc/playground/Code/Time
const int ledPin = 8; // LED watt indicator initialization. int ledState = LOW; // watt LED indicator lamp unsigned long ledOnTime = 0; // start time of LED pulse count on time
byte siteID[2]= {'1','4'}; byte delimiter[1]= {','}; byte crlf[2]= {0x0D,0x0A};
volatile unsigned int wattSensor = 0; // Counts power pulses in interrupt, 1 pulse = 1 watt unsigned int wattSensorCount; //number of watts during logging interval unsigned long totalWatts = 0; // Total power used since the sketch started ???
unsigned long oldtime=0; //last time loop has ran
unsigned int demandMinutes[15]; //Array that holds each powerusage reading done during the last 15 minutes unsigned int demandMinutesKwh=0; //Average of last 15 minutes in Kwh unsigned int maxDemandKwh=0; //Maximum 15 minute demand in Kwh
const int resetDay = 1; //day of month to reset counters, 1-31 const int resetHour = 0; //hour of day to reset counters, 0-23 const int resetMinute = 0; //minute of hour to reset counters, 0-59
const int tempPin = 1; //the analog pin the TMP36's Vout (sense) pin is connected to unsigned int temperatureK; //temperatue in degrees kelvin, used to eliminate negative temperatures
void setup(void) { pinMode(ledPin, OUTPUT); // LED watt indicator initialization
attachInterrupt(1, wattSensorInterrupt, FALLING);
for (int i=0; i<15 ;i++) //Initialize last fifteen minute Kwh to 0 demandMinutes[i]=0;
setSyncProvider(RTC.get); // the function to get the time from the RTC
// Serial.begin(9600); // int calcRam = freeRam(); // Serial.print("Free RAM: "); // Serial.println(calcRam); }
void loop(void) { time_t t = now(); // turn watt led off if 50 ms has passed since watt counted if (digitalRead(ledPin) == HIGH && millis() - ledOnTime >= 50) { digitalWrite(ledPin, LOW); } if( minute(t) != oldtime) //1 minute interval for data reporting { wattSensorCount = wattSensor; //get the count from the interrupt handler wattSensor = 0; //reset the watts count wattSensor = 300; //=18kwh, used for testing, comment out or delete for normal operation totalWatts = totalWatts + wattSensorCount; //total watts counter oldtime = minute(t); //use this for one minute interval calculateDemand(); // Calculate 15 minute demand measureTemperature(); //measure temperature in degrees Kelvin /* Serial.print("14,"); // print site id Serial.print(t); //print unix time Serial.print(','); Serial.print(wattSensorCount); //print watts per minute Serial.print(','); Serial.print(totalWatts); //print accumulated watts Serial.print(','); Serial.print(demandMinutesKwh); //print 15 minute demand Serial.print(','); Serial.print(maxDemandKwh); //print max 15 minute demand Serial.print(','); Serial.print(temperatureK); //print temperature in degrees Kelvin Serial.println(); */ FileLogger::append("data.txt", siteID, 3); //print site id write_long(t); //print unix time FileLogger::append("data.txt", delimiter, 1); write_long(wattSensorCount); //print watts per minute FileLogger::append("data.txt", delimiter, 1); write_long(totalWatts); //print accumulated watts FileLogger::append("data.txt", delimiter, 1); write_long(demandMinutesKwh); //print 15 minute demand FileLogger::append("data.txt", delimiter, 1); write_long(maxDemandKwh); //print max 15 minute demand FileLogger::append("data.txt", delimiter, 1); write_long(temperatureK); //print temperature in degrees Kelvin FileLogger::append("data.txt", crlf, 2);
//reset totalWatts and maxDemandKwh to zero once a month if ((day(t) == resetDay) && (hour(t) == resetHour)) { if ((minute(t) == resetMinute)) { totalWatts = 0; maxDemandKwh = 0; } } } }
void calculateDemand() //calculates rolling 15 minute average of one minute Kw usage { for (int i=0; i<15 ;i++) //Block move previous 14 minutes by one step demandMinutes[i]=demandMinutes[i+1]; demandMinutes[14]=wattSensorCount; //Assign latest one minute average to 15 minute average array demandMinutesKwh=0; //Reset demandMinutesKwh to 0 for (int i=0; i<15 ;i++) //Calculate new 15 minute demand demandMinutesKwh=demandMinutesKwh+demandMinutes[i]; demandMinutesKwh=demandMinutesKwh*4;
if (demandMinutesKwh > maxDemandKwh) //Assign maxDemandKwh to demandMinutesKwh if new high demand maxDemandKwh=demandMinutesKwh; }
void measureTemperature (void) { unsigned int tempReading = 0; // the analog reading from the sensor analogRead(tempPin); //discard first reading for (int i = 0; i < 50; i++) { tempReading = tempReading + analogRead(tempPin); } unsigned int voltage = tempReading * 329 / 1024 /50; temperatureK = (((voltage - 50) * 100) + 27315); // degrees K * 100 to save as integer }
void write_long(uint32_t number) //break data into byte array for writing to FileLogger { uint8_t buf[10]; uint8_t i=0; do { i++; buf[sizeof(buf) - i] = number%10 + '0'; number /= 10; } while (number);
FileLogger::append("data.txt", &buf[sizeof(buf) - i], i); }
void wattSensorInterrupt() // routine called when external interrupt is triggered { wattSensor = wattSensor + 1; //Update number of pulses, 1 pulse = 1 watt ledOnTime = millis(); digitalWrite(ledPin, HIGH); } /* // this function will return the number of bytes currently free in RAM int freeRam(void) { extern int __bss_end; extern int *__brkval; int free_memory; if((int)__brkval == 0) { free_memory = ((int)&free_memory) - ((int)&__bss_end); } else { free_memory = ((int)&free_memory) - ((int)__brkval); } return free_memory; } */
edit: Currently the Serial.print is commented out for the filelogger to work.
|
|
|
|
« Last Edit: October 29, 2010, 10:27:00 am by CRS8291 »
|
Logged
|
|
|
|
|
|