Arduino standalone with ATmega328p TQFP

Hi to all,

I tried to convert my old PCB board based on ATmega328p DIP by using an ATMEGA328p TQFP-32.
I also tried to add a FT232R in order to be able to directly connect to the microcontroller by using a USB cable.
I use the header JP3 to connect a Wi-Fi card (the ESP8266 WiFi Module) which works at 3.3VDC, so I needed to include the LM1117 (3.3VDC, 800mA).
Since both the Wi-Fi module and the FT232R use the RX and TX port on the ATmega, I decided to use SoftwareSerial to use pins 11 and 10 as an additional serial port for the Wi-Fi. Since the pin 11 is also the MOSI used on the ICSP connector, I included a jumper JP4 to connect the MOSI to the ICSP connector if I will need to use it.

I would like to receive suggestions about some aspects:

  • I connected the FT232R:RX to the Arduino:TX, is it correct or do I need to directly connect the RX from the FT232R to the RX on the ATmega?

  • is the FT232R correctly connected? I connected the DTR to the ATmega RESET, is it correct?

  • the capacitors PC1 and PC2 used on the LM1117 are enough for this regulator? The datasheet suggests to use tantalum capacitors, but i don't think I will need these caps for my application.

  • The Wi-Fi module needs the level shifting since it is not capable to handle the 5VDC, so I used a voltage divider with R22 and R23 on the RX pin of the Wi-Fi module (pin 1 on the JP3). Is it OK?

  • any other suggestion on how to improve the schematics? Are there other errors?

Thank you!

I connected the FT232R:RX to the Arduino:TX, is it correct

That is correct.

I connected the DTR to the ATmega RESET, is it correct?

DTR should be connected to reset through (in series with) a 0.1uf cap.

The datasheet suggests to use tantalum capacitors, but i don't think I will need these caps for my application.

Deviate from the data sheet at your own risk. I use a 0.1uf in input and output and a 10uf tantalum on the output. Never had any trouble. 2200uf seems, to me, excessive.

The level shift for the ESP is good.

Do not connect 5V to Aref, just bypass Aref to ground with the 0.1uf cap. Aref is connected to Vcc internally when analog reference is default,

groundFungus:
DTR should be connected to reset through (in series with) a 0.1uf cap.

So, it should be OK since I connected C11 100nF between DTR and GND, is it OK?

groundFungus:
Do not connect 5V to Aref, just bypass Aref to ground with the 0.1uf cap. Aref is connected to Vcc internally when analog reference is default,

Thank you for this tip! I connected to ground the Aref by using a 0.1uF capacitor.

I made all the changes and I also replaced the capacitors on the LM1117 by using the tantalum ones.
Is it correct to use two capacitors in parallel at the output of the regulator? Or did I do a mistake?

C11 100nF between DTR and GND, is it OK?

No, one leg of the cap goes to DTR and the other leg goes to RESET (not ground). The cap supplies a short low going pulse to RESET when DTR goes low, Otherwise, since DTR stays low, the chip won't come out of reset.

Is it correct to use two capacitors in parallel at the output of the regulator?

Yes, that is correct. The 0.1uf to filter higher frequency noise and the 10uf to keep the output steady with varying loads (low frequencies) and add stability to the regulator.

Depending on the application, you may want to add a jumper to swap the ESP's RX/TX, in order to update the firmware. Being able to programming the ESP directly is a huge advantage in my eyes.

PieterP:
Depending on the application, you may want to add a jumper to swap the ESP's RX/TX, in order to update the firmware. Being able to programming the ESP directly is a huge advantage in my eyes.

Can you give me an example, please?
Do you mean to have the possibility to swap the RX and TX ports by using two jumpers?

@groundFungus: I will update the circuit and I will post it in a while, thank you

Programming the ESP8266 is much easier, and much more efficient than using AT commands. To program it, you need to access it from the computer over USB. You can do this by connecting ESP TX to FTDI RX and vice versa. This is the oposite of communicating with the ATmega.

PieterP:
AT commands and complex networking protocols
AT commands are a convoluted way to communicate with the ESP, and all code executes on the Arduino. AT commands only really support raw TCP and UDP, if you want to use protocols on top of that (e.g. HTTP, MQTT, OSC ...), all that code executes on your Arduino, using a lot of resources. Especially if you need to parse text-based requests requiring large or dynamic buffers.
It's also much, much harder to debug or to check for errors. If you program the ESP directly, you have high-level functions and classes for these protocols, that provide a simple interface and you can easily check if a function completed successfully by checking if it returned true or false. This makes error handling much simpler.
These libraries do not exist for AT commands, and even if they do exist, they are much less mature. Their documentation is often very poor, and the online resources are limited, because pretty much nobody uses them.

If you have to do multiple protocols at once (e.g. a HTTP web server and an OSC client), you can just about forget about it if you try to use AT commands.
Pretty much all code is blocking, because it uses the same Serial connection, and you can really only do one thing at once.

If you program the ESP directly, you can have many services running "in parallel". (e.g. a HTTP web server, an OSC client, a DNS server, mDNS server, OTA service ... all at once.)

