Show Posts
Pages: 1 2 3 [4] 5 6
46  Using Arduino / Programming Questions / Re: LIFO (Last In First Out) retreival from .csv file on: January 24, 2013, 01:06:31 pm
This looks like a great solution and is pretty much what I am looking for, but I am getting a compiling error when trying to use <SD.h> with <SdFat.h>.  Are there any other functions similar to seek() and position() in SdFat? or possibly another solution?

I guess if there isn't I can try and redesign my sketch to write the .csv files using SD.h rather than SdFat.h, but there might be a problem down the road. 

Any suggestions?

Thank you,
Daniel
47  Using Arduino / Programming Questions / Re: LIFO (Last In First Out) retreival from .csv file on: January 24, 2013, 10:46:09 am
I think the SD library supports random access,

I am a little confused about this?  Do you mind expanding on it.

Here is my idea, but I am having trouble implementing it.  Lets say I have a file.csv with entries looking like A,B,C,D (A,B are ints and C,D are floats).

FILE.CSV

A,B,C,D
A,B,C,D
A,B,C,D
A,B,C,D
A,B,C,D
A,B,C,D
...

I want to read the value of 'D' starting from the buttom going up towards the top of the file.  I was thinking of using pointers to address the memory address of these values.  I want to stay away from using a while() to get to the bottom of the file.  The file can is thousands of entries long and I want to be reading these values at least 50 Hz back into the micro.

I am not the greatest in C++ and I have never implemented pointers in the Arduino, but I think it should be the same.

Your suggestions?

Daniel
48  Using Arduino / Programming Questions / LIFO (Last In First Out) retreival from .csv file on: January 23, 2013, 02:50:25 pm
Hello,

In my application I am datalogging (2 ints and 2 floats) into a CSV file.  After logging, I would like to be able to retrieve the entries in a "last-in first-out" fashion.  Are their any libraries, compatible with Arduino or not, that I may look at the code and learn from?

To avoid this, a solution maybe to datalog into the SD card in a reverse manner and read normally, or datalog normally and read in a reverse manner.  I feel like these 2 solutions will require wasted clock cycles, especially if the stack is large.

Any suggestions would be appreciated!

Daniel
49  Using Arduino / Programming Questions / Re: sdin.eof() reading CSV error.. on: January 22, 2013, 02:09:32 pm
Ah!  Stupid me, I appologize for the question... I also have a write in the setup() as a header.  I forget the my reading function only takes care of 2 ints and 2 floats in sequence with commas.

Thank you for leading me to solve my issue.

Daniel
50  Using Arduino / Programming Questions / sdin.eof() reading CSV error.. on: January 22, 2013, 01:50:02 pm
Hello,

With my DUE I am recieving encoder positions and writing the to an SD card via .csv.  Each entry contains 2 ints and 2 floats with commas and no spaces.

Now, I wish to read the created file with the Arduino and just display them through the Serial communication.  I am getting an error at:

Code:
if (!sdin.eof()) error("readFile")

It seems like the created file is not ending with an EOF which is triggering this error.

The code is large, so I will post the interface between writing and reading.

Writing

Code:
void loop()
{
  err = slaveEncoder - masterEncoder;
  analogWrite(EnA, setPWM(err)); // Write PWM value as the encoder count of the Master (controller)
 
  if (recordState  == true){
    int m;
    m = millis();
 
    if (m % LOG_INTERVAL == 0) {

      // use buffer stream to format line
      obufstream bout(buf, sizeof(buf)); 
     
      bout << m << ',' << ID << ',' << masterEncoder << ',' << slaveEncoder << endl;
      ID++;

    #if ECHO_TO_SERIAL
      cout << buf;
    #endif  // ECHO_TO_SERIAL

      // log data and flush to SD
      logfile << buf << flush;
     
      // check for error
      if (!logfile) error("!!WDF!!"); //Write Data Fail
     
      // don't log two points in the same millis
      if (m == millis()) delay(1);
    }
  } 
 
  if (Serial.available() > 0){
    command = Serial.read();
  if (command == 82){       //R - Record
    cout << pstr("Recording...") << endl;
    recordState = true;
    return;
  }
  else if (command == 84){  //T - Traverse
    cout << pstr("Stopped...") << endl;
    logfile.close();
    readFile();
    recordState = false;
    return;
  }
  else if (command == 83){  //S - Stop
    cout << pstr("Stopped...") << endl;
    logfile.close();
    recordState = false;
    return;
  }
  else if (command == 88){  //X - Exit
    logfile.close();
    cout << pstr("Done!");
    while (1);
  }
  else return;
  }
}

