Question

Yesterday, I started with some serial port communication. Today, I tried to open exactly the same sketch I used yesterday. It worked, but a few minutes later when I uploaded it again, it doesn't work at all.

Here's the code:

#include "Blink_main.h"

int pin = 1;

void pulsePin(int abc, int length){
    digitalWrite(abc, true);
    delay(length);
    digitalWrite(abc, false);
}

void setup() {
    pinMode(pin, OUTPUT);
    Serial.begin(9600);
    Serial.println("Hi serial!");
    pulsePin(pin, 1000);
}

void loop() {
    if(Serial.available() > 0){
            Serial.println(Serial.read());
            pulsePin(pin, 1000);
    }
}

When opening the application, I don't see the "Hi serial!" message, When sending something, I don't get a message back and I don't see the LED flashing. Why is this happening?

Was it helpful?

Solution

You are using pin 1 to blink the led, move the led to another pin since it is used as the serial TX

Digital Pins 0-1/Serial In/Out - TX/RX - These pins cannot be used for digital i/o (digitalRead and digitalWrite) if you are also using serial communication (e.g. Serial.begin).

OTHER TIPS

It look like the problem come from the Arduino board.

Firstly, try to upload a Serial example sketch. If it doesn't work, try to reinstall the driver or change the COM port used.

If the problem is still happening, it's probably the ATMEGA8U2 or ATMEGA16U2 which is dead. You can test with an external USB to UART convert directly on pins 0 and 1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top