I am attempting to automate a parking ticket printing process that will allow me to utilize some equipment at work more efficiently.
In a normal ticket printing process, a vehicle activates an inductance loop which enables the ticket spitter. The customer then pushes a button which causes the ticket spitter to print a ticket. When the customer removes the ticket, the ticket spitter activates the necessary components to raise a gate and allow access into a parking deck/garagage/lot/etc.
Electrically, I have been able to build a circuit that simulates a vehicle activating an inductance loop, the customer pushing the ticket button, and the customer removing the ticket.
I want to use my Arduino Uno and relay shield to control this electrical circuit. This system will be used to print anywhere from 1 ticket to hundreds or even thousands of tickets depending on the requirement. One stipulation I have for this system is that I want user input(the number of tickets that need to be printed) to be controlled via a program running on a windows based PC (Windows 7 but would be nice if also compatible with XP).
Ideally, I would like for anyone in the office to be able to say "Hey, I need to print 200 tickets…" and they can open this program on the computer, punch in "200" and let the system do its thing.
I am a beginner in regards to c/c++ and have been told that c/c++ is probably not the easiest way to communicate serially. But as of right now, I have written the Arduino sketch to control my relay shield and also a c++ program that basically goes through some dialogue to prompt the user to input the number of tickets that need to be printed.
Here are issues I am facing:
- I am unable to send the integer input in the c++ program (number of tickets) to the arduino.
- I have learned that using the serial monitor in the Arduino IDE sends ASCII and not integers. I remedied that buy subtracting 48 from the value read in from serial. However, once I start sending double digit values such as "10" this does not work. I think I need to read in the values from the serial port byte-wise but if that is the case, I am not quite sure how to go about it.
Arduino Sketch
//RELAY SHIELD TEST
#define relay1 7 //a loop
#define relay2 6 //b loop
#define relay3 5 //ticket request
#define relay4 4
#define MAXPRINT 101 //max number of tickets that will be printed
//before 10 minute cooldown is implemented
#define secDelay 1000 //1 second time between relays when necessary
#define halfDelay 500 //500 millisecond time delay
int tickets = 0, temp = 0;
void setup()
{
Serial.begin(9600);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
Serial.println("Enter number of tickets to be printed:");
}
void loop()
{
if(Serial.available() > 0)
{
tickets = (Serial.read() - 48);
Serial.println(tickets);
temp = tickets;
if(tickets <= MAXPRINT)
{
for(int a = 0; a < temp; a++)
{
digitalWrite(relay1, HIGH);
delay(secDelay);
digitalWrite(relay3, HIGH);
digitalWrite(relay2, HIGH);
delay(secDelay);
digitalWrite(relay3, LOW);
delay(secDelay);
digitalWrite(relay1, LOW);
delay(secDelay);
digitalWrite(relay2, LOW);
delay(halfDelay);
Serial.println(a + 1);
}//end for loop
}//end if
if(tickets > MAXPRINT)
{
int x = 0, y = 0;
for(int i = 0; i < temp; i++)
{
do
{
digitalWrite(relay1, HIGH);
delay(secDelay);
digitalWrite(relay3, HIGH);
digitalWrite(relay2, HIGH);
delay(secDelay);
digitalWrite(relay3, LOW);
delay(secDelay);
digitalWrite(relay1, LOW);
delay(secDelay);
digitalWrite(relay2, LOW);
delay(halfDelay);
Serial.println(i + 1);
x++;
} while(x <= MAXPRINT);
delay(6000); //10 minute delay
}//end for loop
}//end inner if
}//end outter if
}//end loop
C++ Program //I realize that I have some file I/O code that uses C syntax but that was the closest example I could find online so I was trying to mess around with it
#define DEFTIME 5 //time in seconds that one ticket printing evolution requires (get more accurate time information)
//will use to estimate time to complete
#define MIN 60 //seconds in a minute
#define MAXPRINT 100 //number of tickets allowed per print cycle (cooldown every 100 tickets)
#define COOLDOWN 10 //time spitter cools down (in minutes)
#include <fstream>
#include <iostream>
#include <cstdio>
using namespace std;
void main(void)
{
int tickets = 0, option = 0, cooldown = 0, tempTime = 0;
float time;
FILE *file;
file = fopen("COM1:","w"); //Opening serial port
cout << endl;
cout << "Please verify that:" << endl;
cout << "(1) the spitter test set is connected properly" << endl;
cout << "(2) the spitter is powered on" << endl;
cout << "(3) the spitter has an adequate number of tickets available for printing" << endl << endl;
cout << "How many tickets would you like to print? ";
cin >> tickets;
flushall();
cout << endl << "Note: The automatic print sequence will enter a 10 minute cool down\n for every 100 tickets printed to preserve electronic equipment." << endl << endl;
cout << "Press 1 to continue and print " << tickets << " tickets, or press 2 to exit the program. ";
cin >> option;
flushall();
if(tickets > MAXPRINT){
tempTime = (tickets/MAXPRINT) * COOLDOWN;
}
time = ((DEFTIME * tickets)/MIN) + tempTime;
if(option == 1){
fprintf(file,"%d",tickets); //Writing to the serial port
cout << endl << "Testing..." << endl << endl;
cout << "Estimated time to print " << tickets << " tickets is " << time << " minutes." << endl << endl;
}//end if
else{
return;
}//end else
fclose(file);
}//end main
Any input, suggestions, etc. would be greatly appreciated.
I am not married to using c/c++ in order to provide a program that the user uses to interface with the Arduino, but that is really the only language I have any experience with and I have very little time to devote to learning something completely different.