May 14, 2017

4. Arduino MEGA 2560

WHY?


The grandiosity of the plans we have for our mighty robot raised some concerns. Can a single Arduino UNO carry on all the tasks we expect? At that time we did not trust much the wires-saving technologies like I2C or SPI. So we thought, first of all, we will quickly run out of available Arduino ports.

The calculations were the following:

Module Required Arduino ports
Electric Motors Driver 6 for motors + 2 for Hall sensors
Ultrasonic Distance Sensor (robots with such sensor look pretty like Wall-E, so, no doubt, we also need this one) 2
Servo for the Ultrasonic Distance Sensor (robots which can turn their "head" and "look" here and there get +500 to cuteness, so, no doubt, we need this as well) 1 (PWM)
WiFi ESP13/ESP8266 - for the Remote Control 2
Edge detection sensor 2x (at least) 2
LED illumination (robot should have headlights, backlights, maybe even more than this) 3 (this function is a good candidate to use shift register and SPI)
Beeper 1 (PWM)
Sound module (MP3?) 4
Microphone 1 Analog In
LCD screen text-only 2 Analog In (if I2C will be used)

As you see — up to 20 pins can be consumed easily just for such basic functions. It is really too much for UNO.

Other serious limitation - memory size. Even if image and sound recognition will not be performed by the Arduino itself, the basic operations still consume a lot of resources. Managing all connected components requires adding more and more code to the firmware. Sooner or later we will exceed  UNO's memory limit.

The next level in the Arduino boards tribe is occupied by Arduino MEGA 2560. It brings more power, has more input/output ports and more memory. Power consumption is comparable to UNO, and the price is just $5 higher.

Arduino MEGA2560 Board


Features comparison reassured our choice.

Board Mega 2560 UNO
CPUATmega2560 ATmega328P
Work/
Input Voltage
5 V / 7-12 V 5 V / 7-12 V
CPU Clock 16 MHz 16 MHz
Analog inputs/outputs 16/0 6/0
Digital pins/PWM 54/15 14/6
EEPROM [kB] 4 1
SRAM [kB] 8 2
Flash [kB] 256 32
USB Regular Regular
UART 4 1

Arduino MEGA 2560 to some extent is identical to Arduino UNO. At least the leftmost 3 inches😊

Arduino MEGA2560 vs UNO


The board was designed to have exactly the same contacts located at the same places within those leftmost 3 inches. That's why all shield boards, designed for Arduino UNO, should also fit Arduino MEGA and work the same way.

We discovered only one shield which is incompatible with Arduino MEGA out of the hundreds of available shields. It is Video Experimenter. We definitely do not plan to use it in our robot, so nothing to worry about.

Other important differences to take into account:
  • I2C pins were moved from A4-A5 (UNO) to 21 and 21 (MEGA)
  • 3 extra hardware serial interfaces added to the board. This simplify connection of WiFi boards or similar modules which use UART interface
  • Usage of the libraries Tone and Servo does not harm PWM functionality at ports 3, 11, 9 and 10. Yet, when you connect more than 11 servos to MEGA, you will lose PWM at ports 11 and 12.

When you choose your board - make sure the name contains "2560". Preferably it should also include "R3". This is the most recent version which replaced the previous one.

Our choice was Geekcreit™ Mega2560 R3 ATmega2560-16AU. To be more precise - we've got it in a kit with 3.2 inch TFT LCD screen. That screen is put aside - maybe we'll use it in some other project.

We had quite mixed experience with online purchases from the manufacturers in China. Usually, you can't predict the quality of the ordered item. Electronics from Geekcreit is the best proof that there are companies there, which care about reputation and the products quality. Everything we've got from this brand was built perfectly well. Our Mega 2560 board is not an exception. All joints are soldered carefully and neatly. The PCB is clean and accurate. All sockets are straight and solid. Among other electronics suppliers from China - Geekcreit for sure goes to the top of the list.

HOW?

It is time to choose a final placement layout for the electronic boards at our chassis. The chassis plates are scattered with lots of different portholes and hatches. But this did not help -  we could not find any combination to match the Arduino MEGA board mounting points. That's why we had to place a mounting layer to install the board into the chassis.

Board holder

First, we cut a piece of a transparent plastic plate (from the old CD box) and screwed Arduino MEGA on top of it. Then - we installed this plate with the board at the chassis using standard holders which are used, for example, to mount motherboards inside PC. You can also attach the plate right to the chassis. Fortunately, there are no special requirements for ventilation or whatever. Arduino is a reliable and robust platform - it can survive even in a cardboard box glued with a sticky tape.

Arduino board mounted on a plastic plate - 1

Arduino board mounted on a plastic plate - 2


As a result - our board stays solid and looks nice on a chassis. It is convenient to connect wires and lead them around the board.

In the next post let's talk about how to drive the DC motors and make the robot finally moving around.

No comments:

Post a Comment