I am trying to write a sketch that shows some messages after receiving a command true the USB.
It displays it on a serial LCD. In my opinion the code is straight forward but it doenst work.
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
boolean _gs232WActice = false; // gs232 W command in process
int _gs232AzElIndex = 0; // position in gs232 Az El sequence
long _gs232Azimuth = 0; // gs232 Azimuth value
long _gs232Elevation = 0; // gs232 Elevation value
boolean _azimuthMove = false; // azimuth move needed
boolean _elevationMove = false; // elevation move needed
String azRotorMovement; // string for az rotor move display
String elRotorMovement; // string for el rotor move display
#include <SoftwareSerial.h>
const int TxPin = 7; // Define the transmit pin to LCD
// There is no receive pin from the LCD
// Create a software Serial instance for the Serial LCD
SoftwareSerial serLCD = SoftwareSerial(255, TxPin);
void setup() {
// setup standard serial USB
Serial.begin(9600);
// setup serial LCD and display welcome message
pinMode(TxPin, OUTPUT);
digitalWrite(TxPin, HIGH); // Neccesary if no display attached
serLCD.begin(9600); // The Parralax display used has a max baudrate of 19200
delay(100);
startUp();
}
void loop()
{
// Check for serial data
if(Serial.available()>0)
{
decodeGS232(Serial.read());
}
}
// Decode received command from terminal or other program
void decodeGS232(char character)
{
switch(character)
{
case's':
case'S': // Stop all movements
{
serLCD.write(148);
serLCD.print("Emergency Stop");
break;
}
}
}
// Initialize the LCD and show the copyright message
void startUp()
{
serLCD.write(12); // Clear LCD
serLCD.write(17); // Turn backlight on
serLCD.write(22); // Set cursor off
delay(50); // Required delay
serLCD.print("GS-232 Monitor"); // First line
serLCD.write(13); // Form feed
serLCD.print("Ver 0.1 (c) 2013"); // Second line
serLCD.write(212); // Quarter note
serLCD.write(220); // A tone
delay(3000); // Wait 3 seconds
serLCD.write(12); // Clear LCD
serLCD.write(25); // Set cursor on and character blink
serLCD.print("Waiting.."); // Goto input mode
}
#UKHeliBob
It functions until the switch/case part.
Shows the welcome message and then when typing something on the terminal no response is displayed.
Looks like nothing is received.
Sorry but i am not so experience as all the others here
It doesn't take experience to see what is on the LCD screen. Does anything at all go on the screen? Have you tried just sending the data to the serial monitor?
Even if you have no experience there should be some output you expected?
Give this variation a try. I expect it will generate always some output, some char between <>
// Decode received command from terminal or other program
void decodeGS232(char character)
{
switch(character)
{
case 's':
case 'S': // Stop all movements
serLCD.write(148);
serLCD.print("Emergency Stop");
break;
default:
serLCD.write(148);
serLCD.print("<");
serLCD.print(character);
serLCD.print(">");
break;
}
}
It moves to the second line and prints the < character, nothing else.
I know the connection to the LCD is correct becourse direct sent message are visable.
I would personally read the serial data into a variable before putting it into the call to your display routine.
something like
byte c = Serial.read();
decodeGS232(c);
It doesn't logically make sense why it make a difference, but the inner workings of interrupts and functions may be at work here.
When you ran the code that Rob gave you, you noticed that it stopped completely after printing "<"
That clues me that when it went to do the character part, everything went bonkers.
If it just had null as characters, it should have continued on and printed the ">" part. So, something threw your code off the rails.
Are you sure you are sending your character in the right format? Char = byte not a proper ascii string, so perhaps you need to send a null terminated string to the display. The serLCD.print function is probably looking for the null at the end of your string, and you aren't providing one so, it is hung up waiting for it.
Because it may get hung up in the first line as it is now. If the print routine itself is waiting for that null character, it will never go to the second line of code because it won't exit.
I am fairly certain that I have used the + in my code many times to add parts to a string to print. I may be wrong, but I am 99% certain.