Central MN, USA
Offline
Faraday Member
Karma: 35
Posts: 5918
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #15 on: February 11, 2012, 10:40:06 am » |
Thanks for finding out the answer mmcp42. I guess F() is a part of the solution to SRAM problem but eventually becomes part of the FLASH problem. Does anyone know how to turn on optimization option for the compiler while using arduino ide?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 6
Posts: 1399
Arduino rocks
|
 |
« Reply #16 on: February 11, 2012, 11:42:19 am » |
I believe it's just a technique to avoid using "words" that people might already have in their program who in their right mind would use variables like __fred?!? Right. One would have to count (underscores) instead of read (words) 
|
|
|
|
|
Logged
|
|
|
|
|
Leighton Buzzard, UK
Online
Edison Member
Karma: 11
Posts: 1049
|
 |
« Reply #17 on: February 11, 2012, 11:54:14 am » |
this is a bit klunky, but might help (like I said, who in their right mind actually types __  ) __FlashStringHelper *myStrings[3];
void setup(void) { Serial.begin(19200); myStrings[0] = F("abcdefg"); myStrings[1] = F("xbcdefg"); } void loop(void) { Serial.println(myStrings[0]); Serial.println(myStrings[1]); delay(1000); }
|
|
|
|
|
Logged
|
there are only 10 types of people them that understands binary and them that doesn't
|
|
|
|
Massachusetts, USA
Offline
Tesla Member
Karma: 96
Posts: 6364
|
 |
« Reply #18 on: February 11, 2012, 01:26:51 pm » |
I think you can even initialize the array at compile time rather than run time. __FlashStringHelper *myStrings[] = {F("abcdefg"), F("xbcdefg")};
void setup(void) { Serial.begin(19200); } void loop(void) { Serial.println(myStrings[0]); Serial.println(myStrings[1]); delay(1000); }
|
|
|
|
|
Logged
|
|
|
|
|
Leighton Buzzard, UK
Online
Edison Member
Karma: 11
Posts: 1049
|
 |
« Reply #19 on: February 11, 2012, 01:50:15 pm » |
|
|
|
|
|
Logged
|
there are only 10 types of people them that understands binary and them that doesn't
|
|
|
|
Adelaide, South Australia
Offline
Full Member
Karma: 0
Posts: 135
Arduino rocks
|
 |
« Reply #20 on: February 11, 2012, 03:41:48 pm » |
can you clarify the origin of the F() syntax, is it from Mikal Hart's Flash library, or is it part of C or the standard IDE ?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 116
Posts: 10144
|
 |
« Reply #21 on: February 11, 2012, 04:13:23 pm » |
can you clarify the origin of the F() syntax, is it from Mikal Hart's Flash library That's how I was introduced to it.
|
|
|
|
|
Logged
|
|
|
|
|
Adelaide, South Australia
Offline
Full Member
Karma: 0
Posts: 135
Arduino rocks
|
 |
« Reply #22 on: February 11, 2012, 06:47:28 pm » |
so: (and this may seem a very dumb question)
if (I don't include the flash library in my sketch) { F() will not work? ;} endif
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
God Member
Karma: 0
Posts: 596
Arduino rocks
|
 |
« Reply #23 on: February 11, 2012, 07:24:25 pm » |
This sketch compiles and runs, so the answer seems to be no, one doesn't have to (explicitly) include Flash library to use F(). // F test
void setup() { Serial.begin(9600); Serial.println(F("STRINGA 1")); Serial.println(F("STRINGA 2")); }
void loop() { }
|
|
|
|
|
Logged
|
|
|
|
|
Adelaide, South Australia
Offline
Full Member
Karma: 0
Posts: 135
Arduino rocks
|
 |
« Reply #24 on: February 12, 2012, 05:09:07 am » |
doh! I could've done that ... excellent way to resolve my query, thanks mromani
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
God Member
Karma: 0
Posts: 596
Arduino rocks
|
 |
« Reply #25 on: February 12, 2012, 06:16:01 am » |
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 13
|
 |
« Reply #26 on: March 23, 2012, 10:22:24 am » |
Could someone please help me out with this, I am unable to get the F() macro compiled on FreeBSD. I am using avr-gcc and the arduino 1.0 codebase. The following line Serial << F("This is a test string"); throws up an error by the compiler which says flash_streaming.cpp:210:13: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away qualifiers I apologize for cross posting, but I already asked the same question in an earlier post - but didn't make any headway http://arduino.cc/forum/index.php?topic=95572.newThe command I am issuing is - avr-gcc tst.cpp -mmcu=atmega328p -DF_CPU=16000000UL -Os -w -Wl,--gc-sections -ffunction-sections -fdata-sections -DARDUINO=100 -I /home/rr/code/arduino//include/arduino/ -I . -c -o tst.o
|
|
|
|
|
Logged
|
|
|
|
|
USA
Offline
Full Member
Karma: 0
Posts: 231
|
 |
« Reply #27 on: March 23, 2012, 10:25:59 am » |
Serial << F("This is a test string");
Try Serial.print( F("This is a test string") );or Serial.println( F("This is a test string") );
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 13
|
 |
« Reply #28 on: March 23, 2012, 10:35:24 am » |
It has nothing to do with the << operator, even Serial.print(F("Hello World")) has the same problem. Serial.print(F("Hello World")); gives tst.cpp:19:18: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away qualifiers
I have a medium sized multi-file sketch compiling and functioning using avr-gcc, so there is no problem in general with compiling/linking etc. But this particular issue has me puzzled.
|
|
|
|
|
Logged
|
|
|
|
|
USA
Offline
Full Member
Karma: 0
Posts: 231
|
 |
« Reply #29 on: March 23, 2012, 10:37:02 am » |
What version of avr-gcc are you using?
|
|
|
|
|
Logged
|
|
|
|
|
|