Resource management
The Arduino has limited resources (32KiB flash, 2KiB or RAM and an 8-bit 16MHz CPU in case of the UNO) while the ESP is much faster and has many times more memory (4MiB flash, 64 KiB of instruction RAM, 96 KiB of data RAM, 32-bit CPU up to 160MHz).
So if you've got the choice, it makes sense to run all heavy networking code and text processing/parsing on the ESP, and save the resources of the Arduino for your actual microcontroller sketch.

Abstraction and code quality
My preferred approach is to have one piece of code on the ESP that connects to WiFi, sets up mDNS services, OTA update services, web servers, UDP listeners, MQTT clients ... whatever you need.
All code that receives and parses network requests runs on the ESP as well. If the ESP receives a command (e.g. "Turn on the lights"), it sends a command over serial to the Arduino (e.g. "Pin 16, HIGH").

On the other hand, if the Arduino wants to send something over the internet (e.g. to post the temperature to a database), it just sends it over serial to the ESP (e.g. "Temperature=21.3°C"), and the ESP takes this data, establishes a connection to the server, constructs a request, adds the right data, sends the request, checks the response, etc.

This greatly improves the readability and abstraction of both pieces of code. Having to mix networking stuff and microcontroller logic in one sketch is just really cumbersome.

For communication between the two MCUs, take a look at Robin2's Serial Input Basics.

Debugging
Another advantage is that you can test the microcontroller code without the ESP, by just using the Serial Monitor. The Arduino doesn't care if it's talking to an ESP8266 or to a human with a serial console.

You can also use UART1 on the ESP for printing debug information from the ESP, and UART0 on the Arduino for printing debug information from the Arduino.
If you use AT commands, debugging becomes a whole lot harder, especially if you use an UNO, where the only UART that is used for debugging over USB is also used for AT communication. This means that you can't read the responses from the AT firmware, only the commands sent by the Arduino.

Please don't take my word for it, try it yourself, and pick the approach you like the most.
I used AT commands when I got my first ESP8266, but ever since I discovered the ESP8266 Arduino Core for programming it directly, I've never touched AT commands again.

Whichever approach you pick, I'd recommend to get a dev board that supports both approaches.
At $3.50, there's really no valid argument against a WeMos D1 mini (clone).
Even if you decide to use AT commands, it will still be easier because you have a decent power supply on-board, and you can use the USB interface to update the AT firmware really easily.

I also think that using the esp as a simple WiFi adaptor for an ATmega is a waste. Its like towing a Ferrari with a golf cart, as I have said before. The esp is much faster, with more ram, flash etc. Just not many pins, even on an esp12/13. But that can be remedied with i2c I/o expanders which will be fast enough for most applications. But there are applications where the ATmega has the advantage, especially when trying to achieve very low power for battery circuits, for example. What projects do you have planned for your board?

Hello Paul, I need to control some solenoid valves.
The control circuit works very well on my previous board, but now I need to control the valves through Wi-Fi and so I would like to use the ESP.

So, my idea is to use a Wi-Fi router where I connect my laptop and the ESP. I will send text strings to the ESP and I will read them with the ATmega.

I don't know If I need to program the ESP multiple times, anyway I was thinking to do it by unmounting the module from the board and to attach it to a rs232 adapter to connect it to my computer.

Do you think that can be a good idea?

Well, solenoids does not sound like a battery powered circuit, so my approach would be to forget the ATmega, use a Wemos mini and tpic6b595 or tpic6a595 or similar to drive the solenoids. You can even update/reprogram the esp over WiFi direct from the Arduino IDE (an Over-The-Air or OTA update).

PaulRB:
Well, solenoids does not sound like a battery powered circuit, so my approach would be to forget the ATmega, use a Wemos mini and tpic6b595 or tpic6a595 or similar to drive the solenoids.

+1

The ESP8266 has 11 IO pins you can use, if that's not enough, you can use the shift registers PaulRB recommended. They could replace the drive circuitry you already have, or you could use low-power ones like the normal 74HC595 to control your solenoid drivers.

Take a look at this project I did a while back. It's just a web interface with toggle switches that turn the GPIO pins of the ESP on and off (it can be synced in real-time over multiple devices).

ESP8266/Control Panel

Thank you a lot for your support!

The problem is that I already have my well tested circuit based on the ATmega which works very well with the solenoids and so I would like to avoid to change it. Moreover, I was planning to do another version with xbee in place of the ESP in future.
In this way, I should change only the communication circuit by leaving all the rest of the circuit as it is. It is more easy for me.

I would like to ask you another question: do you think that 2A at 5VDC would be enough to power the system (atmega + ft232)?

Or I will have to go with 5A?

I know that the power consumption of the atmega is very low, the I was worried about the FT232.

I would be very surprised if the 328 + FTDI draws more than 100mA. The FTDI datasheet specs operating current at 15mA. The ESP 8266 could be drawing an additional (maybe) 300mA while transmitting. So 2A should be plenty.