Skip to content

Commit fbdbbcc

Browse files
committed
Adding Vernier Library, examples and documentation. Use of library allows for auto id of our sensors in sketches.
1 parent 824b83f commit fbdbbcc

File tree

11 files changed

+1151
-0
lines changed

11 files changed

+1151
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "VernierLib.h"
2+
VernierLib Vernier;
3+
float sensorReading;
4+
void setup()
5+
{
6+
Serial.begin(9600);
7+
Vernier.autoID();// this is the routine to do the autoID
8+
printSensorInfo();
9+
}
10+
11+
void loop()
12+
{
13+
sensorReading =Vernier.readSensor();
14+
Serial.print(sensorReading);
15+
Serial.print(" ");
16+
Serial.println(Vernier.sensorUnits());
17+
delay(500);//half a second
18+
}
19+
20+
void printSensorInfo()
21+
{
22+
// print out information about the sensor found:
23+
Serial.println("Sensor Information:");
24+
Serial.print("Sensor ID number: ");
25+
Serial.print("\t");
26+
Serial.println(Vernier.sensorNumber());
27+
Serial.print("Sensor Name: ");
28+
Serial.print("\t");
29+
Serial.println(Vernier.sensorName());
30+
Serial.print("Short Name: ");
31+
Serial.print("\t");
32+
Serial.println(Vernier.shortName());
33+
Serial.print("Units: ");
34+
Serial.print("\t");
35+
Serial.println(Vernier.sensorUnits());
36+
Serial.print("ID voltage level: ");
37+
Serial.print("\t");
38+
Serial.println(Vernier.voltageID());
39+
Serial.print("Page: ");
40+
Serial.print("\t");
41+
Serial.println(Vernier.page());
42+
Serial.print("slope: ");
43+
Serial.print("\t");
44+
Serial.println(Vernier.slope());
45+
Serial.print("intercept: ");
46+
Serial.print("\t");
47+
Serial.println(Vernier.intercept());
48+
Serial.print("cFactor:");
49+
Serial.print("\t");
50+
Serial.println(Vernier.cFactor());
51+
Serial.print("calEquationType: ");
52+
Serial.print("\t");
53+
Serial.println(Vernier.calEquationType());
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "VernierLib.h"
2+
VernierLib Vernier;
3+
byte DCUSetting= 0;
4+
float sensorReading;
5+
float threshold = 5.0;
6+
7+
void setup()
8+
{
9+
Serial.begin(9600);
10+
Vernier.autoID();// this is the routine to do the autoID
11+
}
12+
void loop()
13+
{
14+
sensorReading = Vernier.readSensor();
15+
Serial.print(sensorReading);
16+
Serial.print(" ");
17+
Serial.println(Vernier.sensorUnits());
18+
if (sensorReading >threshold )
19+
{
20+
DCUSetting =7;
21+
}
22+
else
23+
{
24+
DCUSetting =0;
25+
}
26+
Vernier.DCU(DCUSetting);
27+
delay(500);
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//VernierLib Demo Program
2+
#include "VernierLib.h"
3+
VernierLib Vernier;
4+
byte PWMSetting= 0;
5+
6+
void setup()
7+
{
8+
Serial.begin(9600);
9+
Vernier.autoID();// this is the routine to do the autoID
10+
}
11+
12+
void loop()
13+
{
14+
Serial.print(Vernier.readSensor());
15+
Serial.print(" ");
16+
Serial.println(Vernier.sensorUnits);
17+
// demononstrate PWM by fade in from min to max in increments of 5 points:
18+
for(int PWMSetting = 0 ; PWMSetting <= 255; PWMSetting +=5)
19+
{
20+
// sets the value (range from 0 to 255):
21+
Serial.println(PWMSetting);
22+
Vernier.DCUPWM(PWMSetting);//set PWM level
23+
// wait for 30 milliseconds to see the dimming effect
24+
delay(30);
25+
}
26+
// fade out from max to min in increments of 5 points:
27+
for(int PWMSetting = 255 ; PWMSetting >= 0; PWMSetting -=5)
28+
{
29+
// sets the value (range from 0 to 255):
30+
Vernier.DCUPWM(PWMSetting);//set PWM level
31+
// wait for 30 milliseconds to see the dimming effect
32+
delay(30);
33+
}
34+
delay(1000);//
35+
}
36+
37+
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "VernierLib.h"
2+
VernierLib Vernier;
3+
4+
void setup()
5+
{
6+
Serial.begin(9600);
7+
}
8+
9+
void loop()
10+
{
11+
for (int DCUSetting=0; DCUSetting <= 7; DCUSetting++)
12+
{
13+
Serial.println(DCUSetting);
14+
Vernier.DCU(DCUSetting);
15+
delay(1000);
16+
}
17+
}
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "VernierLib.h"
2+
VernierLib Vernier;
3+
int stepDelay=30; //step time in ms. If this value is too low for your motor
4+
int stepCount=48;
5+
int stepDirection =0;//direction 0 =CW, 1 = CCW
6+
7+
void setup()
8+
{
9+
Serial.begin(9600);
10+
}
11+
12+
void loop()
13+
{
14+
Vernier.DCUStep(stepCount,stepDirection, stepDelay);
15+
Vernier.DCU(0); // turn off all lines
16+
delay(500);//delay a half second
17+
stepDirection ++;
18+
if (stepDirection>1) stepDirection =0;
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "VernierLib.h"
2+
VernierLib Vernier;
3+
float distance = 0;// distqnce in cm
4+
void setup()
5+
{
6+
Serial.begin(9600);
7+
Serial.print("Motion Detector reading...");
8+
}
9+
10+
void loop()
11+
{
12+
distance = Vernier.readMotionDetector();
13+
Serial.print(distance);
14+
Serial.println(" cm");
15+
delay(100);//delay a tenth of a second
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "VernierLib.h"
2+
VernierLib Vernier;
3+
float sensorReading;
4+
void setup()
5+
{
6+
Serial.begin(9600);
7+
Vernier.autoID();// this is the routine to do the autoID
8+
}
9+
void loop()
10+
{
11+
sensorReading =Vernier.readSensor();
12+
Serial.print(sensorReading);
13+
Serial.print(" ");
14+
Serial.println(Vernier.sensorUnits());
15+
delay(500);//half a second
16+
}
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#include "VernierLib.h"
2+
VernierLib Vernier;
3+
float sensorReading;
4+
///
5+
const int buttonPin=12; //button on Vernier Interface Shield
6+
int buttonState = 0;//variable for reading the pushbutton
7+
char namestring[17];//character array for printing strings to display
8+
char tempstring[16]; // character array used to create string for displaying numbers
9+
#include <SoftwareSerial.h> //library used in printing to display
10+
SoftwareSerial mySerial(3,9); //for display, pin 9 = TX, pin 3 = RX (unused)
11+
///
12+
void setup(void)
13+
{
14+
Serial.begin(9600);
15+
///
16+
mySerial.begin(9600); // for sending characters to display
17+
delay(500); // wait for display to boot up
18+
mySerial.write(124); // adjust backlight brightness of display
19+
mySerial.write(150); //max=157, 150=73%, 130=40%,128=off
20+
///
21+
Vernier.autoID();// this is the routine to do the autoID
22+
printSensorInfo();
23+
///
24+
//send characters to 2-line display: (you could get rid of all of this if you do not have a 2-line display)
25+
//Display Name, Units, and Page
26+
mySerial.write(254); // cursor to beginning of first line
27+
mySerial.write(128);
28+
mySerial.print(" "); // clear display for next loop
29+
mySerial.print(" ");
30+
mySerial.write(254); // cursor to beginning of first line (position 128)
31+
mySerial.write(128);
32+
mySerial.print(Vernier.sensorName()); // display name on first line
33+
mySerial.write(254); // cursor to beginning of second line
34+
mySerial.write(192);
35+
mySerial.print(Vernier.sensorUnits()); // display units on second line
36+
mySerial.write(254);// cursor to the end of second line
37+
mySerial.write(204);
38+
mySerial.print("p=");// display page at end of second line (-1 if resistor ID)
39+
mySerial.print(Vernier.page());
40+
delay(2000); // short delay
41+
mySerial.print(" "); // clear display for what is next
42+
mySerial.print(" ");
43+
//Special section to display equation type, slope, intercept, and c, if button is pressed:
44+
buttonState = digitalRead(buttonPin);
45+
// check if the pushbutton is pressed.
46+
// if it is, the buttonState is LOW:
47+
if (buttonState == LOW)
48+
{
49+
//Display SensorNumber, cal equation type, and a (intercept)
50+
mySerial.write(254); // cursor to beginning of first line
51+
mySerial.write(128);
52+
mySerial.print("#");
53+
mySerial.print(Vernier.sensorNumber()); // Sensor ID number
54+
mySerial.write(254);// cursor to middle of the first line
55+
mySerial.write(133); // cursor to position 6 of first line
56+
mySerial.print(" cal eq="); // // display cal eq type
57+
mySerial.print(Vernier.calEquationType()); //
58+
// display page at end of second line
59+
mySerial.write(254); // cursor to beginning of 2nd line
60+
mySerial.write(192);
61+
mySerial.print("a(int)=");
62+
mySerial.print(Vernier.intercept());
63+
delay (2000);
64+
//Display b(slope), and c (cfactor):
65+
mySerial.print(" "); // clear display for next loop
66+
mySerial.print(" ");
67+
mySerial.write(254); // cursor to beginning of first line
68+
mySerial.write(128);
69+
mySerial.print("b(sl)="); // one space
70+
mySerial.print(Vernier.slope()); //
71+
mySerial.write(254); // cursor to beginning of second line
72+
mySerial.write(192);
73+
mySerial.print("c=");
74+
mySerial.print(Vernier.cFactor()); //
75+
delay (2000);
76+
//Display shortName and AutoID voltage:
77+
mySerial.write(254); // cursor to beginning of first line (position 128)
78+
mySerial.write(128);
79+
mySerial.print(" "); // clear display for next loop
80+
mySerial.print(" ");
81+
mySerial.write(254); // cursor to beginning of first line (position 128)
82+
mySerial.write(128);
83+
mySerial.print(Vernier.shortName()); // display name on first line
84+
mySerial.write(254); // cursor to near the beginning of first line
85+
mySerial.write(192);
86+
mySerial.print("ID volts=");
87+
mySerial.print(Vernier.voltageID()); // print out the raw voltage from the sensor
88+
delay (2000);
89+
}// end of special display done if button is down
90+
//set up screen for displaying data:
91+
mySerial.write(254); // cursor to beginning of first line
92+
mySerial.write(128);
93+
mySerial.print(" "); // clear display for next loop
94+
mySerial.print(" ");
95+
mySerial.write(254); // cursor to beginning of first line (position 128)
96+
mySerial.write(128);
97+
mySerial.print(Vernier.sensorName()); // display name on first line
98+
mySerial.write(254); // cursor to middle of the second line
99+
mySerial.write(200);
100+
mySerial.print(Vernier.sensorUnits()); // display units on second line
101+
}
102+
103+
void loop()
104+
{
105+
sensorReading =Vernier.readSensor();
106+
Serial.print(sensorReading);
107+
Serial.print(" ");
108+
Serial.println(Vernier.sensorUnits());
109+
mySerial.write(254); // command character
110+
mySerial.write(192); // move to line 2, position 0,
111+
Serial.println(sensorReading); // display Sensor Reading on monitor
112+
mySerial.print(sensorReading);
113+
mySerial.write(254); // command character
114+
mySerial.write(200); // move to line 2, position 7
115+
mySerial.print(Vernier.sensorUnits()); // print out sensor units
116+
delay(1000);// a second
117+
mySerial.write(254); // cursor to beginning of first line
118+
mySerial.write(192);
119+
mySerial.print(" "); // clear 2nd line of display for next loop
120+
}
121+
void printSensorInfo()
122+
{
123+
// print out information about the sensor found:
124+
Serial.println("Sensor Information");
125+
Serial.print("Sensor ID number: ");
126+
Serial.print("\t");
127+
Serial.println(Vernier.sensorNumber());
128+
Serial.print("Sensor Name: ");
129+
Serial.print("\t");
130+
Serial.println(Vernier.sensorName());
131+
Serial.print("Short Name: ");
132+
Serial.print("\t");
133+
Serial.println(Vernier.shortName());
134+
Serial.print("Units: ");
135+
Serial.print("\t");
136+
Serial.println(Vernier.sensorUnits());
137+
Serial.print("ID voltage level: ");
138+
Serial.print("\t");
139+
Serial.println(Vernier.voltageID());
140+
Serial.print("Page: ");
141+
Serial.print("\t");
142+
Serial.println(Vernier.page());
143+
Serial.print("slope: ");
144+
Serial.print("\t");
145+
Serial.println(Vernier.slope());
146+
Serial.print("intercept: ");
147+
Serial.print("\t");
148+
Serial.println(Vernier.intercept());
149+
Serial.print("cFactor:");
150+
Serial.print("\t");
151+
Serial.println(Vernier.cFactor());
152+
Serial.print("calEquationType: ");
153+
Serial.print("\t");
154+
Serial.println(Vernier.calEquationType());
155+
}
156+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "VernierLib.h"
2+
VernierLib Vernier;
3+
float sensorReading;
4+
///
5+
#include <SoftwareSerial.h> //library used in printing to display
6+
SoftwareSerial mySerial(3,9); //for display, pin 9 = TX, pin 3 = RX (unused)
7+
///
8+
9+
void setup()
10+
{
11+
Serial.begin(9600);
12+
Vernier.autoID();// this is the routine to do the autoID
13+
mySerial.begin(9600); // for sending characters to display
14+
delay(500); // wait for display to boot up
15+
mySerial.write(124); // adjust backlight brightness of display
16+
mySerial.write(150); //max=157, 150=73%, 130=40%,128=off
17+
delay(500); // wait for display to start
18+
mySerial.write(254);
19+
mySerial.write(1); //clear display
20+
mySerial.print(Vernier.shortName()); // display Short Name
21+
mySerial.write(254); // cursor to middle of bottom line
22+
mySerial.write(200);
23+
mySerial.print(Vernier.sensorUnits()); // display Units
24+
}
25+
void loop()
26+
{
27+
sensorReading =Vernier.readSensor();
28+
Serial.print(sensorReading);
29+
Serial.print(" ");
30+
Serial.println(Vernier.sensorUnits());
31+
mySerial.write(254); // command character
32+
mySerial.write(192); // move to line 2, position 0,
33+
mySerial.print(sensorReading);
34+
delay(1000);// a second
35+
///
36+
}
37+
38+

0 commit comments

Comments
 (0)