0

I am doing a prototype using ATmega8L-8PU to detect temperature and control a relay and buzzer, but the schematic seems not work, therefore I do a simple test to verify the AVR's pins are working perfectly or not.

I using the example sketch - Blink to control Digital-13 to let LED blink. It is work.

Then I do a second sketch to test all pins (Due to leak of LED, I test first 8 pins.) It failed. Second Sketch is quite simple and strict forward: blink D0-D7 LED one by one.

char i, j, pcnt = 1;

char startDigitalPin = 0;
char maxDigitalPin = 7;

void setup()
{
    digitalWrite(13, HIGH);
    delay(100);
    digitalWrite(13, LOW);
    delay(100);

    digitalWrite(13, HIGH);
    delay(100);
    digitalWrite(13, LOW);
    delay(100);

    digitalWrite(13, HIGH);
    delay(100);
    digitalWrite(13, LOW);
    delay(100);

    // put your setup code here, to run once:
    for(i=startDigitalPin; i<=maxDigitalPin; i++) {
        pinMode(i, OUTPUT);
        digitalWrite(i, LOW);
    }
}

void loop()
{
    // put your main code here, to run repeatedly:
    digitalWrite(13, HIGH);
    delay(1000);
    digitalWrite(13, LOW);
    delay(1000);

    digitalWrite(13, HIGH);
    delay(1000);
    digitalWrite(13, LOW);
    delay(1000);

    digitalWrite(13, HIGH);
    delay(1000);
    digitalWrite(13, LOW);
    delay(1000);

    for(i=startDigitalPin; i<=maxDigitalPin; i++) {
        for(j=i; j<=maxDigitalPin; j++) {
            digitalWrite(j, HIGH);
            delay(100 * pcnt);
            digitalWrite(j, LOW);
            delay(100 * pcnt);
        }

        digitalWrite(i, HIGH);
        delay(200 * pcnt);
    }

    pcnt++;

    if(pcnt > 10) {
        pcnt = 1;
        delay(8000);
    }
}

Question:

  1. Why I using Blink example sketch, D13 is work fine, the LED light on with normal bright.
  2. Why second sketch, the D13 LED super dark, but it light on.

Check it out these 2 videos in youtube. https://www.youtube.com/watch?v=sknNPxqg5zc https://www.youtube.com/watch?v=KWsdP3egsvY

I have burn a bootloader to ATmega8L-8PU (Summary Datasheet) using Arduino IDE 1.6.5 with MiniCore, Config: ATmega8 External 8MHz.

Parts in my bearboard using:

  1. ATmega8L-8PU
  2. 2 x 22pf
  3. 1 x 100nf
  4. 1 x 8MHx crystal
  5. 9 x LED with 330Ohm resistor
  • 1
    You forgot the pinMode for pin 13, perhaps the led is blinking very dark with the internal pullup resistor of 50k. The MiniCore is not the official Arduino core. I think the OptiBoot comes with a small bootloader for the ATmega8, and perhaps you need an extra board in "boards.txt", but you can use the normal Arduino software. The resulting code is already small (don't use floating point). I see no need for a special MiniCore. – Jot Oct 25 '17 at 18:38
  • 1
    You forgot pinMode(13, OUTPUT) in the setup. – user31481 Oct 25 '17 at 18:43
  • Post your schematic. – user31481 Oct 25 '17 at 18:44
2

I tested your sketch after adding pinMode(13, OUTPUT) in the setup, and it works as you intended.

But, as you don't post your schematic, I was only able to chech on-board LED blinking.

void setup()
{
  pinMode(13, OUTPUT);

  for (int i=0; i < 3; i++) {
      digitalWrite(13, HIGH);
      delay(100);
      digitalWrite(13, LOW);
      delay(100);
  }

    // put your setup code here, to run once:
    for(i=startDigitalPin; i<=maxDigitalPin; i++) {
        pinMode(i, OUTPUT);
       digitalWrite(i, LOW);
    }
}

I also reduce your code using a for loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.