Introduction: Control Pi-Plate With Spark Core

About: Just an engineer having fun.

The ppDAQC board from Pi-Plates.com is an inexpensive yet powerful solution for expanding the input/output capabilities of the Spark Core. And since Pi-Plates are stackable, it is a simple task to scale up the I/O capabilities of a single Core. All that is required for connectivity are the four SPI signals (signals A2-A5) as well as a single digital output (D6). Power can come from the Core or from the ppDAQC board.

Step 1: Required Components

To build this assembly the following components are required:

1. A ppDAQC board from Pi-Plates.com

2. A Spark Core

3. A 5VDC power supply or the USB power supply included with the Core.

4. A small protoboard (currently included with the Core Evaluation kit)

5. Jumper wires

Step 2: Connections - 1

The diagram and table explain how the ppDAQC and the Spark Core board are connected. This implementation uses an external 5VDC supply that provides power for the Spark Core through the ppDAQC board. This approach allows you to drive peripherals with the open collector pins that would pull more than 1 amp. If you’re just playing around, use the USB power supply that came with your Spark Core.

Step 3: Code: Structure

All Spark applications for the ppDAQC require three files:

1. ppDAQC.ccp – a lightweight set of library functions

2. ppDAQC.h – the header file with all of the function prototypes

3. yourapplication.ino – your application program

The application program has to have the following structure:

#include "ppDAQC.h"

extern int ppFRAME; //____ppDAQC I/O ports that are initialized below

extern int ppCE; //

void setup()

{

SPI.begin();

delay(1); // Wait 1msec

SPI.setClockDivider(SPI_CLOCK_DIV64);

delay(1); // Wait 1msec

SPI.setDataMode(SPI_MODE0); //All of these function are required for

//initializing the SPI/Pi-Plate interface

pinMode(ppFRAME,OUTPUT); //

pinMode(ppCE,OUTPUT); //

digitalWrite(ppCE,HIGH); //

//initialization for your application variables go below:

}

void loop()

{

// Your application code

}

Here’s an example of a program that makes the LEDs on the ppDAQC board count in binary. It also reads the value of the 5VDC supply and saves it to an integer variable which is exposed with the name of “Voltage” for external access:

#include "ppDAQC.h"

int adData;

extern int ppFRAME; //____ppDAQC I/O ports that are initialized below

extern int ppCE;

void setup()

{

SPI.begin();

delay(1); // Wait 1msec

SPI.setClockDivider(SPI_CLOCK_DIV64);

delay(1); // Wait 1msec

SPI.setDataMode(SPI_MODE0); //All of these function are required for

//--initializing the ppDAQC interface

pinMode(ppFRAME,OUTPUT);

pinMode(ppCE,OUTPUT);

digitalWrite(ppCE,HIGH);

Spark.variable("Voltage", &adData, INT); //Expose voltage: Test for reading variable

}

void loop()

{

byte addr; // declare address of ppDAQC board - values can range from 0 to 7

addr=0; // set address to 0

for (int i=0;i<128;i++) // perform 128 times

{

setDOUTall(addr,i); // write index value to ppDAQC Digital Output (DOUT)

delay(10); // Wait 10msec

}

adData=getADC(0,8); // Read the power supply voltage (on channel 8 of the ADC)

// and write to adData

}

The most recent ppDAQC.cpp and ppDAQC.h library files are available from:

https://pi-plates.com/downloads/spark-ppDAQC.zip

Step 4: Code Reference

As mentioned earlier, the function library for the ppDAQC board is lightweight. However, there are enough calls to access all of the major features. For more information about all of the features of the ppDAQC board, visit www.pi-plates.com. Common to all functions is an address argument with most functions requiring at least one parameter.

  1. void setDOUTall(byte addr, byte value) – write to all 7 open collector channels. The address value (addr) can range from 0 to 7. The value can range from 0 to 127.
  2. void setDOUTbit(byte addr, byte bit) – set a single open collector bit. The address value (addr) can range from 0 to 7. The bit can range from 0 to 6.
  3. void clrDOUTbit(byte addr, byte bit) – clear a single open collector bit. The address value (addr) can range from 0 to 7. The bit can range from 0 to 6.
  4. void toggleDOUTbit(byte addr, byte bit) – toggle a single open collector bit. The address value (addr) can range from 0 to 7. The bit can range from 0 to 6.
  5. int getADC(byte addr, byte channel) – perform a 10-bit A/D conversion. The address value (addr) can range from 0 to 7. The channel can range from 0 to 8. Note that the A/D range is 0 to 4.097 volts and that channel 8 is the power supply voltage.
  6. byte getDINall(byte address) – returns an 8-bit number showing the current signal status on the Digital Input block. The address value (addr) can range from 0 to 7.
  7. byte getDINbit(byte addr, byte bit) – returns the value of a single input bit (0 or 1). The address value (addr) can range from 0 to 7. The bit can range from 0 to 7.

Step 5: Wrap Up

The Spark Core is a small yet powerful microcontroller that has the potential of becoming the go-to device in the IoT arena. Merging it with a ppDAQC board from Pi-Plates.com using the steps above makes it an even more versatile tool.