Arduino Documentation: Hardware
Arduino Documentation: Hardware
Hardware
The LCD operates using the KS0108 Graphics LCD Library, required for modification of
the arduino code.
Blue
Clock
Green
Data
Red
VCC
Yellow
Ground
LEDs Example
4. Pressure Sensor
The pressure sensors mounted in the apparatus is a 100 lb Flexiforce pressure
sensor, model SEN-08685. The resistance within the sensor is variable based on the pressure
applied.
Software
1.
2.
3.
4.
5.
6.
Software Architecture
LabVIEW Sampling, Read in Resistances to LabVIEW
Sensor Reading
Converting Sensor Reading (Resistance) to Temperature
Displaying Temperature Reading on LCD Screen
Convert Temperature Readings to HSV
Convert HSV to RGB to Int32 Color Function to LED Strip
The majority of the code below is commented. This can be viewed easier in an editor such as
notepad++ under C (language).
/*********************************************************************************
**
** Includes.
**
********************************************************************************/
// Standard includes. These should always be included.
#include <Wire.h>
#include <SPI.h>
#include <Servo.h>
#include "LabVIEWInterface.h"
#include <WS2801.h>
#include <glcd.h>
// include the Fonts
#include <fonts/allFonts.h>
// Constants
float RINF = 0.0881613489;
int B = 3950; //
int dataPin = 2;
int clockPin = 3;
int MAXHDEG = 240;
unsigned long timeReset =0;
break;
case 1:
*r = byte(round(255*q));
*g = byte(round(255*v));
*b = byte(round(255*p));
break;
case 2:
*r = byte(round(255*p));
*g = byte(round(255*v));
*b = byte(round(255*t));
break;
case 3:
*r = byte(round(255*p));
*g = byte(round(255*q));
*b = byte(round(255*v));
break;
case 4:
*r = byte(round(255*t));
*g = byte(round(255*p));
*b = byte(round(255*v));
break;
default: // case 5:
*r = byte(round(255*v));
*g = byte(round(255*p));
*b = byte(round(255*q));
}
}
// Set the first variable to the NUMBER of pixels. 25 = 25 pixels in a row
WS2801 strip = WS2801(18, dataPin, clockPin);
/* Helper functions */
// Create a 24 bit color value from R,G,B
uint32_t Color(byte r, byte g, byte b)
{
uint32_t c;
c = r;
c <<= 8;
c |= g;
c <<= 8;
c |= b;
return c;
}
/*********************************************************************************
** setup()
**
** Initialize the Arduino and setup serial communication.
**
** Input: None
** Output: None
*********************************************************************************/
void setup()
{
// Initialize Serial Port With The Default Baud Rate
syncLV();
GLCD.Init();
Serial.begin(9600);
// Select the font for the default text area
GLCD.SelectFont(System5x7);
// Place your custom setup code here
strip.begin();
// Update LED contents, to start they are all 'off'
strip.show();
}
/*********************************************************************************
** loop()
**
** The main loop. This loop runs continuously on the Arduino. It
** receives and processes serial commands from LabVIEW.
**
** Input: None
** Output: None
*********************************************************************************/
void loop()
{
// Check for commands from LabVIEW and process them.
checkForCommand();
// Place your custom loop code here (this may slow down communication with LabVIEW)
int sensorValue[5];
float Temp[9];
float Res[9];
byte r,g,b;
float SATURAION = 100.0;
float VALUE = 100.0;
if (millis() >= (timeReset+2000)) {
// Read Sensor Values
sensorValue[0] = analogRead(A0);
sensorValue[1] = analogRead(A1);
sensorValue[2] = analogRead(A2);
sensorValue[3] = analogRead(A3);
sensorValue[4] = analogRead(A4);
sensorValue[5] = analogRead(A5);
sensorValue[6] = analogRead(A6);
sensorValue[7] = analogRead(A7);
sensorValue[8] = analogRead(A8);
sensorValue[9] = analogRead(A9);
sensorValue[10] = analogRead(A10);
sensorValue[11] = analogRead(A11);
// GLCD Stuff
GLCD.ClearScreen();
GLCD.CursorTo(0, 1);
GLCD.print("#|Temp (F)|# |Temp(F)\n");
for(int i = 0; i < 6; i++){
GLCD.print((i+1), DEC);
GLCD.print("| ");
Temp[i] = TemperatureReturn(sensorValue[i]);
if ( (Temp[i]) > 0){
GLCD.print(Temp[i], 2);
GLCD.print(" |");
}
else {
GLCD.print("-------");
GLCD.print("|");
}
// Returning Resistance
//Temp[2*i+1] = TemperatureReturn(sensorValue[2*i+1]);
if (i < 5){
GLCD.print((i+7), DEC);
GLCD.print("| ");
//
//
//Temp[2*i+2] = TemperatureReturn(sensorValue[2*i+1]);
//Set the Pixel Color For each of the 18
//H = 240*Temp/212 (0 to 240 deg) of (0 to 212 deg)
//There are 18
for(int ii = 0; ii < 4; ii++){
HSV_to_RGB((240*Temp[i]/212), SATURAION, VALUE,&r,&g,&b);
strip.setPixelColor(i*4+ii,Color(r,g,b));
}
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
}
timeReset = millis(); //Reset time since last reading
strip.show(); // Write out pixels
}
// Some example procedures showing how to display to the pixels
//colorWipe(Color(TemperatureReturn(sensorValue[0])/250, 0, 0), 50);
if(acqMode==1)
{
sampleContinously();
}
}