Germany
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« on: November 06, 2012, 10:57:42 am » |
Hi all, I have a strange problem with my selfmade class. I want to use some DMX spots over WiFi, so I created a simple sketch for a client (Arduino+WiFi) and a sketch for a server (Arduino+Ethernet). For the server I wrote a class called DMX_RGB (see attached). I need to create some instances (globaly)in DMXNet_Server.ino: DMX_RGB Bar1("192.168.1.40",4711,10,11,12,9,8); When I create such an instance, the sketch stops and nothing happens anymore. Also no debug output on the serial monitor... If I comment out everything which is relating to the instance Bar1 (and of course the code above) the sketch works (also it is not doing what I want :-( ) I think it is a simple, stupid problem - but I cannot find where. Has anyone an idea? Thanks a lot, Holger
|
|
|
|
|
Logged
|
Perl is the only language that looks the same before and after RSA encryption.
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35535
Seattle, WA USA
|
 |
« Reply #1 on: November 06, 2012, 11:33:14 am » |
Has anyone an idea? I'm going to guess that you are running out of memory.
|
|
|
|
|
Logged
|
|
|
|
|
USA
Offline
Full Member
Karma: 0
Posts: 231
|
 |
« Reply #2 on: November 06, 2012, 11:35:23 am » |
I don't know what the function dbg does but I imagine it "prints" out characters over the serial link. My guess is that the UART isn't initialized yet. Try commenting out the dbg function calls in the constructor of DMX_RGB.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Tesla Member
Karma: 73
Posts: 6631
Arduino rocks
|
 |
« Reply #3 on: November 06, 2012, 01:06:17 pm » |
If its not a Mega you should check the amount of RAM in use - for instance what value is UDP_TX_PACKET_MAX_SIZE ?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #4 on: November 06, 2012, 03:15:37 pm » |
I agree with mkwired. You have probably fallen prey to the "static initialization order fiasco" (Google it).
I suggest you do a minimal number of things in your constructor (for example, save the arguments into class variables). Then make a DMX_RGB::begin() method and do the rest there.
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #5 on: November 07, 2012, 03:15:00 am » |
Hi all!
thanks for your hints. I wonder that one class instance would need so much memory. I will try your suggestions and write the solution to this thread as soon as possible.
Regards, Holger
|
|
|
|
« Last Edit: November 07, 2012, 03:23:58 am by Codeman »
|
Logged
|
Perl is the only language that looks the same before and after RSA encryption.
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35535
Seattle, WA USA
|
 |
« Reply #6 on: November 07, 2012, 05:55:19 am » |
I wonder that one class instance would need so much memory. There's this: byte _red; byte _green; byte _blue; byte _dim; byte _red_memory; byte _green_memory; byte _blue_memory; byte _dim_memory; float _steps; int _addr_red; int _addr_green; int _addr_blue; int _addr_dim; int _addr_mode; float _stepping_red; float _stepping_green; float _stepping_blue; byte _queue_red[MAX_FADE_ELEMENTS]; byte _queue_green[MAX_FADE_ELEMENTS]; byte _queue_blue[MAX_FADE_ELEMENTS]; float _queue_time[MAX_FADE_ELEMENTS]; int _queue_counter; int _q; int _step_counter; IPAddress remote_ip; uint16_t remote_port;
and this: void _DMXNet_send(uint16_t addr,uint8_t data); DMX_RGB(char* ip, uint16_t port,int addr_red, int addr_green, int addr_blue, int addr_dim,int addr_mode); void set_rgb(byte r, byte g, byte b); void set_red(byte r); void set_green(byte g); void set_blue(byte b); void set_dim(byte d); int get_steps(void); void fade_to(byte r, byte g, byte b, float time); void flash(byte flashes, int min_time, int max_time, int fade_time); void worker(void); void init(int cmd); That's not a trivial list of data fields or a trivial list of functions. For EACH instance.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Tesla Member
Karma: 73
Posts: 6631
Arduino rocks
|
 |
« Reply #7 on: November 07, 2012, 06:48:52 am » |
Methods are shared between all instances.
And 50 bytes or so isn't "massive".
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Edison Member
Karma: 45
Posts: 2237
What a host of balls she had seen: gaity, the brass buttons...
|
 |
« Reply #8 on: November 07, 2012, 07:00:56 am » |
Methods are shared between all instances.
And 50 bytes or so isn't "massive".
50? How big is MAX_FADE_ELEMENTS?
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #9 on: November 07, 2012, 07:18:24 am » |
Hi all, ok, I see, that my Uno is not a memory giant... and my class is not very small. But with MAX_FADE_ELEMENTS set to 10 the storage for one instance should be about 180 Bytes. I tried to use only _one_ instance and the Arduino freezes. Nick Gammon's hint was the solution (not for everything, but now it works!): The constructor was "too big" - don't ask me why this is a problem. But when rewriting the constructor function to a DMX_RGB.begin() method it works! Also four instances are working! I took a look at http://www.arduino.cc/playground/Code/AvailableMemory and checked my free memory and there were about 300 bytes empty. If anyone can explain why the constructor was the problem and why I should use a begin()-method for initialization I would be very glad! Thanks for helping! Holger 
|
|
|
|
|
Logged
|
Perl is the only language that looks the same before and after RSA encryption.
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35535
Seattle, WA USA
|
 |
« Reply #10 on: November 07, 2012, 07:24:21 am » |
The constructor was "too big" - don't ask me why this is a problem. It wasn't "too big". It was that the stuff that it did, it did when the rest of the processor was not ready for it to do things. Using the Serial instance, as an example, before the Serial instance has been created.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #11 on: November 07, 2012, 02:49:15 pm » |
PaulS is right. You really need to read up on "static initialization order fiasco".
The order in which static data is instantiated is undefined, particularly between compilation units. In your case, if you are using Serial, then Serial.begin() is done in setup, but if your dbg class uses Serial it will definitely be calling it too soon (the constructor will be called before setup).
The same remark applies to timers, and indeed anything related to Arduino libraries.
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #12 on: November 08, 2012, 02:54:30 am » |
Ok, I understand what my problem was.
Thanks for your help!
Holger
|
|
|
|
|
Logged
|
Perl is the only language that looks the same before and after RSA encryption.
|
|
|
|
|