Quiz Show Buzzer With A Twist

Hi Everybody,

I've been watching / reading about Arduino for a long time and finally jumped in with the new Arduino Yun.

I'm starting out with a fairly simple project that has a real world use for me. My roommate and I DVR Jeopardy and try to compete against each other. We've needed a good quiz show buzzer system for a long time to make things fair. The twist is that the DIRECTV DVR can be controlled via HTTP commands (How to build your own open source IoT platform | OpenRemote) and I want the show to be paused every time someone buzzes and playback resumed via a separate button.

I've actually got the whole thing working already, but it will only work when I've uploaded the sketch to the Arduino via a USB connection to my Windows 7 PC.

I've created 2 sketches, one with networking and one without. The one without the networking works correctly whether it's been uploaded via USB or wifi. Everything works the way it should.

The sketch with the HTTP call works correctly when uploaded via USB. Monitoring the serial port via the USB connection displays all the expected returns from the DVR. If I have it working, unplug the USB from the PC, Plug it into a power source, give it time to boot up...I get nothing. The sketch doesn't work at all. In the Arduino Windows app the device comes up as an available port via IP, but neither the LEDs nor the HTTP calls work.

Same results if I upload the exact same sketch via wifi.

As soon as I go back to uploading the sketch via USB and staying connected to USB, the program works as expected.

I don't really understand what is going wrong... Does anyone have any insight for me? Both sketches are provided below. Thanks in advance for your assistance.

This is the simple version. No HTTP calls. Sorry it’s lacking comments, the next sketch is better.

// set pin numbers:
const int buttonPin1 = 3; // the number of the pushbutton pin
const int ledPin1 = 10; // the number of the LED pin
const int buttonPin2 = 4; // the number of the pushbutton pin
const int ledPin2 = 11; // the number of the LED pin
const int buttonPin3 = 5; // the number of the pushbutton pin
const int ledPin3 = 12; // the number of the LED pin
const int resetButton = 6;

// variables will change:
int button1State = 0; // variable for reading the pushbutton status
int button2State = 0; // variable for reading the pushbutton status
int button3State = 0; // variable for reading the pushbutton status
int answerPresent = 0; // variable for reading if an answer is present

void setup() {

// initialize the LED1 pin as an output:
pinMode(ledPin1, OUTPUT);
// initialize player 1 button as input
pinMode(buttonPin1, INPUT);
// initialize the LED2 pin as an output:

pinMode(ledPin2, OUTPUT);
// initialize player 2 button as input
pinMode(buttonPin2, INPUT);
// initialize reset button

pinMode(ledPin3, OUTPUT);
// initialize player 3 button as input
pinMode(buttonPin3, INPUT);
// initialize reset button

pinMode(resetButton, INPUT);

}

void loop(){
// read the state of the pushbutton value:
button1State = digitalRead(buttonPin1);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:

if (button1State == HIGH && answerPresent == 0) {
// turn LED on:
digitalWrite(ledPin1, HIGH);
answerPresent = 1;
}
else {}

button2State = digitalRead(buttonPin2);
if (button2State == HIGH && answerPresent == 0) {
// turn LED on:
digitalWrite(ledPin2, HIGH);
answerPresent = 1;
}
else {}

button3State = digitalRead(buttonPin3);
if (button3State == HIGH && answerPresent == 0) {
// turn LED on:
digitalWrite(ledPin3, HIGH);
answerPresent = 1;
}
else {}

if(digitalRead(resetButton)==HIGH){
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
answerPresent=0;
}
else {}

}

Simple_Jeopardy_no_HTTP.ino (2.73 KB)

And this is the one with the HTTP Calls. The DVR is 192.168.1.11. The Arduino is 192.168.1.3.

/*
This is Jeopardy!

This sketch acts as a 3 player quiz show buzzer with indicator LEDs AND the ability to send an HTTP call to my DIRECTV DVR.

When a player buzzes in the corresponding LED will be turned on and a ‘Pause’ command will be sent to the DIRECTV DVR while other players are prevented from buzzing in.

*/

//Libraries
#include <Bridge.h>
#include <HttpClient.h>

// Set Pin Numbers
const int buttonPin1 = 3; // Player 1 Button
const int ledPin1 = 10; // Player 1 LED
const int buttonPin2 = 4; // Player 2 Button
const int ledPin2 = 11; // Player 2 LED
const int buttonPin3 = 5; // Player 3 Button
const int ledPin3 = 12; // Player 3 LED
const int resetButton = 6; // Reset Button

