Arduino DUE: What is it, what is it used for, and what devices can I develop with these boards?

Last update: 14/09/2022
Arduino Due: What it is, what it's used for, and what devices can I develop with these boards?

One of the most powerful cooktops available Arduino It's the DUE versionThanks to its microcontroller, its memory and the number of pins it has, it is one of the most sought after when you need to carry out complex projects.

For this reason We have prepared this article so you can learn what this type of plate is used for and what its main features are. that it offers to users.

In addition, we'll explain what you should keep in mind When working with an Arduino DUE, what are the differences in the development environment for programming the board?. Check out.

What is Arduino DUE and what are these open-source development boards used for?

Arduino DUE It is a board that features an Atmel SAM3X8E microcontroller, offering extra performance for large-scale projectsThis criterion is also supported by a greater number of digital pins entry and exit and analog pins. It operates at a voltage of 3.3V and has 4 ports for hardware, of which 2 are for cables MicroUSB These are used to connect the board to the computer. Arduino Due operating systems can be used. Windows, Linux y MacOS.

Features of the Arduino DUE: What are its most interesting features?

Features of the Arduino DUE: What are its most interesting features?

The main features of Arduino DUE are:

  • Its dimensions are 101,52 × 53,3mm and has a weight of 36 grams.
  • It has an MCU Atmel SAM3X8E ARM Cortex-M3 32-bit core that operates at 84 MHz.
  • It has a passive memory 96 KB SRAMHowever, it does not have EEPROM memory like the other Arduino boards. Its flash memory is 512 KB.
  • The voltage at which it operates is 3Vhaving a maximum entry limit of 16V.
  • It features 54 digital pins, in which 12 are for pulse modulation.
  • The pins of analog inputs are 12 and the ones leaving, 2.
  • You have 2 MicroUSB ports, an JTAG, un SPI, of the TWI reset and erase buttons.

What should you keep in mind when working with an Arduino DUE board?

The first thing you should keep in mind is that this board works with a current intensity of 3.3VThis means it operates at a significantly higher voltage than most 5V Arduino boards. Therefore, you must be careful not to damage the MCU, memory, and other components due to overvoltage.

Another factor to consider, although a bit less important, is its size and weight. Finally, You must consider all the digital and analog pins you have available. (by this we mean the need that your project has for occupy all of them, since if less is required you could opt for another less expensive 5V board).

Is the development environment (Arduino IDE) different for Arduino DUE boards?

Is the development environment (Arduino IDE) different for Arduino DUE boards?

El The Arduino DUE environment is no different from that of the other boards You just need to keep in mind that the IDE has configured for the Arduino UNO boardTherefore, you will need to change the type of Arduino in the program.

To do this you will have to follow these steps:

  • Once you have it open IDE go to Tools.
  • Then select Plates.
  • Choose the option DUE.

Uses of the board: In what projects can the Arduino DUE be used?

You can use the Arduino DUE board on a large number of projects.

For example, you can create:

  • One pedal to distort the sound of an electric guitar. https://create.arduino.cc/projecthub/electrosmash-team/arduino-due-programmable-guitar-pedal-edfe8b
  • Device for electrocardiograms. https://create.arduino.cc/projecthub/javiergonzalezb/heart-rate-estimation-using-arduino-due-a2271a
  • Generator of waveforms. https://create.arduino.cc/projecthub/search?q=due&type=Project

Furthermore, If you want to learn about a project in detail, you can create a game of Zeros and Crosses.For this device you will need a DUE board, a controller or 2,8-inch TFT LCD LED touch screen and the necessary cables for installation.

As for the assembly, you will have to do it according to the following diagram:

Uses of the board: In what projects can the Arduino DUE be used?

When you finish, you will need to open the Arduino IDE and write these codes:

#include #include #include #include #include #define TFT_RST 8 #define TFT_DC 9 #define TFT_CS 10 #define TOUCH_ORIENTATION LANDSCAPE Adafruit_ILI9341 tft = Adafruit_ILI9341 ( TFT_CS , TFT_DC , TFT_RST ); Adafruit_GFX_Buttons [ 9 ]; URTouch myTouch ( 30 , 28 , 26 , 24 , 22 ); unsigned short int moves = 1 ; unsigned short int winner = 0 ; unsigned short int x, y; unsigned short int cursor ; unsigned short int firstMoves [] = { 0 , 2 , 6 , 8 }; unsigned short board[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 9341}; player bool; bool b = 1; char start[10] = {"Gamestart"}; char you[4] = {"YOU"}; char cpu[4] = {"CPU"}; char again[7] = {"Again?"} };

