Global Moderator
UK
Online
Brattain Member
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
|
 |
« Reply #15 on: November 06, 2011, 11:05:21 am » |
One more time. Change the 'long' array declarations to 'unsigned int'. Change the sizeof calculation to use unsigned int instead of long (a macro would be useful here). Job done, for now.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 334
Posts: 36443
Seattle, WA USA
|
 |
« Reply #16 on: November 06, 2011, 11:08:53 am » |
Job done, for now. At least it is if FreeMemory() reports enough memory remains as you continue adding more code.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
|
 |
« Reply #17 on: November 06, 2011, 11:20:55 am » |
Yeah, I know, but at least something will have been learned. More strings to your bow, and all that.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 31
Arduino rocks
|
 |
« Reply #18 on: November 06, 2011, 11:34:04 am » |
One more time. Change the 'long' array declarations to 'unsigned int'. Change the sizeof calculation to use unsigned int instead of long (a macro would be useful here). Job done, for now.
ok i did this now. Now i had a bit more free space and could add 5 more IF's. But now i'm again stuck only 79 free..
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
|
 |
« Reply #19 on: November 06, 2011, 11:40:07 am » |
So, go for the PROGMEM solution. Or go for the factoring and look up table solution. Sorry, there is no free lunch.
|
|
|
|
« Last Edit: November 06, 2011, 11:42:30 am by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 31
Arduino rocks
|
 |
