Show Posts
Pages: 1 2 3 [4] 5 6 ... 9
46  Using Arduino / Programming Questions / Re: reading text from an sd card on: June 07, 2012, 01:39:08 pm
Quote
Is this a trick question ?

Do you mean 'How the * should I know?'. Was just hoping there might be an obvious way, different to my approach, to speed up the reading of each file on the card

It's currently taking 54ms to open,read, then close each (1024byte) file.  This equates to a maximum of 18fps before any further time spent processing.

I came across http://code.google.com/p/fat16lib/ which is an optimised sd library but it only supports fat16 standard sd cards and I don't have one to test. Any idea if this would speed up file opening and reading times?


Using hex instead of csv takes 2/3 of the time, but if there is no delimiter, how do I read in values less than 0xF? ie where there is only one digit...  Can I just write 00 rather than 0 in the text file?


Thanks for your optimised filename code. I wasn't sure how to do it with chars. It's way better!


edit- also, how do I convert a char[] with a value of (for example) 'FF' into an int with a value of 255?
47  Using Arduino / Programming Questions / Re: reading text from an sd card on: June 06, 2012, 06:21:14 am
Hi Michael.

I'm using a Mega2560 with an ethernet shield.

I've created text files, each one representing one 'frame' of 512 8bit values.  The plan is to read these load each frame into arduino ram, update these 512 values (which get sent as dmx), then load the next frame.

I need to read 512 8bit values at as close to 30 fps as possible.


Below is the test code I'm using to open then close 30 of these text files

Where do you think the bottleneck is?

Code:
#include <SD.h>

File myFile;

void setup()
{
  Serial.begin(57600);
  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
   pinMode(53, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
 
  String filenamePre = "fr";
  String filenamePost = ".txt";
  String filenameStr = "fr21.txt";
  char filename[13]; 
  char testBuff[513];
 
 
  Serial.println("beginning read");
  Serial.println(millis());
 
  int j = 0;
  while(j < 30)
  {
 
    // re-open the file for reading:
    filenameStr = filenamePre + j + filenamePost;
    filenameStr.toCharArray(filename, 13);
    myFile = SD.open(filename);
    if (myFile) {
      //Serial.println(filename);
     
      // read from the file until there's nothing else in it:
      int byteCount = 0;
      while (myFile.available())
      {
        testBuff[byteCount] = myFile.read();
        byteCount++;
      }
      testBuff[byteCount] = NULL;

     
      // close the file:
      myFile.close();
    } else {
    // if the file didn't open, print an error:
      Serial.println("error opening test.txt");
    }
   
   
   // Serial.println(testBuff);
   
  j++;
  }
 
  Serial.println();
  Serial.println(millis());
 
 
 
}

void loop()
{
// nothing happens after setup
}
48  Using Arduino / Programming Questions / Re: reading text from an sd card on: May 30, 2012, 03:04:12 pm
Great.

One more thing - As each comma separated value is describing one value of 0-255, is it possible to just send single bytes in sequence with a delimiter at the end?

If so, how would these appear in a text file? I'm using another piece of software to generate the text files and make it do anything. I'm just not sure what a single byte should 'look like'

This would reduce each file size by 75%, which would be great as I'm trying to send lots of values very quickly.

Thanks again
49  Using Arduino / Programming Questions / Re: reading text from an sd card on: May 30, 2012, 02:26:04 pm
Ah haah, thanks. you've just helped me understand some crucial things!

how's this? -

Code:
int byteCount = 0;
      while (myFile.available())
      {
        testBuff[byteCount] = myFile.read();
        byteCount++;
      }
      testBuff[byteCount] = NULL;

Can I set the size of char testBuff[] dynamically, increasing by 1 every time I need to add a new byte, or do you have to just initialise the array to be larger than it can ever be?
50  Using Arduino / Programming Questions / Re: reading text from an sd card on: May 30, 2012, 12:59:54 pm
I'm trying to make the same thing smiley
51  Using Arduino / Programming Questions / Re: reading text from an sd card on: May 30, 2012, 11:33:48 am
I want to read in the text  "46,110,173,237;"

and store it as a String "46,110,173,237;"
52  Using Arduino / Programming Questions / Re: reading text from an sd card on: May 30, 2012, 05:30:00 am
Ha, I just rewrote the code and it works. Not sure what it was as the code is mostly just the example sketch.

One question, this code is printing to serial using Serial.write, not Serial.print.  As I understand it this is because the data is in binary form. Given this, how do I assign the text (ascii) contents of this file to a string?


Here is the code -

Code:
#include <SD.h>

File myFile;

void setup()
{
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
   pinMode(53, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
 
 
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
   
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
  // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
// nothing happens after setup
}

53  Using Arduino / Programming Questions / reading text from an sd card on: May 29, 2012, 10:25:31 am
I'm playing with the sd card read/write tutorial.  The example sketch works fine.

When I create a text file in notepad, copy it to an sd card and open it using the arduino, the formatting is different.  Ie -

Original text - this is a test 1 2 34
Text printed in serial monitor - tisisa es 12 4

I've tried asni, utf8 etc

any ideas?
54  Using Arduino / Installation & Troubleshooting / Re: Arduino Mega com port not free on: May 07, 2012, 07:09:48 am
Looks like I was being impatient. Sorry for the false alarm!
55  Using Arduino / Installation & Troubleshooting / Arduino Mega com port not free on: May 04, 2012, 10:18:49 am
Just got a Mega 2560

If I unplug it, then re plug it, I have to restart the computer before the com port becomes available again.

Most inconvenient
56  Community / Exhibition / Gallery / Re: YAAMI-DRUM, a 52 analog inputs trigger-to-midi drummachine on: March 25, 2012, 05:49:59 am
Hi Guys, sorry to butt in.

I've got two piezos hooked up directly to an arduino, with no mux shield, and no other sensors.  Could someone advise how to just take the code necessary to process the hits from these and send the midi out?  There's alot of other things going on in that sketch and it's confusing me!


Thanks
57  Development / Other Software Development / Re: Linux/Windows V0022/1.0 ethernet problem SOLVED on: March 16, 2012, 01:26:24 pm
thanks!
58  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet module freezing on: March 16, 2012, 01:16:03 pm
Didn't help sadly.

What behaviour should I be expecting here?

I'm sending packets 530 bytes in size, about 40 packets per second, with the following code -

Code:

#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(2, 0, 0, 101);

unsigned int localPort = 6454;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[1024]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged";       // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);

  Serial.begin(57600);
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if(packetSize)
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i =0; i < 4; i++)
    {
      Serial.print(remote[i], DEC);
      if (i < 3)
      {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(packetBuffer,1024);
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    // send a reply, to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
  delay(10);
}

The correct response is (with my packets)-
Received packet of size 530
From 2.0.0.1, port 6454
Contents:
Art-Net


Wheras most of the responses end up being something like-
Received packet of size 702
From 0.0.0.0, port 0
Contents:


or-
Received packet of size 20012
From 0.1.0.0, port 2
Contents:
É


And often the packet size value will rise to  just under 32000 before crashing.

I've tried flushing the buffer after each read with EthernetUdp.flush() which in theory would fix my problem (I don't care about lost packets).  But it just seems to make the crashes more frequent

grrrrrrrr
59  Development / Other Software Development / Re: Linux/Windows V0022/1.0 ethernet problem SOLVED on: March 16, 2012, 08:35:35 am
Where can I download the 1.0.1 rc?
60  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet module freezing on: March 16, 2012, 07:19:04 am
Thanks for the tip.

Tried it but it hasn't helped my issue
Pages: 1 2 3 [4] 5 6 ... 9