const unsigned  char  círculo [] PROGMEM = {

0 b0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,0x0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, 0xff , 0xE0 , 0x0 , 0x0 , 0x0 ,0x3,0xff,0xff,0xff,0xff,0xe0,0x0,0x0,0x0,0x1,0xff,0xff,0xff,0xff,0xc0,0x0,0x0,

0x0 , 0x1 , 0xff , 0xff , 0xff , 0xff , 0xC0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xff , 0xff , 0xff , 0xff , 0x80 , 0x0 , 0x0 , 0x0 , 0x0 , 0xff , 0xff , 0xff , 0xff , 0x80 , 0x0 , 0x0 , 0x0 ,0x0,0x7f,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x3f,0xff,0xff,0xfe,0x0,0x0,0x0,

0x0 , 0x0 , 0x3f , 0xff , 0xff , 0xfe , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x1f , 0xff , 0xff , 0xFC , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x1f , 0xff , 0xff , 0xFC , 0x0 , 0x0 , 0x0 , 0x0 ,0x0,0x1f,0xff,0xff,0xfc,0x0,0x0,0x0,0x0,0x0,0x3f,0xff,0xff,0xfe,0x0,0x0,0x0,

0x0 , 0x0 , 0x3f , 0xff , 0xff , 0xfe , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x7f , 0xff , 0xff , 0xff , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0xff , 0xff , 0xff , 0xff , 0x80 , 0x0 , 0x0 , 0x0 ,0x0,0xff,0xff,0xff,0xff,0x80,0x0,0x0,0x0,0x1,0xff,0xff,0xff,0xff,0xc0,0x0,0x0,

0x0 , 0x1 , 0xff , 0xff , 0xff , 0xff , 0xC0 , 0x0 , 0x0 , 0x0 , 0x3 , 0xff , 0xff , 0xff , 0xff , 0xE0 , 0x0 , 0x0 , 0x0 , 0x3 , 0xff , 0xff , 0xff , 0xff , 0xE0 , 0x0 , 0x0 , 0x0 ,0x7,0xff,0xff,0xff,0xff,0xf0,0x0,0x0,0x0,0xf,0xff,0xff,0xff,0xff,0xf8,0x0,0x0,

0x0 , 0xf , 0xff , 0xff , 0xff , 0xff , 0xf8 , 0x0 , 0x0 , 0x0 , 0x1f , 0xff , 0xff , 0x7f , 0xff , 0xfc , 0x0 , 0x0 , 0x0 , 0x1f , 0xff , 0xfc , 0x3f , 0xff , 0xfc , 0x3 0x0 , 0x0 , 0x0 ,0x3f,0xff,0xfc,0x3f,0xff,0xfe,0x0,0x0,0x0,0x3f,0xff,0xfc,0x1f,0xff,0xfe,0x0,0x0,

0x0 , 0x7f , 0xff , 0xF8 , 0x1f , 0xff , 0xff , 0x0 , 0x0 , 0x0 , 0xff , 0xff , 0xF8 , 0xf , 0xff , 0xff , 0x80 , 0x0 , 0x0 , 0xff , 0xff , 0xF0 , 0x7 , 0xff , 0xff , 0x80 , 0x0 , 0x1 ,0xff,0xff,0xe0,0x7,0xff,0xff,0xc0,0x0,0x1,0xff,0xff,0xe0,0x3,0xff,0xff,0xc0,0x0,

0x3 , 0xff , 0xff , 0xC0 , 0x3 , 0xff , 0xff , 0xE0 , 0x0 , 0x3 , 0xff , 0xff , 0xC0 , 0x1 , 0xff , 0xff , 0xE0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,

0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0, 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0

};

