Martha MigliacioAlex Wong
Published © GPL3+

Using the Pmod DA2 with Arduino Uno

Application notes for Pmod DA2 and Arduino Uno. In this app, the output voltage of the Pmod is chosen by the user from the serial monitor.

BeginnerShowcase (no instructions)1 hour1,994
Using the Pmod DA2 with Arduino Uno

Things used in this project

Story

Read more

Schematics

Pmod DA2and Arduino Uno Fritzing file

Fritzing file displaying the connection of the Pmod DA2 to the Arduino Uno.

Pmod DA2 and Arduino Uno Fritzing Image

Fritzing image displaying the connection between the Pmod DA2 and Arduino Uno.

Code

Pmod DA2 and Arduino Uno Code

Arduino
Using this code will enable the the user to choose the output voltage from the serial monitor.
/************************************************************************
*
* Test of the Pmod 
*
*************************************************************************
* Description: Pmod_DA2
* The output voltage of the Pmod is chosen by the user from the
* Serial monitor
*
*
* Material
* 1. Arduino Uno
* 2. Pmod DA2
*
************************************************************************/

#define CS 10 // affectation of CS pin
#include <SPI.h> // Include library
char tableau[4] = {0,0,0,0};
int i = 0;
long valeur;
long consigne;
int consigne_basse;
int consigne_haute;
int val=0;
float tension;

void setup()
{
 Serial.begin(115200); // initialization of serial communication
 SPI.begin(); // initialization of SPI port
 SPI.setDataMode(SPI_MODE3); // configuration of SPI communication in mode 3
 SPI.setClockDivider(SPI_CLOCK_DIV16); // configuration of clock at 1MHz
 pinMode(CS, OUTPUT);
}

void loop()
{
 Serial.println("Enter the voltage in mV on 4 digits then Send");
 while (Serial.available()==0); // wait for data
 for(i = 0;i<4;i++) // Loop to write data in a table
  {
  tableau[i]=Serial.read();
  delay(1);
  }
 delay(100);
// recomposition du nombre tension
 valeur=1000*(tableau[0]-48)+100*(tableau[1]-48)+10*(tableau[2]-48)+(tableau[3]-48);
 consigne=4095*valeur;
 consigne=consigne/5000;
 consigne_haute=consigne>>8; // order high get 4 high bits order
 consigne_basse=consigne&0XFF; // order low get 8 low bits order
 digitalWrite(CS, LOW); // activation of the CS line
 SPI.transfer(consigne_haute); // Send order
 SPI.transfer(consigne_basse);
 delay(5);
 digitalWrite(CS, HIGH); // deactivation of CS line
 delay(100);
 Serial.print("La tension de consigne est : ");
 Serial.print(valeur);
 Serial.println(" mV");
}

Credits

Martha Migliacio

Martha Migliacio

5 projects • 18 followers
Alex Wong

Alex Wong

14 projects • 53 followers
I work in Digilent and like creating projects
Thanks to Lextronics.

Comments