« Reply #20 on: November 06, 2011, 02:48:06 pm » |
Ok as the first solution brought me to the edge of and with arduino i was searching for another solution  Now i always have just have one array in memory, that gets filled with the pulse values by serial communication. Via serial i can let the IR led blink when sending the "r" command. Somehow this only works once, so each time i send the "r" command the arduino is stuck and doesn't react on serial communication anymore. Can anyone see the problem? Here it is: #include <Messenger.h>
String deviceName = "LedRGBSteuerung"; char seperator = ','; int irLedPin = 13;
int maxMsgLength = 100; long msg[100]; int counter = 0;
Messenger message = Messenger(seperator);
void pulseIR(long microsecs) { // we'll count down from the number of microseconds we are told to wait cli(); // this turns off any background interrupts while (microsecs > 0) { // 38 kHz is about 13 microseconds high and 13 microseconds low digitalWrite(irLedPin, HIGH); // this takes about 3 microseconds to happen delayMicroseconds(10); // hang out for 10 microseconds digitalWrite(irLedPin, LOW); // this also takes about 3 microseconds delayMicroseconds(10); // hang out for 10 microseconds // so 26 microseconds altogether microsecs -= 26; } }
void blinkLed(long highTime, long lowTime) { pulseIR(highTime); delayMicroseconds(lowTime); }
void setup() { // Initiate Serial Communication Serial.begin(115200); // Attach the callback function to the Messenger message.attach(messageReady); //reset array resetMsg(); Serial.println(deviceName + " ready!!"); }
// Create the callback function void messageReady() { char firstChar = message.readChar(); // Gets the first word as a character if (firstChar == 'c') resetMsg(); else if (firstChar == 'a') { long value;
do { value = message.readLong(); //if not -1 is returned save value in array //and increase counter if (value != -1) { msg[counter] = value; counter++; } } while (value != -1); Serial.println("ADDED"); } else if (firstChar == 'r') { //let the led blink for (int i=0; i<maxMsgLength;i=i+2) blinkLed(msg[i], msg[i+1]); Serial.println("BLINKED"); } else if (firstChar == 'g') { //output of current array values Serial.print("On/Off: {"); for (int i=0; i<maxMsgLength;i++) if (msg[i] != -1) { Serial.print(msg[i]); Serial.print(","); } else break; Serial.println("}"); } else { Serial.println("UNKNOWN CMD"); message.readInt(); } }
void loop() { while ( Serial.available() ) message.process(Serial.read () ); }
void resetMsg() { counter = 0; for (int i=0; i<maxMsgLength;i++) msg[i] = -1; Serial.println("CLEAR DONE!"); }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 16
Posts: 1036
Arduino rocks
|
 |
« Reply #21 on: November 06, 2011, 03:00:54 pm » |
You turn off interrupts without turning them back on in pulseIR(). Serial communication depends on interrupts.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 334
Posts: 36443
Seattle, WA USA
|
 |
« Reply #22 on: November 06, 2011, 03:00:59 pm » |
Your code is very hard to read. When using else if, both words belong on the same line. For loops should always have { and }, even when not strictly needed. Random indenting and extraneous blank lines don't help.
When you send an r, I don't see that you reset the message instance, after processing the r.
I really can't see what value the Messenger library is adding to this sketch.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 31
Arduino rocks
|
 |
« Reply #23 on: November 06, 2011, 03:09:12 pm » |
You turn off interrupts without turning them back on in pulseIR(). Serial communication depends on interrupts.
oh thx i see it now, this was the problem thx a lot!!! You turn off interrupts without turning them back on in pulseIR(). Serial communication depends on interrupts. I really can't see what value the Messenger library is adding to this sketch.
How would you do it without using Messenger library for the serial communication?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 334
Posts: 36443
Seattle, WA USA
|
 |
« Reply #24 on: November 06, 2011, 03:22:52 pm » |
How would you do it without using Messenger library for the serial communication? I'd collect the data in a character array, and parse it myself. You know what you are sending, how the pieces are delimited, and what order the pieces are in. http://jhaskellsblog.blogspot.com/2011/05/serial-comm-fundamentals-on-arduino.html
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 31
Arduino rocks
|
 |
« Reply #25 on: November 07, 2011, 04:01:46 pm » |
ok, however finally it's nearly working perfect with messenger library and following sketch: #include <Messenger.h>
String deviceName = "LedRGBSteuerung"; char seperator = ','; int irLedPin = 13;
int maxMsgLength = 100; long msg[100]; int counter = 0;
Messenger message = Messenger(seperator);
void pulseIR(long microsecs) { // we'll count down from the number of microseconds we are told to wait cli(); // this turns off any background interrupts while (microsecs > 0) { // 38 kHz is about 13 microseconds high and 13 microseconds low digitalWrite(irLedPin, HIGH); // this takes about 3 microseconds to happen delayMicroseconds(10); // hang out for 10 microseconds digitalWrite(irLedPin, LOW); // this also takes about 3 microseconds delayMicroseconds(10); // hang out for 10 microseconds // so 26 microseconds altogether microsecs -= 26; } sei(); //turn on interrupts again }
void blinkLed(long highTime, long lowTime) { pulseIR(highTime); delayMicroseconds(lowTime); }
void setup() { // Initiate Serial Communication Serial.begin(115200); // Attach the callback function to the Messenger message.attach(messageReady); //array init resetMsg(); Serial.println(deviceName + " ready!!"); }
// Create the callback function void messageReady() { char firstChar = message.readChar(); // Gets the first word as a character if (firstChar == 'c') resetMsg(); else if (firstChar == 'a') { long value;
do { value = message.readLong(); //if not -1 is returned save value in array //and increase counter if (value != -1) { msg[counter] = value; counter++; } } while (value != -1); Serial.println("ADDED"); } else if (firstChar == 'r') { //let the led blink for (int i=0; i<maxMsgLength;i=i+2) if (msg[i+1]!=-1) blinkLed(msg[i], msg[i+1]); else break; Serial.println("BLINKED"); } else if (firstChar == 'g') { //output of current array values Serial.print("On/Off: {"); for (int i=0; i<maxMsgLength;i++) { Serial.print(msg[i]); Serial.print(","); } Serial.println("}"); } else { Serial.println("UNKNOWN CMD"); message.readInt(); } }
void loop() { while ( Serial.available() ) message.process(Serial.read () ); }
void resetMsg() { counter = 0; for (int i=0; i<maxMsgLength;i++) msg[i] = -1; Serial.println("CLEAR DONE!"); }
There is only one problem: If i send the messages too fast to Arduino, it get's stuck (IR Led is always on, Arduino doesn't react on serial commandos anymore). How to solve this?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 31
Arduino rocks
|
 |
« Reply #26 on: November 08, 2011, 03:22:36 am » |
Any ideas?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 31
Arduino rocks
|
 |
« Reply #27 on: November 10, 2011, 09:57:19 am » |
If i send the messages too fast to Arduino, it get's stuck (IR Led is always on, Arduino doesn't react on serial commandos anymore). How to solve this?
I experimented some more time regarding this issue. It seems that somehow a buffer (or even the RAM) is getting full when sending messages too fast to the Arduino. This causes the Arduino to be stuck completely (so i have to reset it / or replug the usb connector to get it working again). How to solve this?
|
|
|
|
|
Logged
|
|
|
|
|
|