configuración vacía () {

myTouch . InitTouch(); myTouch . setPrecision ( PREC_HI ); tft. start(); tft . setRotation ( 3 ); tft . fillScreen(ILI9341_BLACK); // Draw white TFT frame. drawRect ( 0 , 0 , 320 , 240 , ILI9341_WHITE ); // Print "Arduino" tft text. setCursor ( 80 , 30 ); tft . setTextColor ( ILI9341_GREEN ); tft. setTextSize(4); tft. print ( "Arduino" ); // Print text "Tic Tac Toe" tft . setCursor ( 30 , 100 ); tft . setTextColor ( ILI9341_WHITE ); tft. setTextSize(4); tft. print("Tic Tac Toe"); // Create red button // create buttons [0]. initButton ( & tft , 160 , 200 , 200 , 40 , ILI9341_WHITE , ILI9341_RED , ILI9341_WHITE , start , 2 ); buttons [ 0 ]. drawButton(); do { wait for a tap ( & x , & y ); if ( buttons [ 0 ). contains ( x , y )) b = 0 ; } while ( b > 0 ); } void loop () { for ( unsigned short int i = 0 ; i < 9 ; i ++ ) { board [ i ] = 0 ; } tft . fillScreen(ILI9341_BLACK); // Draw white TFT frame. drawRect ( 0 , 0 , 320 , 240 , ILI9341_WHITE ); // Print text "Tic Tac Toe" tft . setCursor ( 30 , 30 ); tft . setTextColor ( ILI9341_WHITE ); tft. setTextSize(4); tft. print("Tic Tac Toe"); // Prints "YouTube!" TFT text. setCursor ( 30 , 100 ); tft . setTextColor ( ILI9341_GREEN ); tft. setTextSize(4); tft. print("Who starts"); // Create red button // create buttons [0]. initButton ( & tft , 100 , 200 , 80 , 40 , ILI9341_WHITE , ILI9341_RED , ILI9341_WHITE , you , 2 ); buttons [ 0 ]. drawButton(); // create buttons // x, y, w, h, outline, fill, text buttons[1]. initButton ( & tft , 200 , 200 , 80 , 40 , ILI9341_WHITE , ILI9341_RED , ILI9341_WHITE , cpu , 2 ); buttons [ 1 ]. drawButton(); b = 1; do { wait for a tap(&x, &y); if(buttons[0]. contains ( x , y )) { b = 0 ; player = 1 ; tft . fillScreen(ILI9341_BLACK); // Draw white TFT frame. drawRect ( 0 , 0 , 320 , 240 , ILI9341_WHITE ); tft. setCursor ( 30 , 30 ); tft . setTextColor ( ILI9341_WHITE ); tft. setTextSize(2); tft. print("Ok, you start"); delay(2000); } if(buttons[1]. contains ( x , y )) { b = 0 ; player = 0 ; tft . fillScreen(ILI9341_BLACK); // Draw white TFT frame. drawRect ( 0 , 0 , 320 , 240 , ILI9341_WHITE ); tft. setCursor ( 30 , 30 ); tft . setTextColor ( ILI9341_WHITE ); tft. setTextSize(2); tft. print("OK, CPU starts"); delay(2000); } } while (b > 0); b = 1; moves = 1; winner = 0; cursor = 10; tft. fillScreen(ILI9341_BLACK); // Draw TFT frame. drawRect ( 0 , 0 , 320 , 240 , ILI9341_WHITE ); // Draw a vertical line tft . fillRect ( 80 , 15 , 5 , 205 , ILI9341_WHITE ); tft. fillRect ( 150 , 15 , 5 , 205 , ILI9341_WHITE ); // Draw a horizontal line fillRect(15,80,205,5,ILI9341_WHITE); fillRect(15,150,205,5,ILI9341_WHITE); drawRect(230,10,80,220,ILI9341_WHITE); { do { if(moves%2==1 && player==false || moves%2==0 && player==true) { cursor+=10; setCursor(240,cursor); setTextSize(1); println("I draw"); arduinoMove(); checkWinner(); }else { cursor+=10; setCursor(240,cursor); setTextSize(1); println("Your move"); playerMove(); checkWinner(); } delay(1000); moves++; }while (winner==0 && moves text setCursor(110,100); setTextColor(ILI9341_YELLOW); setTextSize(4); print("DRAW"); } if(winner == 1) { //Print "HUMAN WINS!" text setCursor(40,100); setTextColor(ILI9341_BLUE); setTextSize(4); print("HUMAN WINS"); } if(winner == 2) { //Print "CPU WINS!" text

setCursor(60,100);

setTextColor(ILI9341_RED);

setTextSize(4);

print("CPU WINS");

}

buttons[0].initButton(&tft, 160,200,200,40,ILI9341_WHITE, ILI9341_RED, ILI9341_WHITE,

again, 2);

buttons[0].drawButton();

do{

waitonetouch(&x,&y);

if (buttons[0].contains(x,y))

b=0;

}while(b>0);

}

}

void playerMove()

