how to load a txt file

hello

i have a very simple problem: my arduino is controlling a Stepper motor. the movement is based on information that is stored in a txt file.

i know how to control the stepper with the arduino and i know how to load and process the information from the txt file with processing. but i don't know how to do both together. can i load a txt file on the arduino or do i have to use processing and arduino together.

is there i simple example on how to do so?

thanks!

can i load a txt file on the arduino

If the file is static (never ever changes) and is especially small, then that may work.

do i have to use processing and arduino together

In general, that's a better solution.

is there i simple example on how to do so?

Someone else will be able to better help with that question.

This may help... http://www.arduino.cc/playground/Interfacing/Processing

This may work for you... http://www.firmata.org/ http://www.arduino.cc/playground/Interfacing/Firmata http://www.arduino.cc/en/Reference/Firmata

This may help... http://www.arduino.cc/playground/Code/Messenger

Or, you can roll your own by sending and receiving data through the Arduino's serial port.

GoBetwino will read a text file for you and send it's content back to Arduino one line at a time.

In your Arduino code you simply ask GoBetwino to execute a command that returns line number X from the file.

http://mikmo.dk/gobetwino.html

can i load a txt file on the arduino

Yes, there is no need for anything else apart from a library or so.

Look at the SDuFAT and other SD card libraries. You can then read from a text file.

I saw someone do something like this, taking commands from a text file, not too long ago but I can't remember what it was. There is the duino644 clock that takes text from an SD card and displays quotes from it on an LED matrix. That might help you... http://timewitharduino.blogspot.com/2009/10/testing-duino644-main-sketch.html

Mowcius

hey,

thanks for the help!!!

my processing is already starting to talk with my arduino, but they are misunderstanding each other all the time. :-?

i have this code in processing:

import processing.serial.*;
Serial port; 

void setup()  
{
  size(200, 200);
  frameRate(25);
  port = new Serial(this, Serial.list()[0], 9600);
}

void draw()
{  
  port.write(int(random(20)));
}

and this in arduino:

int val = 0;
void setup() {
    Serial.begin(9600);
}

void loop() {

  val = Serial.read();
  Serial.println(val); 

}

the numbers that i am sending are not coming back properly. if i use longer number is is getting worse. but sometimes it is working for a few numbers...

what am i doing wrong?

Before you read from the serial port on the Arduino, you should use Serial.available() to make sure that this is data to read.

Beyond that, without seeing how the numbers received differ from the numbers sent, I can’t offer any help.

Before testing with random numbers, I’d have the Processing sketch write the numbers from 0 to 254 to the serial port, and compare known values written to what was read. Perhaps that might provide a clue as to what is wrong.

thanks.

i changed the code:

import processing.serial.*;
Serial port; 
int i =0;

void setup()  
{
  size(200, 200);
  frameRate(25);
  port = new Serial(this, Serial.list()[0], 2400);
}

void draw()
{  
  i++;
  port.write(i);
}
int incomingByte = 0;
void setup() {
    Serial.begin(2400);
}

void loop() {

      if (Serial.available() > 0) {
            // read the incoming byte:
            incomingByte = Serial.read();

            // say what you got:
            Serial.print("I received: ");
            Serial.println(incomingByte, DEC);
      }


}

what i get is still only funky bits: the part that seems quite normal came out after i stopped processing

