Martha MigliacioAlex Wong
Published © GPL3+

Using the Pmod JSTK with Arduino Uno

Application notes for Pmod JSTK and Arduino Uno. In this app, the Pmod JSTK will be used to control LEDs with button pushes.

BeginnerShowcase (no instructions)1 hour988
Using the Pmod JSTK with Arduino Uno

Things used in this project

Story

Read more

Schematics

Pmod JSTK and Arduino Uno Fritzing file

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

Pmod JSTK and Arduino Uno Fritzing Image

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

Code

Pmod JSTK and Arduino Uno Code

Arduino
Using this code, X and Y values will display in the serial monito table, and LEDs LD1 and LD2 will light up when BTN1 and BTN2 are pushed.
/************************************************************************
*
* Test of the Pmod 
*
*************************************************************************
* Description: Pmod_JSTK
* X and Y values will be shown in serial monitor in a table
* and LEDs LD1 and LD2 will light on when
* BTN1 and BTN2 are pushed.
*
*
* Material
* 1. Arduino Uno
* 2. Pmod JSTK
*
************************************************************************/

#define CS 10 // affectation of CS pin
#include <SPI.h> // Include library
int i;
byte recu[6]; // store data from module
int X;
int Y;
int led=128;
void setup()
{
 Serial.begin(9600); // initialization of the serial communication
 SPI.begin(); // initialization of SPI port
 SPI.setDataMode(SPI_MODE0); // configuration SPI link in mode 0
 SPI.setClockDivider(SPI_CLOCK_DIV16); // configuration of clock at 1MHz
 pinMode(10, OUTPUT);
}

void loop()
{
 digitalWrite(CS, LOW); // activation of CS line
 delayMicroseconds(15); // see doc: wait 15μs after activation of CS line
 for (i=0;i<5;i=i+1)
    {
    recu[i] = SPI.transfer(led); // Send 5 data to get data from module (LEDs are off)
    delayMicroseconds(10); // see doc: wait 10μs after each send
    }
digitalWrite(CS, HIGH); // deactivation of CS line
X = recu[0]; // X has a 10-bit format
X |= (recu[1] << 8);
Y = recu[2]; // Y has a 10-bit format
Y |= (recu[3] << 8);
for (i=0;i<5;i=i+1) // write in serial monitor
   {
   Serial.print("i");
   Serial.print(i);
   Serial.print("=");
   Serial.print(recu[i]);
   Serial.print('\t'); // tabulation
   }
Serial.print("X=");
Serial.print(X);
Serial.print('\t'); // tabulation
Serial.print("Y=");
Serial.println(Y);
delay(10);
switch (recu[4])
{
case 2: // BTN1 working
 led=129;
 break;
case 4: // BTN2 working
 led=130;
 break;
case 6: // BTN1 and BTN2 working
 led=131;
 break;
default:
 led=128;
break;
 }
}

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