Go Down

Topic: Read set up text file at compile (Read 7823 times) previous topic - next topic

maniacbug

Also, you can use xxd for this if you have binary data you want to bring in.

Code: [Select]

$ echo Hello > hello.txt
$ xxd -i hello.txt > hello.h
$ cat hello.h
unsigned char hello_txt[] = {
  0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x0a
};
unsigned int hello_txt_len = 6;

Daneel

I've got a workaround which I use which I could happily modify for you if you like:

I've made a batch file which copies the sketch and then searches through the sketch for placeholder values then replaces them with the values I want from a second file.  It'd be easy to modify it to work for what you'd like to do.

All you need to do is replace the values in your code with a placeholder, so for instance, if you had 11,12,13 before, now you put REPLACEME1,REPLACEME2,REPLACEME3

Then in the script you just make it search for those placeholders and replace them with 11,12,13 which would be stored in your 'config' file.  That way you end up with a new sketch file (or folder if you'd like that - I can make it do that) which had the test values in it.  Then you can keep it for the future too if you want to reuse those values.

If that sounds like what you're after then I'd be happy to rewrite it for you :)  let me know :)


As an aside - this sort of question is asked regularly..  I might try and generalise the rewrite so almost anyone can use it.

Asa Herring

I have thought about doing that using VB because I use to play with text like that a lot. Thanks for the offer. It is cool that I can get help in North Carolina from some one half way around the world.

If I am away from the arduino environment, I can hold my own as a hobbyist but I am dyslexic and didn't have enough back ground reading in the learning area to catch what was being said.  Luckily, I just got the code from liudr to work. I couldn't understand what he was going for at first but as I read more and he answered my newbie questions a light went off in my head and I started banging away at the key board.

It does exactly what I want it to do now. I can edit that text file and not take a chance of messing up good working code. There will be times when I will have to change the locations or the stations and tune the amounts of liquid. During these times, I will be constantly updating the file, either manually or with another quickie application. I sure don't want to dive down in the code six months from now and have to re-teach myself what I did before making a change. Of course the arrays do simplify the code quite a bit. I just discovered the serial window and it is great to see it jump through that stations, updating the distances and times as it goes. Automation is a wonderful thing.

This phase is fully complete. Thanks for everyone's help!
I have an Arduino Mega 2560. I also have a (pH) BNC Sensor Shield,an I2C/SPI/Onewire Shield(I beleive that it an on board clock.)and a Breakout Board Shield, all three are from Andrew Oke. Additionally, I have a Stepping Motor but could certainly buy a Servo Motor instead if it is any better for what I want to do, short term/long term. Trying to read the lable, I guess that it is: Type 57BYG. 12 V/Phase, 20ohm, 0-6A/Phase 1.8 Deg/Step, No. 04052 with a K179 Stepper Driver board attached. I can't confirm that the board is fully funtional

liuzengqiang

Very good! I myself learned something while helping you: I didn't know it would work?!

I then thought about it and tested it out on my arduino and it did! Good news for both of us. I'll be blogging this trick sometime today!

That's what a teacher does, learn himself and teach it like he knows it for decades  XD

Asa, you must be a good learner. Typical learners get easily discouraged and start blaming professors for giving them hard problems to solve. You went out yourself and look for solutions.

Any chance you attend the university named after your location?
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

Asa Herring

I went to Arizona State in the 70's…in sociology, which prepares you for everything and nothing. Now I and a commercial aerospace design engineer in Winston-Salem. Go figure. My daughter attends there studying Psychology but I heard that they have a good computer program.

You came up with a great answer very quickly. Honestly, I didn't do the requisite reading to implement your solution at first. I'm still not going to read all that I should because of the dyslexia so I will continue to be a pain when I get to other heralds in my project.

I have a few patents so I always come up with easy ideas that aren't that easy to do. One part of making them come to fruition is, not letting my ignorance get in my way.

After I didn't get it, I started googling this and found that know one was doing set up files, I really thought that I had bitten off more that I could chew.

Thanks for pulling me out of the fire.
I have an Arduino Mega 2560. I also have a (pH) BNC Sensor Shield,an I2C/SPI/Onewire Shield(I beleive that it an on board clock.)and a Breakout Board Shield, all three are from Andrew Oke. Additionally, I have a Stepping Motor but could certainly buy a Servo Motor instead if it is any better for what I want to do, short term/long term. Trying to read the lable, I guess that it is: Type 57BYG. 12 V/Phase, 20ohm, 0-6A/Phase 1.8 Deg/Step, No. 04052 with a K179 Stepper Driver board attached. I can't confirm that the board is fully funtional

liuzengqiang

I see. I remember there was a teaching position opening some years back at that university which I could have applied for but I can't say for sure :)

Since the text-based website has no information about your age, I assumed you were a college student. Well, you were :) My sociology colleagues are pretty good at pulling apart fabrics of lies woven around us :) I enjoy talking to them over lunch.

The code I gave you simply serves as replacement inside the compiler.

If you do:
#define Fubar 9

Then:
Every time the compiler sees Fubar, it replaces it entirely with 9, so if I have this in the latter part of the program:

if(damage==fubar) reparable=FALSE;

Then the compiler sees

if (damage==9) reparable=FALSE;

This way if later you decide damage level 7 is fubar, you don't have to change all the fubar in your program from 9 to 7, but just change the #define. It's the same principle of algebra, using symbols instead of numerical literals in various situations.

The #define is a pre-processor directive.



Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

Asa Herring

#21
Mar 30, 2011, 08:36 pm Last Edit: Mar 30, 2011, 09:04 pm by Asa Herring Reason: 1
Cool,

I guess that I could use this even if I didn't plan for it in advance. So I guess that I had better change my one digit character variables to two, now that I have them working. That way I can find them later.

int d[6]={d_val};                    int distance[6]={d_val};
int f[6]={f_val};         To         int ftime[6]={f_val};
int w[6]={w_val};                   int wtime[6]={w_val};

I'm sure that I will be asking more weird questions in different threads because now I'm a super programmer, on a roll! ...at lease in my own mind. :D

There are several things that I will need to do to actually get this feeder running well. I just need to understand the difference between necessary and cool and keep my eye on the ball.

Thanks again,
Asa (?sâ;) Herring
I have an Arduino Mega 2560. I also have a (pH) BNC Sensor Shield,an I2C/SPI/Onewire Shield(I beleive that it an on board clock.)and a Breakout Board Shield, all three are from Andrew Oke. Additionally, I have a Stepping Motor but could certainly buy a Servo Motor instead if it is any better for what I want to do, short term/long term. Trying to read the lable, I guess that it is: Type 57BYG. 12 V/Phase, 20ohm, 0-6A/Phase 1.8 Deg/Step, No. 04052 with a K179 Stepper Driver board attached. I can't confirm that the board is fully funtional

Go Up