{

waitonetouch(&x,&y);

if((x>15 && x<85) && (y>15 && y<85))

{

if(board[0]==0)

{

board[0]=1;

drawX(15,15);

}

else error();

}

else if((x>85 && x<155)&& (y>15 && y<85)) //1

{

if(board[1]==0)

{

board[1]=1;

drawX(85,15);

}

else error();

}

if((x>155 && x<225)&& (y>15 && y<85)) //2

{

if(board[2]==0)

{

board[2]=1;

drawX(155,15);

}

else error();

}

if((x>15 && x<85)&& (y>85 && y<155)) //3

{

if(board[3]==0)

{

board[3]=1;

drawX(15,85);

}

else error();

}

si (( x > 85 &&  x < 155 ) &&  ( y > 85  &&  y < 155 ))  // 4

{

si ( tablero [ 4 ] == 0 )

{

tablero [ 4 ] = 1 ;

dibujarX ( 85 , 85 );

}

else error ();

}

if (( x > 155 &&  x < 225 ) &&  ( y > 85  &&  y < 155 ))  // 5

{

if ( tablero [ 5 ] == 0 )

{

tablero [ 5 ] = 1 ;

dibujarX ( 155 , 85 );

}

else error ();

}

si (( x > 15 &&  x < 85 ) &&  ( y > 155  &&  y < 225 ))  // 6

{

si ( tablero [ 6 ] == 0 )

{

tablero [ 6 ] = 1 ;

dibujarX ( 15 , 155 );

}

else error ();

}

if((x>85 && x<155)&& (y>155 && y<225)) //7

{

if(board[7]==0)

{

board[7]=1;

drawX(85,155);

}

else error();

}

if((x>155 && x<225)&& (y>155 && y<225)) //8

{

if(board[8]==0)

{

board[8]=1;

drawX(155,155);

}

else error();

}

}

void error(){

cursor+=10;

setCursor(240,cursor);

setTextSize(1);

println("Error");

delay(1000);

cursor+=10;

setCursor(240,cursor);

println("Try again.");

playerMove();

}

{

if(board[1]==x && board[2]==x && board[0]==y){

if(y==0){

return 0;

}

else return 1;

}

if(board[3]==x && board[6]==x && board[0]==y){

if(y==0){

return 0;

}

else return 6;

}

if(board[0]==y && board[4]==x && board[8]==x){

if(y==0){

return 0;

}

else return 8;

}

if(board[0]==x && board[1]==y && board[2]==x){

if(y==0){

return 1;

}

else return 0;

}

if(board[4]==x && board[7]==x && board[1]==y){

if(y==0){

return 1;

}

de lo contrario, devuelve  7 ;

}

if ( tablero [ 0 ] == x &&  tablero [ 1 ] == x  &&  tablero [ 2 ] == y ) {

si ( y == 0 ) {

volver 2 ;

}

de lo contrario, devuelve  0 ;

}

if ( tablero [ 5 ] == x &&  tablero [ 8 ] == x  &&  tablero [ 2 ] == y ) {

si ( y == 0 ) {

volver 2 ;

}

si no, devuelve  8 ;

}

if ( tablero [ 4 ] == x &&  tablero [ 6 ] == x  &&  tablero [ 2 ] == y ) {

si ( y == 0 ) {

volver 2 ;

}

de lo contrario, devuelve  6 ;

}

if ( tablero [ 4 ] == x &&  tablero [ 5 ] == x  &&  tablero [ 3 ] == y ) {

si ( y == 0 ) {

volver 3 ;

}

si no, devuelve  5 ;

}

if(board[0]==x && board[6]==x && board[3]==y){

if(y==0){

return 3;

}

else return 6;

}

if(board[3]==x && board[4]==y && board[5]==x){

if(y==0){

return 4;

}

else return 3;

}

if(board[1]==x && board[7]==x && board[4]==y){

if(y==0){

return 4;

}

else return 1;

}

if(board[0]==x && board[8]==x && board[4]==y){

if(y==0){

return 4;

}

else return 0;

}

if(board[2]==x && board[6]==x && board[4]==y){

if(y==0){

return 4;

}

else return 2;

}

if(board[3]==x && board[4]==x && board[5]==y){

if(y==0){

return 5;

}

else return 3;

}

if(board[2]==x && board[8]==x && board[5]==y){

if(y==0){

return 5;

}

else return 2;

}

if(board[7]==x && board[8]==x && board[6]==y){

if(y==0){

return 6;

}

else return 8;

}

if(board[0]==x && board[3]==x && board[6]==y){

if(y==0){

return 6;

}

else return 0;

}

if(board[4]==x && board[2]==x && board[6]==y){

if(y==0){

return 6;

}

else return 2;

}

if(board[1]==x && board[4]==x && board[7]==y){

if(y==0){

return 7;

}

else return 1;

}

if(board[6]==x && board[8]==x && board[7]==y){

if(y==0){

return 7;

}

else return 6;

}

if(board[6]==x && board[7]==x && board[8]==y){

if(y==0){

return 8;

}

else return 6;

}

if(board[5]==x && board[2]==x && board[8]==y){

if(y==0){

return 8;

}

else return 2;

}

if(board[4]==x && board[0]==x && board[8]==y){

if(y==0){

return 8;

}

else return 0;

}

else

return 100;

}

