Martha MigliacioAlex Wong
Published © GPL3+

Using the Pmod AD1 with Arduino Uno

Application notes for Pmod AD1 & Arduino Uno. In this app, the result of the A/D conversion of channel A0 displays on the serial monitor.

BeginnerProtip1 hour3,088
Using the Pmod AD1 with Arduino Uno

Things used in this project

Story

Read more

Schematics

Pmod AD1 and Arduino Uno Fritzing file

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

Pmod AD1 and Arduino Uno Fritzing Image

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

Code

Pmod AD1 and Arduino Uno Code

Arduino
Using this code display the result of A/D conversion of channel A0 on the serial monitor.
/************************************************************************
*
* Test of the Pmod
*
*************************************************************************
* Description: Pmod_AD1
* The result of A / D conversion of channel A0 is displayed on the serial monitor.
* Material
* 1. Arduino Uno
* 2. Pmod AD1 
*
************************************************************************/

#define CS 10 // Assignment of the CS pin

#include <SPI.h> // call library

int i;
byte recu[3]; // storage of data of the module
int X;

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

void loop()
{
 digitalWrite(CS, LOW); // activation of CS line
 delayMicroseconds(20);
 for (i=0;i<2;i=i+1)
   {
   recu[i] = SPI.transfer(0); // send 2 data to retrieve the converted value on 2 bytes
   delayMicroseconds(20);
   }
 digitalWrite(CS, HIGH); // deactivation of CS line
 X = recu[1]; // X is in a 12 bit format
 X |= (recu[0] << 8);
 for (i=0;i<2;i=i+1) // Send in serial monitor
   {
   Serial.print("i");
   Serial.print(i);
   Serial.print("=");
   Serial.print(recu[i]);
   Serial.print('\t'); // tabulation
   }
 Serial.print("X=");
 Serial.println(X);
 delay(100);
}

Credits

Martha Migliacio

Martha Migliacio

5 projects • 20 followers
Alex Wong

Alex Wong

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

Comments