// Set Variables
int button1State = 0; // Variable for reading Player 1 button
int button2State = 0; // Variable for reading Player 2 button
int button3State = 0; // Variable for reading Player 3 button
int answerPresent = 0; // variable for reading if an answer is present

void setup() {
// initialize player 1 LED as OUTPUT and button as INPUT
pinMode(ledPin1, OUTPUT);
pinMode(buttonPin1, INPUT);

// initialize player 2 LED as OUTPUT and button as INPUT
pinMode(ledPin2, OUTPUT);
pinMode(buttonPin2, INPUT);

// initialize player 3 LED as OUTPUT and button as INPUT
pinMode(ledPin3, OUTPUT);
pinMode(buttonPin3, INPUT);

// initialize reset button
pinMode(resetButton, INPUT);

//initialize the bridge and turn on LED on Pin13 when ready
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Bridge.begin();
digitalWrite(13, HIGH);

//initialize serial connection
Serial.begin(9600);
// wait for a serial connection
while(!Serial);

}

void loop(){

// check if the button1 is pressed. if it is, set button1State to HIGH:
button1State = digitalRead(buttonPin1);

// If Button1 is pressed and No Answer is present - Turn on the LED and Prevent others from buzzing in
if (button1State == HIGH && answerPresent == 0)
{
// turn LED on:
digitalWrite(ledPin1, HIGH);

// Set answerPresent to 1 to indicate someone has buzzed in
answerPresent = 1;

// Initialize the HTTP Client
HttpClient client;

//This delay seems to help reliability
delay(100);

// Send ‘Pause’ command via HTTP
client.get(“http://192.168.1.11:8080/remote/processKey?key=pause”);

// If there are incoming bytes available from the server, read them and print them
// At this time, this serves no useful purpose for this application
while (client.available())
{
char c = client.read();
Serial.print(c);
}
Serial.flush();
delay(100);
}
else {
}

// check if the button1 is pressed. if it is, set button2State to HIGH:
button2State = digitalRead(buttonPin2);

// If Button2 is pressed and No Answer is present - Turn on the LED and Prevent others from buzzing in
if (button2State == HIGH && answerPresent == 0)
{
// turn LED on:
digitalWrite(ledPin2, HIGH);

// Set answerPresent to 1 to indicate someone has buzzed in
answerPresent = 1;

// Initialize the HTTP Client
HttpClient client;

//This delay seems to help reliability
delay(100);

// Send ‘Pause’ command via HTTP
client.get(“http://192.168.1.11:8080/remote/processKey?key=pause”);

// If there are incoming bytes available from the server, read them and print them
// At this time, this serves no useful purpose for this application
while (client.available())
{
char c = client.read();
Serial.print(c);
}
Serial.flush();
delay(100);
}
else {
}

// check if the button3 is pressed. if it is, set button3State to HIGH:
button3State = digitalRead(buttonPin3);

// If Button3 is pressed and No Answer is present - Turn on the LED and Prevent others from buzzing in
if (button3State == HIGH && answerPresent == 0)
{
// turn LED on:
digitalWrite(ledPin3, HIGH);

// Set answerPresent to 1 to indicate someone has buzzed in
answerPresent = 1;

// Initialize the HTTP Client
HttpClient client;

//This delay seems to help reliability
delay(100);

// Send ‘Pause’ command via HTTP
client.get(“http://192.168.1.11:8080/remote/processKey?key=pause”);

// If there are incoming bytes available from the server, read them and print them
// At this time, this serves no useful purpose for this application
while (client.available())
{
char c = client.read();
Serial.print(c);
}
Serial.flush();
delay(100);
}
else {
}

if(digitalRead(resetButton)==HIGH)
{
//Reset LEDs
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);

//Clear answerPresent
answerPresent=0;

// Initialize the HTTP Client
HttpClient client;

// Send ‘Play’ command via HTTP
client.get(“http://192.168.1.11:8080/remote/processKey?key=play”);

// if there are incoming bytes available from the server, read them and print them:
while (client.available())
{
char c = client.read();
Serial.print(c);
}

Serial.flush();
delay(100);
}
else {
}

}

It fails when it has no serial connection? I wonder if the while(!serial) has anything to do with that?

Delta_G:
It fails when it has no serial connection? I wonder if the while(!serial) has anything to do with that?

Alright, so, clearly I'm a dummy... Thanks for your help.

But, follow up question... If I want to print out or monitor the data returned by the HTTP call...how do I do that without being connected to USB?

I thought the serial monitor would still work when accessing the arduino over wifi rather than USB.

Thanks again.