Problems reading Data from a SD-Card to PWM (char to int?)


hello everybody,

 i´m arduino beginner , not familiar programming in general. in advance thank can give me little hint or advice concerning following subject:

the idea log data on sd card , few days later, read data , dim led on digital pin pwm. example more complex thing.

i logged data on sd card, using simple potentiometer analog pin (0-1023). „core" of patch shown under rec. works fine! made file (excerpt: play) read data sd card, have trouble doing this. (just because of testing reasons made 2 different files moment, rec , play).
as far understand, data on sd card ascii; when „println" data on serial monitor, values 10 13 48 13 10… i´m able interpret these values (p.e. 48 = 0…)
i tried several methods address digital pin(0-255) dim led using data sd card, without success far. @ least using play patch, got many 0´s in serial monitor serial monitor lists numbers while logging. deduce, there kind of conversion string of chars int(?), got zero´s… :-((( compiler works fine, d´ont error messages.

the final rec/play patch should run stable many days, therefore i´m not sure if using strings best way this, since i´ve read, that  dynamic memory allocation cause problems in practice.

i´m using:

http://www.sparkfun.com/products/12761
arduino uno/r3
software arduino 1.0.6
sd.h library v1.3

****************************

rec:

code: [select]
file datafile = sd.open(„data.txt", file_write); // creates/opens datafile
                                                   
if (datafile && valred == high) {
   datafile.println(sensorvalue); //recording per line
   datafile.close();
   delay(2);

  }



play:
code: [select]
int sdvalues = datafile.read();
int sdval = 0;
int sdvalindex = 0;

string sdvaltostr;
   
datafile = sd.open(„data.txt", file_read); // opens data.txt
 
  if (datafile) {
      digitalwrite(6, high); turn on control led

    while (datafile.available()) {
      // serial.write(datafile.read()); // if not commented out, serial monitor shows values 0-1023
      // serial.println(datafile.read()); // if not commented out, serial monitor shows ascii char (48, 49, ...)

        sdval = datafile.read();
 
      if ( sdval >= 48 ) {
        sdvaltostr.setcharat(sdvalindex, string(sdval).charat(0));   // nothing shown in serial monitor out of these lines
        sdvalindex++;
      }

      if ( sdval == 10 ) {
        sdvalindex = 0;    // i´m not sure, these 2 lines produce 0 in serial monitor

      }

      serial.println(sdvaltostr.toint());
      //analogwrite(atmungled, sdvalues);     
    }

    datafile.close(); // close file:
    digitalwrite(6, low); //turn off control led




thank comment or hint.
best regards!  :)  :smiley-confuse:

code: [select]
      if ( sdval >= 48 ) {
        sdvaltostr.setcharat(sdvalindex, string(sdval).charat(0));   // nothing shown in serial monitor out of these lines
        sdvalindex++;
      }

it's rather pathetic wasting resources on (multiple, actually) string instances, , doing monkey motion stuff treat string string. shitcan string , use string (a null terminated array of chars).


Arduino Forum > Using Arduino > Programming Questions > Problems reading Data from a SD-Card to PWM (char to int?)


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code