Reading

Code:
void readFile() {
  int read_millis;
  int read_ID;
  float read_ME, read_SE;
  char comma1, comma2, comma3;
 
  // open input file
  ifstream sdin(fileName);
 
  // check for open error
  if (!sdin.is_open()) error("open");
 
  // read until input fails
  while (sdin >> read_millis >> comma1 >> read_ID >> comma2  >> read_ME >> comma3 >> read_SE) {
   
    // error in line if not commas
    if (comma1 != ',' || comma2 != ',' || comma3 != ',') error("comma");
   
    // print in six character wide columns
    cout << read_millis << setw(6) << read_ID << setw(6) << read_ME << setw(6) << read_SE << endl;
  }
 
  // Error in an input line if file is not at EOF.
  if (!sdin.eof()) error("readFile");
}

If anyone can suggest a reason why I cannot read the file properly, I would really appreciate a tip smiley

Daniel
51  Products / Arduino Due / Re: RTClib DS1307 with Arduino on: January 21, 2013, 12:15:09 pm
Hello,

With the new library, I am running "ds1307" example in a new .pde file and I am getting the same error as the previous library.

Code:
test:6: error: expected ')' before '*' token
test:6: error: expected ')' before '*' token
test.ino: In function 'void setup()':
test:11: error: request for member 'begin' in '1074666080u', which is of non-class type 'Rtc*'
test:13: error: request for member 'isrunning' in '1074666080u', which is of non-class type 'Rtc*'
test:16: error: request for member 'adjust' in '1074666080u', which is of non-class type 'Rtc*'
test.ino: In function 'void loop()':
test:21: error: request for member 'now' in '1074666080u', which is of non-class type 'Rtc*'

This seems to be bug, would you know why this is the case?  Many poeple on the forums are getting this error.

Daniel

52  Products / Arduino Due / RTClib DS1307 with Arduino on: January 18, 2013, 03:21:54 pm
Hello,

I got the RTClib from ladyada but running it with my code, I am getting the following error.  Are people getting this library to work with them?

Code:
motortestdue:56: error: expected ')' before '*' token
motortestdue:56: error: expected ')' before '*' token
motortestdue.ino: In function 'void dateTime(uint16_t*, uint16_t*)':
motortestdue:60: error: request for member 'now' in '1074666080u', which is of non-class type 'Rtc*'
motortestdue.ino: In function 'void setup()':
motortestdue:119: error: request for member 'begin' in '1074666080u', which is of non-class type 'Rtc*'
motortestdue:123: error: request for member 'now' in '1074666080u', which is of non-class type 'Rtc*'
motortestdue.ino: In function 'void loop()':
motortestdue:234: error: request for member 'now' in '1074666080u', which is of non-class type 'Rtc*'

Or, does anyone else have a good RTC DS library?

Dan
53  Products / Arduino Due / Re: SdFat for Due posted on: January 18, 2013, 02:57:45 pm
I think I am okay with the speed I have - I am just logging 2 byte numbers at 50Hz - so if I need the extra space, I will change the design.

Thanks smiley-grin
54  Products / Arduino Due / Re: SdFat for Due posted on: January 18, 2013, 12:09:26 pm
Hmmm, interesting, I changed it to EIGHTH speed and quickstart, benchmark and sdformatter all worked.  But that was the only speed that allows me.  I hope this is fast enough for my application.  How can I try and obtain a faster speed.  Perhaps the 6'' cables are too long.

Dan
55  Products / Arduino Due / Re: SdFat for Due posted on: January 18, 2013, 11:50:47 am
Lmao, yes..

I am using a similar stand lone like this:

http://arduino-direct.com/sunshop/index.php?l=product_detail&p=246

