No enough space in memory(SRAM) in Uno..Don't know why.. Need help!

Hi! I'm really new in arduino and this this is a new arduino uno that I bought 3 days ago. Really hope there is nothig wrong with the hardware.
I couldn't do Serial.read(), and so I set this code to check if there is available space in the memory.
This is the code, really simple one...

void setup() {
Serial.begin(9600);
if(Serial.available()==0){
Serial.println("error");
}
}
void loop() {
}

And it just keep saying "error" in serial monitor.. I dont know why... Anybody has the same experience with me?

I have already pressed the reset botton, and it doesn't work.

I set this code to check if there is available space in the memory.

There is nothing in that sketch that would show you available SRAM. All you are doing is printing 'error' all the while there is nothing in the Serial input buffer.

and so I set this code to check if there is available space in the memory

No that code checkes if there is any serial data in the buffer.
It will keep saying error forever. Because it only gets done once in setup it will never say anything else as a reset clears any previously received data.

Craiglin19:
And it just keep saying "error" in serial monitor.. I dont know why...

Well, given that the program you wrote outputs the string "error" to the serial port, and that output would show up in the serial monitor, what exactly is unexpected about what you are seeing?

If you change the string "error" to "everything A-OK!" perhaps that will be more encouraging? :wink:

Edit: Reading between the lines, I'm guessing you think the Serial.available() method reports on SRAM availability?

Serial.available() does something completely different: It tells you how many input character are in the serial input buffer waiting to be read by Serial.read(). So Serial.available()==0 will almost certainly always be true given you've placed this test in the setup section of your program.

Have a careful read of the references pages to the various functions and classes, and perhaps study some of the example sketch programs to see how things can fit together. Good luck!

Craiglin19:
Really hope there is nothig wrong with the hardware.

Your hardware is fine. Trust me on this one.

Craiglin19:
I have already pressed the reset botton, and it doesn't work.

Oh? What happened?

@Craiglin19 - Perhaps, if you posted the original sketch that was causing you problems, we could help you figure out why.

dxw00d:
@Craiglin19 - Perhaps, if you posted the original sketch that was causing you problems, we could help you figure out why.

Thats is all the Sketch xD

Nothing wrong with your hardware/software , just upload a diferent sketch from your example library.

Thanks everyone!! :slight_smile: That really helps a lot.But my problem is still there..

dxw00d:
@Craiglin19 - Perhaps, if you posted the original sketch that was causing you problems, we could help you figure out why.

Em this is the original sketch:

int incomingByte = 0; // for incoming serial data

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {

// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}

This is an example on arduino site, and when it's running, there's nothing happen on my serial monitor.. And this is the reason why I set that "check" code.

pico:
Edit: Reading between the lines, I'm guessing you think the Serial.available() method reports on SRAM availability?

Ya that's what I was thinking and now i know I'm wrong.. :slight_smile:

That sketch is waiting for you to enter something into the serial terminal for it to echo back. Did you try that?

try this

unsigned long seconds = 0;

void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {
                seconds = (millis()/1000);
                Serial.print("Seconds ");
                Serial.println(seconds);
                delay(1000);
        }
}

This code should display in seconds how long arduino is on

I think you might have an extra } in there...

...and a pair of ( ) that aren't needed.

Hi everyone! Thanks for help!!

I have figure the problem out! Really thanks everyone!

It's just you need to input something before it can print out something...

Really silly mistake..Sorry about that and thanks!! :slight_smile: :slight_smile:

BTW the read() convert everything to int, probably the reason why I thought there was an error at the first place