switch (command){
case 100:
//digitalWrite
long x,y;
if (VarParam[0] != -1)
x = VarParam[0];
else
x = (long)((instr[EIP] / 100000) - 10000);
if (VarParam[1] != -1)
y = VarParam[1];
else
y = (long)((instr[EIP] / 10000) - (100000 + x*10));
dwt(y, x);
break;
case 101:
long v,p;
v = (long)((instr[EIP] /100000)-10100);
p = (long)((instr[EIP] /10000)-(101000 + v*10));
use(v,p);
break;
case 102:
long x102 = (long)((instr[EIP] /1000000)-1020);
EPX = (int)x102;
break;
case 103:
long x103 = (long)((instr[EIP] /100000)-10300);
rst(x103);
break;
}
At case 103:, the error is "jump to case label".
I don't understand this error because in the previous line I explicit put a break; instruction.
Could you help me please?
Thanks! Jymmy097!
PS: if I remove the case 103: it works. And it even works if I remove case 102: (and not case 103:).
EDIT: here is the full error log:
JDUINO31.ino: In function 'void decode(int)':
JDUINO31:273: error: jump to case label
JDUINO31:270: error: crosses initialization of 'long int x102'
The switch statement does not like for you to define local variables, unless the entire case statement is a block.
case 100:
{
//digitalWrite
long x,y;
if (VarParam[0] != -1)
x = VarParam[0];
else
x = (long)((instr[EIP] / 100000) - 10000);
if (VarParam[1] != -1)
y = VarParam[1];
else
y = (long)((instr[EIP] / 10000) - (100000 + x*10));
dwt(y, x);
}
break;
PaulS:
The switch statement does not like for you to define local variables, unless the entire case statement is a block.
case 100:
{
//digitalWrite
long x,y;
if (VarParam[0] != -1)
x = VarParam[0];
else
x = (long)((instr[EIP] / 100000) - 10000);
if (VarParam[1] != -1)
y = VarParam[1];
else
y = (long)((instr[EIP] / 10000) - (100000 + x*10));
dwt(y, x);
}
break;
What does that comment have to do with anything?
Thanks a lot! I solved putting '{...} in each case statement.
The comment means that the code contained in 'case 100:' statement calls the digitalWrite procedure with dwt(y,x) command. I'm building a programmable robot for a project. I hope it'll work (I have Arduino Mega so I have more freedom in terms of memory used, but I don't know if 256 KB will be enough, I hope that they will.).
The MEGA 2560 only has 8KB or SRAM. That's where you store your variables. The 256KB is program code. I've not run out of program code in my projects. Lots of them are 3,000 lines and above just FYI. I did have to optimize SRAM though.
liudr:
The MEGA 2560 only has 8KB or SRAM. That's where you store your variables. The 256KB is program code. I've not run out of program code in my projects. Lots of them are 3,000 lines and above just FYI. I did have to optimize SRAM though.
If I set these string to null, will they occupy much space? If I set these strings to null, will they occupy space on Arduino?
Thanks a lot!!
If I set these strings to null, will they occupy space on Arduino?
What strings? A string is a NULL terminated array of chars. Setting the first element of the array to NULL or B or 8 makes no difference in the size of the array.
If I set these strings to null, will they occupy space on Arduino?
What strings? A string is a NULL terminated array of chars. Setting the first element of the array to NULL or B or 8 makes no difference in the size of the array.
I'm sorry, I've spoken about things that I haven't written in this post.
I've lots of String object in my Arduino project. How can I delete them from the SRAM when I don't need them anymore? Will they delete themselves when the procedure finish (they are not in the loop procedure, they are in other procedures)? I mean: when a procedure arrives to the end, the variables declared in that procedure will still occupy space in the arduino SRAM? Only global variables remains in SRAM until I reset arduino. Am I right?
liudr:
Variable scopes are more complicated than what you described. If you use Strings, you are recommended to switch to c-string like:
char my_text[]="hello world!";
You didn't give any evidence how you are using Strings so I can't speak specifically which ones will be removed when a process is over.
I mean this:
void setup(){
//some stuff here, no strings
}
void loop(){
//some stuff here, no strings
}
int SerialToNumber(){
String read = String();
//Code to read something from the serial port and append it to a String object
int number = read.toInt();
return number;
}
The problem is that I need a 1000-dimensions long array and I'm trying to use less SRAM I can.
I have two or three methods that use five/six strings object and I know that the String object is heavy.
My concern is that I won't have enough memory for the array. The array is global, but the strings are local (declared in methods) as seen in the example I gave you.
My question is: when a method arrives to the return directive, will the variables declared in its body be deleted or will they still occupy memory?
I have been used C# that has the garbage collector which destroys the objects when they are useless, so I'm not expert in C++ management memory.
Thanks!
Jymmy097
My question is: when a method arrives to the return directive, will the variables declared in its body be deleted or will they still occupy memory?
When you return local variables are removed. First the actual space for the is on the stack, and that stack is discarded when you return. And in the case of String variables the destructor will do a "free" and remove the space the string took.
Please note that in versions of the IDE up to and including 1.0.3, the String library has bugs as discussed here and here.
In particular, the dynamic memory allocation used by the String class may fail and cause random crashes.
I recommend reworking your code to manage without String. Use C-style strings instead (strcpy, strcat, strcmp, etc.), as described here for example.
So you are receiving things from serial port and parsing with String? Try again with strtok and sscanf. Arduino is a small 8-bit microcontroller. Also, why are you sending/receiving 1000 bytes of data? Can't you parse as you read or is it one of those very long German words that you have to buffer until the last character? You program ideas come from regular computers. Rethink when you use arduino.
I have arduino mega and the version of the ide I'm using is 1.0.4.
I need a so huge array (maybe I can try to go down to 600 or 700) because I need to store the instructions given from the user (I'm building a programmable robot with arduino) in a long array and then, when I switch to execution mode (the code you have entered is executed when a condition happens) these instructions will be decoded and executed by arduino. I succeded in turning on and off a led when a button is pressed only programming arduino from serial port. I told it to execute the program when the button connected to the 24th pin is pressed and then, to digitalWrite to the 23th pin the value 1 (High, I converted the 1 to high with an if clause, not using the function digitalWrite(xx, 1)) and then to finish the program.
Now I'm working with variables and they work properly (I could set a variable and use it in the digitalWrite instuction as the pin). Now I'm working on operations.
The command are sent using the serial port, but in the final project,they will be given by a keyboard, displayed on a LCD and then sent to arduino.
I'm now trying to reduce the SRAM used, for example using a unsigned int array for the variables or by reducing the arrays (now the instructions are 250, but I know I'll need more of them because I'm going to mount on arduino lots of sensors and a motor shield to make it move.
Thanks a lot: I'll try to use char arrays instead of Strings and I'll try strtok amd sscanf.
Jymmy097
Admire you trying to establish remote procedure calls between pc and arduino. I read some background but didn't actually do it. What about using one of these to increase your SRAM easily to 64KB or 512KB if you work a bit harder:
Sorry for the late, but I had much work to do in these days...
I added digitalRead, analogRead, analogWrite and the four operations to my project. I'll post the new programming languare (I called it JAL, but I don't remember why... I'll have to take a look to my notes) and all the project I'm doing in December 2013 because I don't want that the masters of the project think that I've copied the project in the net.
There is a mode to know how much SRAM I used for my variables?
Thanks!
Hi,
Thanks a lot for your help!
I'll post the code on the internet after the project!
Bye! PS. JAL = JDUINO Assembly Language, but I'm thinking about changing it: JDUINO Programming Language or JPL