Atmega328p u standalone

Hello, im using an arduino uno to build a small project to generate 3 square signals on 3 different pins, everything works perfect as coded, i want to use the microprocessor outside the arduino uno board so i bought a atmega328p u with the bootloader installed, i uploaded the code onto the micro, i installed the chip in my breadboard 16 mhz crystal with 22pf caps, 10K ohms to reset as a pull up, 0.1mf caps on pin 22 and pin 7 as decouplers, but is not working, i removed the chip from the breadbord and installed into the arduini board and works perfect, installed onto the breadboard and nothing, any help? what do you think could be? maybe something with the fuses? ifuse, hfuse, efuse?

the fuses are on the chip, not on the board.
try to reset after power up.
or add capacitor 0.1µF from reset to GND

1 Like

hi kolaha, thanks for the reply, yes i know they are on the chip, i tought maybe i needed to set the fuses for standalone mode but also makes no sense since is already bootloaded, i installed the cap and reset but nothing.

show how you connected power to chip

full picture pls, with upper end

that is the whole circuit, is connected to a 5V regulated power supply

The circuit does not contain some necessary components

what else do i need to include?

It is certainly not the fuses if, as you have said, the new chip works perfectly well when it is installed on a Uno? board.
Show the program that you have loaded onto the new chip which you are using to test the bread board layout. I guess you loaded that program when the chip was installed on the Uno.

this is working perfect mounted on the arduino board

Please send code in txt

Are you sure the wire to the led is in Arduino pin 2 (your signalPin1) ?
The picture is not very clear but the pins on the chip run Reset, RX(0), TX(1) then pin 2, 3 etc. and it looks like that red wire could be in TX.

IMG_4137

const int signalPin1 = 2; // Pin for the first signal
const int signalPin2 = 3; // Pin for the second signal
const int signalPin3 = 4; // Pin for the third signal

const unsigned long signalPeriod = 250; // Period of 4 Hz in milliseconds
const unsigned long signalOnTime = signalPeriod * 0.3358; // 33% duty cycle on time

void setup() {
pinMode(signalPin1, OUTPUT);
pinMode(signalPin2, OUTPUT);
pinMode(signalPin3, OUTPUT);
}

void loop() {
// Signal 1
digitalWrite(signalPin1, HIGH); // Signal 1 ON
digitalWrite(signalPin2, LOW); // Signal 2 OFF
digitalWrite(signalPin3, LOW); // Signal 3 OFF
delay(signalOnTime);

// Signal 2
digitalWrite(signalPin1, LOW); // Signal 1 OFF
digitalWrite(signalPin2, HIGH); // Signal 2 ON
digitalWrite(signalPin3, LOW); // Signal 3 OFF
delay(signalOnTime);

// Signal 3
digitalWrite(signalPin1, LOW); // Signal 1 OFF
digitalWrite(signalPin2, LOW); // Signal 2 OFF
digitalWrite(signalPin3, HIGH); // Signal 3 ON
delay(signalOnTime);

pin 2,3,4 on the arduino are 4,5,6 on the atmega328pu

There are a couple of issues with the code:

  1. Incomplete loop() function: Your loop() function does not have the closing }.
  2. Integer truncation: The calculation for signalOnTime will result in an integer value because signalPeriod is of type unsigned long. Multiplying by 0.3358 will result in truncation of the fractional part. This may not be what you intend if you're aiming for precise timing.

Here is the corrected and completed version of your code:

const int signalPin1 = 2; // Pin for the first signal
const int signalPin2 = 3; // Pin for the second signal
const int signalPin3 = 4; // Pin for the third signal

const unsigned long signalPeriod = 250; // Period of 4 Hz in milliseconds
const unsigned long signalOnTime = signalPeriod * 0.3358; // 33% duty cycle on time

void setup() {
    pinMode(signalPin1, OUTPUT);
    pinMode(signalPin2, OUTPUT);
    pinMode(signalPin3, OUTPUT);
}

void loop() {
    // Signal 1
    digitalWrite(signalPin1, HIGH); // Signal 1 ON
    digitalWrite(signalPin2, LOW); // Signal 2 OFF
    digitalWrite(signalPin3, LOW); // Signal 3 OFF
    delay(signalOnTime);

    // Signal 2
    digitalWrite(signalPin1, LOW); // Signal 1 OFF
    digitalWrite(signalPin2, HIGH); // Signal 2 ON
    digitalWrite(signalPin3, LOW); // Signal 3 OFF
    delay(signalOnTime);

    // Signal 3
    digitalWrite(signalPin1, LOW); // Signal 1 OFF
    digitalWrite(signalPin2, LOW); // Signal 2 OFF
    digitalWrite(signalPin3, HIGH); // Signal 3 ON
    delay(signalOnTime);
}

However, if you want to maintain more precise timing and avoid integer truncation issues, you should calculate signalOnTime as a float and then cast it back to unsigned long:

const int signalPin1 = 2; // Pin for the first signal
const int signalPin2 = 3; // Pin for the second signal
const int signalPin3 = 4; // Pin for the third signal

const unsigned long signalPeriod = 250; // Period of 4 Hz in milliseconds
const unsigned long signalOnTime = static_cast<unsigned long>(signalPeriod * 0.3358); // 33% duty cycle on time

void setup() {
    pinMode(signalPin1, OUTPUT);
    pinMode(signalPin2, OUTPUT);
    pinMode(signalPin3, OUTPUT);
}

void loop() {
    // Signal 1
    digitalWrite(signalPin1, HIGH); // Signal 1 ON
    digitalWrite(signalPin2, LOW); // Signal 2 OFF
    digitalWrite(signalPin3, LOW); // Signal 3 OFF
    delay(signalOnTime);

    // Signal 2
    digitalWrite(signalPin1, LOW); // Signal 1 OFF
    digitalWrite(signalPin2, HIGH); // Signal 2 ON
    digitalWrite(signalPin3, LOW); // Signal 3 OFF
    delay(signalOnTime);

    // Signal 3
    digitalWrite(signalPin1, LOW); // Signal 1 OFF
    digitalWrite(signalPin2, LOW); // Signal 2 OFF
    digitalWrite(signalPin3, HIGH); // Signal 3 ON
    delay(signalOnTime);
}

This ensures the calculated signalOnTime retains the fractional part before being cast back to an integer type.Use code tags to format code for the forum

Did you move that pin ? This is from your post #7 which prompted my comment.

image