Go Down

Topic: The HATRED for String objects - "To String, or not to String" (Read 31795 times) previous topic - next topic

GoForSmoke

328P has 2k for heap and stack. That's not much room to have storage elements that copy themselves just to add 1 character, not to mention what that could do in time-critical apps.

I see the String Object school play down awareness of both hardware and what the software is doing. They learn to use/reply on wasteful black boxes and don't bother with simpler more direct code. That's okay when you're not pushing much more than halfway to limits. But step much beyond and then your ability to implement solutions begins with learning what you avoided for however long you did including different approaches to solutions that go with all that. 

It's easier to match the tools (commands and techniques) to the environment. AVR's tend to be very small to small. What is trivial on a PC is not always going to fit well on an AVR. A bathtub that goes well in a house will be a poor fit on a bicycle regardless of the fact that yes you can fit a bathtub on a bicycle. Oh well let's be reasonable and just fit on a sink instead shall we?

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

nickgammon


Don't expect any of the "string" advocates to fix your code using the "string" functions, most likely due to the fact that the real code issue rarely ever has to do with using Strings. If persons can't wrap their head around the real issue, or are just stumped, they can always say "praise Jesus, drink more milk, and don't use Stings". Maybe the cure..., maybe not.


Better read this then:

http://forum.arduino.cc/index.php?topic=172156.msg1284047#msg1284047


So reworking the arduino code to utilize C++ chars rather than strings seems to have solved the problem with it acting inconsistently.


Another happy customer, once he removed "String".
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

zoomkat



Don't expect any of the "string" advocates to fix your code using the "string" functions, most likely due to the fact that the real code issue rarely ever has to do with using Strings. If persons can't wrap their head around the real issue, or are just stumped, they can always say "praise Jesus, drink more milk, and don't use Stings". Maybe the cure..., maybe not.


Better read this then:

http://forum.arduino.cc/index.php?topic=172156.msg1284047#msg1284047


So reworking the arduino code to utilize C++ chars rather than strings seems to have solved the problem with it acting inconsistently.


Another happy customer, once he removed "String".


What was really said :

Quote
So reworking the arduino code to utilize C++ chars rather than strings seems to have solved the problem with it acting inconsistently. The flicker that remained ended up a simple fix. I shortened the length of the wires connecting the buffers as much as physically possible (approximately an inch). I am still unsure why it only was a problem with the Uno and not the Duemilanove. Regardless, it works perfectly on both now. I am attaching a photo of the 1st panel running on the Raspberry Pi with an Uno (Left) and a Duemilanove (Right). All addresses work perfectly and no flicker.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

PeterH


What was really said :

Quote
So reworking the arduino code to utilize C++ chars rather than strings seems to have solved the problem with it acting inconsistently. The flicker that remained ended up a simple fix. I shortened the length of the wires connecting the buffers as much as physically possible (approximately an inch). I am still unsure why it only was a problem with the Uno and not the Duemilanove. Regardless, it works perfectly on both now. I am attaching a photo of the 1st panel running on the Raspberry Pi with an Uno (Left) and a Duemilanove (Right). All addresses work perfectly and no flicker.



The inconsistent behaviour was resolved by removing the use of the problematic String class, as Nick Gammon indicated by his quote. The fact that there was also a hardware issue causing flickering is hardly relevant to this thread.

GoForSmoke



What was really said :

Quote
So reworking the arduino code to utilize C++ chars rather than strings seems to have solved the problem with it acting inconsistently. The flicker that remained ended up a simple fix. I shortened the length of the wires connecting the buffers as much as physically possible (approximately an inch). I am still unsure why it only was a problem with the Uno and not the Duemilanove. Regardless, it works perfectly on both now. I am attaching a photo of the 1st panel running on the Raspberry Pi with an Uno (Left) and a Duemilanove (Right). All addresses work perfectly and no flicker.


I'm not satisfied with clues but that comes from years of debugging. So I went to that thread and ASKED the poster what that meant. Apparently Strings are Arduino code where char arrays are C++ to the beginner.
There's also the "reworking" part that you might have 'got' if you had looked at the original String-based code and the posts saying to ditch Strings, etc, that should have told you that the post you quoted does NOT actually support your view.
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

zoomkat



What was really said :

Quote
So reworking the arduino code to utilize C++ chars rather than strings seems to have solved the problem with it acting inconsistently. The flicker that remained ended up a simple fix. I shortened the length of the wires connecting the buffers as much as physically possible (approximately an inch). I am still unsure why it only was a problem with the Uno and not the Duemilanove. Regardless, it works perfectly on both now. I am attaching a photo of the 1st panel running on the Raspberry Pi with an Uno (Left) and a Duemilanove (Right). All addresses work perfectly and no flicker.



The inconsistent behaviour was resolved by removing the use of the problematic String class, as Nick Gammon indicated by his quote. The fact that there was also a hardware issue causing flickering is hardly relevant to this thread.


Perhaps you missed the "I am still unsure why it only was a problem with the " part above. Obviously the OP had two different hardware setups (Uno and Duemilanove) on which he was originally getting different results. He made both code and hardware changes on the uno setup and got his desired results. Probably different microcontrollers on the two boards with different memory capacities requiring "string" usage on the one with less memory or less efficient memory handling.

Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

PeterH

If you're getting memory corruption then even trivial changes could potentially affect the symptoms - simply choosing a different board type could be enough, if it affects the resulting executable image.

Docedison

In the posted PDF of the TLC5490 driver there are several errors that could well be a part of the issue. The power supply is a 7805 with minimal I/O bypassing, there is no current limiter/CC supply for the LED's and the comment about lead length's is really snarky... rather than indicate a fix it indicates bypassing problems and/or a lack of terminations (Pull-ups/downs) on the control lines. While Strings are certainly responsible for many of the issues, that the completed design works at all is to me a wonder.. I had to make those mistakes myself many years ago and learn from them.

Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Go Up