Troubles using serial communcation

Hello,

I’am using my Arduino for a while now, but yesterday I tried to use serial communiction to send commands from my macbook to my Arduino. To test the communication I used the Physical Pixel example but is doesn’t work.

I’ve set the ‘serialport’ at the ‘tools’ menu right, uploaded the example the the board, but I cant switch on the LED.
Today I have tested the code below, but the only thing I received in the monitor where some crazy characters.

const int ledPin = 13; // the pin that the LED is attached to
int incomingByte;      // a variable to read incoming serial data into

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
    digitalWrite(ledPin, HIGH);
  delay(300);
  digitalWrite(ledPin, LOW);
  delay(300);
  digitalWrite(ledPin, HIGH);
  delay(300);
  digitalWrite(ledPin, LOW);
}

void loop() {
    incomingByte = Serial.read();
    Serial.print(incomingByte);
}

Anybody with a solution?

void loop() {
    incomingByte = Serial.read();
    Serial.print(incomingByte);
}

Why are you reading data without seeing that there is data to read. You need to be using the Serial.available() function.

Also have you checked if the baud rate is 9600 on your Serial terminal display window (it's a dropdown at the bottom right after you open the Serial terminal on Arduino)? Crazy characters can appear if the Serial rate you set in your Serial terminal display window doesn't match the rate you set in your code.

In regard to your LED, have you first checked whether your LED is turning on, without any of the other code?