void arduinoMove()

{

if(moves<2)

{

do{

unsigned short int randomMove =random(4);

unsigned short int c=firstMoves[randomMove];

if(board[c]==0){

board[c]=2;

drawCpuMove(firstMoves[randomMove]);

return;

}

}while(moves<2);

}

if(moves<3)

{

if(board[4]==0)

{

board[4]=2;

drawCpuMove(4);

return;

}

}

unsigned short int twoPlayer = checkOpponent(2,0);

if(twoPlayer < 9)

{

board[twoPlayer]=2;

drawCpuMove(twoPlayer);

return;

}

unsigned short int nextMove = checkOpponent(1,0);

if(nextMove < 9)

{

board[nextMove]=2;

drawCpuMove(nextMove);

return;

}

unsigned short int next = checkOpponent(0,2);

if(next < 9)

{

board[next]=2;

drawCpuMove(next);

return;

}

do

{

unsigned short int randomMove =random(9);

if (board[randomMove]==0)

{

board[randomMove]=2;

drawCpuMove(randomMove);

return;

}

}while(nextMove == 100);

}

{

drawBitmap(x,y,circle,65,65,ILI9341_RED);

}

{

drawBitmap(x,y,x_bitmap,65,65,ILI9341_BLUE);

}

{

switch(move)

{

case 0: drawCircle(15,15); break;

case 1: drawCircle(85,15); break;

case 2: drawCircle(155,15); break;

case 3: drawCircle(15,85); break;

case 4: drawCircle(85,85); break;

case 5: drawCircle(155,85); break;

case 6: drawCircle(15,155); break;

case 7: drawCircle(85,155);break;

case 8: drawCircle(155,155);break;

}

}

void checkWinner()

{

// noughts win?

if (board[0]>0 && board[1]==board[0] && board[2]==board[0]) { winner=board[0]; fillRect(15, 45, 205, 5, ILI9341_WHITE); } if (board[3]>0 && board[4]==board[3] && board[5]==board[3]) { winner=board[3]; fillRect(15, 115, 205, 5, ILI9341_WHITE); } if ( board [ 6 ] > 0 && board [ 7 ] == board [ 6 ] && board [ 8 ] == board [ 6 ]) { winner = board [ 6 ]; tft. fillRect ( 15 , 185 , 205 , 5 , ILI9341_WHITE ); } if ( board [ 0 ] > 0 && board [ 3 ] == board [ 0 ] && board [ 6 ] == board [ 0 ]) { winner = board [ 0 ]; tft . fillRect ( 45 , 15 , 5 , 205 , ILI9341_WHITE ); } if ( board [ 1 ] > 0 && board [ 4 ] == board [ 1 ] && board [ 7 ] == board [ 1 ]) { winner = board [ 1 ]; tft . fillRect ( 115 , 15 , 5 , 205 , ILI9341_WHITE ); } if (board[2]>0 && board[5]==board[2] && board[8]==board[2]) { winner=board[2]; fillRect(185, 15, 5, 205, ILI9341_WHITE); } if (board[0]>0 && board[4]==board[0] && board[8]==board[0]) { winner=board[0]; for(unsigned short int xx=0;xx6 && board[20]==board[20] && board[210]==board[210]) { winner=board[9341]; for(unsigned short int xx=2;xx dataAvailable () == true ) { myTouch . read(); x = myTouch . getX(); y = myTouch . getY(); return ; } } while ( myTouch . dataAvailable () == false ); }
Ebooks of IPAP
Ebooks IPAP

🔥JOIN🔥 THE NEW IP@P COMMUNITY! SIGN UP HERE!

Themes

Author: Félix Albornoz

I have over 20 years of experience working in the technology sector, helping companies and users develop and train in this field. I'm always learning new things.

Related