I have been working on a project for work ( I'm a waiter :/ ) I was tasked to build a food wait time display that receives input from the kitchen and echoes the time via bluetooth to another display. So that we are all on the same page I will describe what I have built and where I am stuck.
Before I do, I would like to state that I have:
- been planning and prototyping this thing for over a month
- googled/crawled all over the web looking for answers
- read the entire manual on the HC05 module
- Bound both of the bluetooth modules via AT commands One as Master the other as Slave
Now with that out out the way here is what I have so far:
- 2x Arduino uno R3
- 2x 16x2 LCD Display
- 2x HC05 Bluetooth Modules (1 set as Master the other as Slave & bound using AT Commands)
- 2x 10K Potentiometers for adjusting the contrast
- 3x Momentary push Button switches on Master with pull-up resistors (timeUp, timeDown, sendButton)
Here is where I am stuck. UPDATE
I was able to get the master and slave to communicate. RX and TX on master were crossed... SMH! However now the issue is that the slave is writing both digits it receives on top of itself. First writing one digit then clearing it and then the second digit...
Enough with the prologue here is the a code:
Master
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //sets up LCD pins
int waitTime = 10; //if food comes quicker than there is no need for a display ;)
const int timeUp = 6;
const int timeDown = 7;
const int sendButton = 8;
int timeUpState = 0;
int timeDownState = 0;
int sendButtonState = 0;
void setup() {
Serial.begin(115200);
pinMode(timeUp, INPUT);
pinMode(timeDown, INPUT);
pinMode(sendButton, INPUT);
lcd.begin(16, 2);
lcd.print(" Sam Kullman's"); //Splash screen on start up
lcd.setCursor(0,1);
lcd.print(" Diner"); //Splash Screen
delay(2000); // Delay intended to allow the device to pair prior to use.
lcd.clear();
lcd.print("Essen Dauert:"); //German for "Food takes":
lcd.setCursor(0,1);
lcd.print(" Minuten"); // xx minutes
}
void loop(){
lcd.setCursor(0,1);
timeUpState = digitalRead(timeUp);
timeDownState = digitalRead(timeDown);
sendButtonState = digitalRead(sendButton);
if (timeUpState == LOW) {
waitTime += 5;
delay(500); //debounce button
lcd.print(waitTime);
}
if(waitTime > 90){ // Max limit for wait time
waitTime = 10; //default wait time
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Essen Dauert:");
lcd.setCursor(0,1);
lcd.print(" Minuten");
}
if (timeDownState == LOW){
waitTime -= 5;
delay(500);
lcd.print(waitTime);
}
if(waitTime < 10){ //Min value waiting time
waitTime = 10;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Essen Dauert:");
lcd.setCursor(0,1);
lcd.print(" Minuten");
}
if(Serial.available()){ // **This is where I am stuck**
if(sendButtonState == LOW){
Serial.write(waitTime);
delay(500);
}
}
}
Slave
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
Serial.begin(9600);
Serial.flush();
lcd.begin(16, 2);
lcd.print(" Sam Kullman's");
lcd.setCursor(0,1);
lcd.print(" Diner");
}
void loop(){
if (Serial.available()) {
int waitTime = Serial.read();
delay(200);
lcd.clear();
lcd.print("Essen Dauert:");
lcd.setCursor(0,1);
lcd.write(waitTime);
lcd.print(" Minuten");
}
}
Thanks in advance, Jonathan
2 Answers 2
lcd.write(waitTime);
This line prints a single byte, whose (ASCII) value is the number in waitTime. You probably should write:
lcd.print(waitTime);
instead, which prints the number in waitTime using one ore more digits as needed.
This doesn't 100% explain the "both digits end up in the same place" symptom, since I'd expect random junk to be printed instead. But I'm pretty certain this is a problem, perhaps there's more problems :-)
-
Thanks for the tip, however when I use
lcd.write(waitTime)
I get the DEC value andlcd.print(waitTime)
gives me the ASCII i.e.. 49 for 1 etc.Jonathan– Jonathan2014年11月29日 14:45:11 +00:00Commented Nov 29, 2014 at 14:45
The problem was how I was reading the incoming serial data.
After changing int waitTime = Serial.read()
to int waitTime = Serial.parseInt()
the code works.
Thanks to everyone for all your help and tips!
Explore related questions
See similar questions with these tags.
delay(500);
after the state change not enough or in the wrong place? After some web crawling on "debouncing" I'm pretty sure I have denounced the buttons, or are you suggesting I take a hardware approach to denounce the buttons? I don't have an oscilloscope so I can't see exactly how the buttons are behaving.