M?C?ceiv159 rece: 16 reced: I rved2 Ieive163 ecei 164 recd: 1I rved: I ive67 ceiv 168rece: 16I reed: I ived1 Ieiv172 ecei: 17 recd: I rved: Ieive76 ecei 177reced: 1I reed: I ived0 ceiv181 rece: 18 reced: I rved4 Ieive185 ecei 186 recd: 1I rved: I ive89 ceiv 190rece: 19I reed: I ived3 Ieiv194 ecei: 19 recd: I rved: Ieive98 ecei 199reced: 2I reed: I ived2 ceiv203 rece: 20 reed: I rved6 Ieive207 ecei 208 recd: 2I rved: I ive11 ceiv 212rece: 21I reed: I ived5 Iceiv216 ecei: 21 recd: I rved: Ieive20 ecei 221reced: 2I reed: I ived4 ceiv225 rece: 22 reed: I rved8 Ieive229 ecei 230 recd: 2I rved: I ive33 ceiv 234rece: 23I reed: I ived7 Iceiv238 ecei: 23 recd: I rved: Ieive42 ecei 243reced: 2I reed: I ived46 ceiv247 rece: 24 reed: I rved0 Ieive251 ecei 252 recd: 2I rved: I ive55 ceiv 0 ceiv1 ceiv2 Ieiv3 Ieive4 Ieive I eive I ive I ived I ived I rived I ived1 Ieive2 ceiv254 rece: 14reced: 1 recd: I reed: I rved: I rived I ived0 Ieive1 ceiv2cei 23 ecei: 24rece: 2 recd: 2 reed: I reved: I rved: I ived Ieive1 Ieiv32 ceiv 33 ecei 34rece: 35recd: 3 reced: I reed: I rved: I ived I ive1 Ieive42 ceiv43 ecei 44 ece: 45reced: 4 recd: 4I reed: I rved: I rved I ived1 Ieive3 Iceiv55 cei 57 ecei 58rece: 60 recd: 6 reed: I reed: I rved: I ived I eive1 Ieiv72 ceiv74 ecei 76 I received: 78 I received: 80 I received: 81 I received: 83 I received: 85 I received: 87 I received: 88 I received: 90 I received: 92 I received: 94 I received: 96 I received: 97 I received: 99 I received: 101 I received: 103 I received: 104 I received: 106 I received: 108 I received: 110 I received: 111 I received: 113 I received: 115 I received: 117 I received: 119 I received: 120 I received: 122 I received: 124 I received: 126 I received: 127 I received: 129 I received: 131 I received: 133 I received: 135 I received: 136 I received: 138 I received: 140 I received: 142 I received: 143 I received: 145 I received: 147 I received: 149 I received: 150 I received: 152 I received: 154 I received: 156 I received: 158 I received: 159 I received: 161 I received: 163 I received: 165 I received: 166 I received: 168 I received: 170 I received: 172 I received: 174 I received: 175 I received: 177 I received: 179 I received: 181 I received: 182 I received: 184 I received: 186 I received: 187 I received: 189 I received: 191 I received: 192 I received: 194 I received: 195 I received: 197 I received: 198 I received: 200 I received: 202 I received: 203 I received: 205 I received: 207 I received: 208 I received: 210 I received: 212 I received: 213 I received: 215 I received: 217 I received: 218 I received: 220 I received: 222 I received: 223 I received: 225 I received: 227 I received: 228 I received: 230 I received: 232 I received: 233 I received: 235 I received: 237 I received: 238 I received: 240 I received: 242 I received: 243 I received: 245 I received: 247 I received: 248 I received: 250 I received: 252 I received: 253 I received: 255 I received: 1 I received: 2 I received: 4 I received: 6 I received: 7 I received: 9 I received: 11 I received: 12 I received: 14 I received: 16 I received: 17 I received: 19 I received: 21 I received: 22 I received: 24 I received: 26 I received: 27 I received: 29 I received: 31 I received: 32 I received: 34 I received: 36 I received: 37

this is what i get with the same code on a mini arduini pro:

;ó[ch133]b[ch133]
jb[ch132]Eó¤¤E¤[ch131]bZD[ch131]JbDE[ch131]ED[ch131]E¥
[ch131]Åb:[ch131]Å [ch133]4[ch131]ÅbDc[ch133]; Dó[ch133]¦[ch132]¤DC[ch133]b[ch133]¤d£EbDE£[ch133]b[ch132]
£[ch133]$£[ch133]
£mbiF£ebyD£ibD£Db%"jbb[ch133]Fó¦B¤$£Ä
E£Äb$F[ch131]
b¤8[ch131][ch133]
E[ch131]zF[ch131]kbe[D[ch131]ieF[ch131]eb[ch133];[ch131][ch133] DE£Db
[ch133]Fób¦;£Ä ¤£Db£¤DcÄ[ch132]ECÄb[ch132]FcÄb¥cbDD>£Ä
DbD£hb£1[ch133]bEDóbDHE¤$£[ch132]
EI[ch132]b¤¤bZD[ch131]Lb¤Fb[ch131]FD[ch133]D[ch131]¤bDH[ch133]b£
[ch133]b%D󦤤E#[ch133]b¤:£[ch133]

£[ch133]"[ch132][ch133]
DC[ch133]b¥DI[ch133]b[ch133][ch133]b£
D£kbb;óz;ó¦1zDù;£[ch132] ¤EI[ch132]b
b[ch132]=[ch131]Ä
[ch132]DÄbFÄb[ch133]DXÄbD£db%£[ch132]b[ch133][ch133]¦b[ch133]Dó=£[ch132]
D£[ch132]bJE£kb$F£
b¤£
Ed[ch132]F£[ch132]bDb[ch132]FC[ch132]b<[ch132]
8óe
nbJEóJóDE¤D[ch133]"5£[ch133]
[ch132]D[ch133]b£
[ch133][ch133][ch133]
:££Kbb:ó[ch133]&bLE
b£Db¤£Äb¤EDb[ch132]:£Ä
8£Ä
¥[ch133]Äb[ch133]D£ÄbD£dbKbbDóó
[ch133]DûBD[ch132]b¤%£[ch132]"FH[ch133]bZ£bzE£JbzJbD£IbD[ch133]b{D£ID=£bD[ch133]¦5£[ch132]
¤#b¤;£[ch132]
¤£jbEkb[ch132]F£
bHDeF£dbeD£
bDóEib
¦[ch132]DóEóL£b£EKÄb[ch132]F£Äb¥¥DKÄb[ch133]FCÄbÄ£
£[ch132]bEb[ch133]óbzDó[ch132]¤DI[ch132]b¤E£[ch132]b£¤E£

Try to put a small delay in the loop, like

void loop() {

if (Serial.available() > 0) { // read the incoming byte: incomingByte = Serial.read(); delay(10); // say what you got: Serial.print("I received: "); Serial.println(incomingByte, DEC); }

}

this is what i get with the same code on a mini arduini pro:

And how are you connecting it up? It looks like the data is upsidedown as if you are feeding RS232 levels directly into the arduino.