Sussex, UK
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« on: December 13, 2012, 03:50:34 am » |
I do a fair bit of programming in PHP and one can just put <?php include "myfile.php" ?> anywhere in the script to make editing the files easier. For my Arduino project I'm making some custom characters for an LCD display but putting #include "customchars.txt" doesn't work - I've tried with all sorts of file paths ("./customchars.txt" etc.) but no joy. Am I barking up the wrong tree?
|
|
|
|
« Last Edit: December 13, 2012, 07:07:23 am by spandit »
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Online
Shannon Member
Karma: 129
Posts: 10378
|
 |
« Reply #1 on: December 13, 2012, 03:57:19 am » |
...doesn't work... Didn't protect your favourite belt from the wild turkeys?
|
|
|
|
|
Logged
|
|
|
|
|
Sussex, UK
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #2 on: December 13, 2012, 03:59:42 am » |
...doesn't work... Didn't protect your favourite belt from the wild turkeys? I'm confused...
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Online
Shannon Member
Karma: 129
Posts: 10378
|
 |
« Reply #3 on: December 13, 2012, 04:06:52 am » |
"doesn't work" is meaningless to everyone except you and someone capable of reading minds (potentially over great distances). I am neither.
My response was a guess at what you meant by "doesn't work".
|
|
|
|
|
Logged
|
|
|
|
|
Sussex, UK
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #4 on: December 13, 2012, 04:08:11 am » |
"doesn't work" is meaningless to everyone except you and someone capable of reading minds (potentially over great distances). I am neither.
My response was a guess at what you meant by "doesn't work".
Ah, OK. It doesn't compile (verify fails saying it can't find the file specified). This was under Windows XP
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14101
Lua rocks!
|
 |
« Reply #5 on: December 13, 2012, 04:09:09 am » |
Post your code, not just "I did something and it didn't work" stuff. It doesn't compile ... Still post your code. What is this "it" of which you speak?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14101
Lua rocks!
|
 |
« Reply #6 on: December 13, 2012, 04:11:56 am » |
Just a heads-up. You have to tell the IDE about your files because it copies them all to another temporary folder. Just putting a file into the directory doesn't cut it. You have to make a new "tab" in the IDE.
|
|
|
|
|
Logged
|
|
|
|
|
Sussex, UK
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #7 on: December 13, 2012, 06:27:29 am » |
OK, to demonstrate, I took the example sketch "CustomCharacter" (from the LCD bit) and saved it as "CustomCharacterTest". I added a new tab, named it "custchars". I took the custom character definitions from the main sketch and moved them to this new tab. I then added the line #include "custchars.ino" Here's a screen grab of what happens when I click "Verify":  As you can see, it can't find the custom character definitions (which were unchanged from the example sketch) as it can't find the file "custchars.ino". I've tried putting "./" before the filename and even tried putting it in angular brackets (which oddly enough didn't cause a "no such file or directory" error, although the other errors were just the same
|
|
|
|
|
Logged
|
|
|
|
|
Sussex, UK
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #8 on: December 13, 2012, 07:06:57 am » |
OK, I changed the extension of the "custchars" to .h and after adding "#define byte uint8_t" to the top of the file (because I was getting a "byte does not name a type" error) and modifying the ambiguous lcd.write call, it now compiles OK #include <LiquidCrystal.h> #include "custchars.h"
// initialize the library with the numbers of the interface pins
void setup() { // create a new character lcd.createChar(1, heart); // create a new character lcd.createChar(2, smiley); // create a new character lcd.createChar(3, frownie); // create a new character lcd.createChar(4, armsDown); // create a new character lcd.createChar(5, armsUp);
// set up the lcd's number of columns and rows: lcd.begin(16, 2); // Print a message to the lcd. lcd.print("I "); lcd.write(1); // numbers above changed to stop ambiguous error call lcd.print(" Arduino! "); lcd.write(2); ...
Just waiting for my LCD to arrive so I can start playing with it properly! 
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Online
Shannon Member
Karma: 129
Posts: 10378
|
 |
« Reply #9 on: December 13, 2012, 01:46:28 pm » |
after adding "#define byte uint8_t" to the top of the file (because I was getting a "byte does not name a type" error) I suggest replacing that with... #include <inttypes.h>
|
|
|
|
|
Logged
|
|
|
|
|
Sussex, UK
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #10 on: December 13, 2012, 01:54:09 pm » |
after adding "#define byte uint8_t" to the top of the file (because I was getting a "byte does not name a type" error) I suggest replacing that with... #include <inttypes.h> If you say so! 
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14101
Lua rocks!
|
 |
« Reply #11 on: December 13, 2012, 04:18:08 pm » |
As you can see, it can't find the custom character definitions (which were unchanged from the example sketch) as it can't find the file "custchars.ino". If you make a tab which is not a .h, .c or .cpp file (in other words, another .ino file) the IDE concatenates it with your main sketch and compiles it as a single unit. You don't need to include it. Because of this behaviour it has probably not actually copied this other .ino to the temporary directory, and even if it had, you would then have used it twice, which you wouldn't want. You are better off sticking to the .h or .cpp paradigm (who includes .txt files into C source?) and work with the IDE on this one.
|
|
|
|
|
Logged
|
|
|
|
|
Sussex, UK
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #12 on: December 13, 2012, 05:59:02 pm » |
You are better off sticking to the .h or .cpp paradigm (who includes .txt files into C source?) and work with the IDE on this one.
Actually, I only put a .txt file for this forum - I was trying to include a .ino file but you say they are concatenated together (in alphabetical or tab order?). I'll stick to the .h for the headers and rejig my code to use the tabbed bits
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14101
Lua rocks!
|
 |
« Reply #13 on: December 13, 2012, 07:16:38 pm » |
Tab order I think (or is it?) Anyway, if you close and re-open the sketch I think it loads the files in the order it finds them. Not sure. That's why I don't use that "feature".
|
|
|
|
|
Logged
|
|
|
|
|
|