I have been experimenting with making my own Arduino Uno board. I have a breadboard version that works great, i connect the end of my USB cable into a CH340G chip, and that connects to the atmega328 chip via the Rx Tx and DTR (reset line). I can upload sketches and communicate over serial, everything works as expected.
I recently finished building my PCB version of the breadboard design. The only difference i can see is that i'm using SMD components (except the 328 chip, it's still the breadboard version, and can be removed) and it's not behaving how it should. This is going to sound weird, but i think the atmega328 chip only does the first line of code, and then just stops.
When i upload the Blink sketch, the IDE says "upload complete" etc, and shows no indication of anything going wrong. However when i look at the PCB, the led on pin 13 is not blinking, it's just constantly on (only pin 13 is HIGH). I push the reset button, and pin 13 does it's usual "reset light display", but it just goes back to keeping pin 13 high forever.
I change the code to put the led onto a different pin, and now only that pin is stuck on HIGH.
I change the code and put: digitalWrite(led,LOW); as the first line. Now the led does not turn on.
I change the code and put delay(5000); in the setup() loop. Led does not turn on now.
??
now it gets even stranger:
Next i uploaded the normal blink sketch onto the 328, then i removed the 328 from the PCB and put it into a genuine Uno device, power it up and the same thing happens, pin 13 is stuck on high.
Now i try and upload the blink sketch onto the 328 chip using the genuine Uno device, i remove the 328 chip and put it in my pcb, and guess what happens.. it blinks as it should !!!! ???
I (use the genuine arduino) upload a sketch that outputs the position of a potentiometer over serial, and put it into my pcb, and it works as it should, so serial output works too.
So now i'm stumped on how to approach this problem.
It's almost as if only part of the code gets uploaded when i try to upload using the PCB.
If i remove the 328 from the PCB and rewire the RX and TX lines from the CH340G chip to a HC-05 module, i can communicate with it without any problems using AT commands. ??
I've checked all my pcb traces, i do use a lipo battery to power, but i've tried a reliable power supply incase it's a power issue and the problem remains, and i never had a power problem when the lipo powered the breadboard version. I even added a 100uF cap across power and ground.
I'll admit that my PCB traces are a bit spaghetti like, with power lines and data lines jumping over and under each other, could it be that?
I've tried changing the board type i'm uploading to, Uno, nano, etc, they all just used to work, but not on the PCB version.