SS to pin 10 and everything else connected to the SPI header in the middle of the due.

Daniel
56  Products / Arduino Due / Re: SdFat for Due posted on: January 17, 2013, 05:27:32 pm
I am having trouble getting my card prepped for the DUE, I am using the SanDISK Extreme Pro 16 Gb (95Mbps)

Running QuickStart

Code:
Enter the chip select pin number: 10

Card successfully initialized.

Can't determine the card size.
Try another SD card or reduce the SPI bus speed.
The current SPI speed is: 10.50 MHz
Edit spiSpeed in this sketch to change it.

Running PrintBenchmark

Code:
Type any character to start
Free RAM: 95507
Can't access SD card. Do not reformat.
SD errorCode: 0X4,0XFF

Any ideas why this is the case?

Dan
57  Products / Arduino Due / Did I damage my board? on: January 16, 2013, 12:30:27 pm
Hello,

I am trying to communicate between a DUE and an UNO via I2C.  I had the communication wire up with a pullup resistor to 5V.  For about 5-8 minutes I was trying to debug why the UNO wasnt receiving any information and then I realized that the DUE's tolerance is 3.3V. 

Could giving 5V to these pins (SCL1 and SDA1 on the DUE) for about 5-8 minute damage the board?  If so, how can I check?

Daniel

58  Products / Arduino Due / Re: DUE PWM Frequency on: January 16, 2013, 11:58:32 am
Hello,

I have fixed the problem, somewhat.

Looking into variant.cpp

Code:
  { PIOB, PIO_PB25B_TIOA0,   ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC0_CHA0     }, // TIOA0
  { PIOC, PIO_PC28B_TIOA7,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC2_CHA7     }, // TIOA7
  { PIOC, PIO_PC26B_TIOB6,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC2_CHB6     }, // TIOB6

  // 5
  { PIOC, PIO_PC25B_TIOA6,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC2_CHA6     }, // TIOA6
  { PIOC, PIO_PC24B_PWML7,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM),   NO_ADC, NO_ADC, PWM_CH7,     NOT_ON_TIMER }, // PWML7
  { PIOC, PIO_PC23B_PWML6,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM),   NO_ADC, NO_ADC, PWM_CH6,     NOT_ON_TIMER }, // PWML6
  { PIOC, PIO_PC22B_PWML5,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM),   NO_ADC, NO_ADC, PWM_CH5,     NOT_ON_TIMER }, // PWML5
  { PIOC, PIO_PC21B_PWML4,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM),   NO_ADC, NO_ADC, PWM_CH4,

Notice that only pins 7, 6, 5 and 4 respond to the #define in the variant.h file.  I am not sure how to configure the rest of the pins to act accordingly.  I havent tried changing NOT_ON_PWM (highlighted in the other pin configurations) to PWM_CH#, if this is possible.  I am assuming the architecture allocates pins 2-13 as PWM pins but on 5-7 as reconfigurable PWM pins.

If anyone would like to contribute why/how to reconfigure other pins - that would be helpful.

Daniel

59  Products / Arduino Due / Re: DUE PWM Frequency on: January 15, 2013, 12:07:24 pm
Quote
You have to restart the IDE if you make changes to the underlying libraries as they are compiled only once for the sketch "to save time". 

you might look at PWMC_ConfigureClocks()

Hello,

I restarted my IDE to let it recompile, but I am still getting 1KHz PWM frequency, also I put the following line into setup but that did not do anything.

PWMC_ConfigureClocks(3922 * PWM_MAX_DUTY_CYCLE , 0, VARIANT_MCK);. 

I wouldn't prefer either way since this micro is designated for motor control, if anything I would like to strictly change the variable in variant.h - if you know any reason why it is still not change, I would much appreciate it.

Daniel

60  Products / Arduino Due / Re: DUE PWM Frequency on: January 10, 2013, 03:52:17 pm
Has anyone found a solid way (preferably in sketch) to modify the output PWM frequency?  Also changing variant.h from 1k to what ever you want isnt working for me.  Changing it and saving doesn't change the output frequency.

Daniel
Pages: 1 2 3 [4] 5 6