First post, First Problem

Good afternoon,

I’m new here, been reading through a lot of posts but can’t find a solution.

My first project was supposed to be very simple. A 2 line display, first line shows a set message, second line shows a line of text received over serial.

So far it’s most of the way there, top line is fine, but the second line will only display numbers, not letters.

I’ve been using ardublock, which may or may not be my problem.

Here’s what I have so far:

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal.h>

// For these LCD controls to work you MUST replace the standard LCD library with 'New LCD' from...
// https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
// Direct download https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/LiquidCrystal_V1.2.1.zip
// Your project will not compile until this is done.
//

LiquidCrystal lcd_I2C_Parallel(12, 11,  5,  4,  3,  2,  7, POSITIVE);

void setup()
{
  lcd_I2C_Parallel.begin (16, 2);
  lcd_I2C_Parallel.setBacklight(HIGH);
  Serial.begin(9600);
  lcd_I2C_Parallel.setCursor( (1) - 1, (1) - 1 );
  lcd_I2C_Parallel.print( "ON DUTY" );

}

void loop()
{
  lcd_I2C_Parallel.setCursor( (1) - 1, (2) - 1 );
  lcd_I2C_Parallel.print( Serial.Read() );
}

Any help would be massively appreciated!

Benjo3000:
void loop()
{
lcd_I2C_Parallel.setCursor( (1) - 1, (2) - 1 );
lcd_I2C_Parallel.print( Serial.parseInt() );
}

And you are surprised it will only display numbers? Check google for the function of 'parseInt'!

Regards,

Graham

I had found that’s a problem, but the alternative was serial.read, and that didn’t do anything. I was assuming that as the parse.Int command was actually showing some results it may have been closer.

That's not how you do programming! :roll_eyes:

Ok, that's also not helpful. I've got a technical query, I've explained it's my first project, my post wasn't so people could just look at it and roll their eyes, I was after something helpful.

And I'll bet good money that this isn't the stupidest question you've seen asked on here.

No, it is not the stupidest question.

But think about it.
Serial.parseInt() sounds like it is receiving input from Serial and evaluating it as an Integer.
Serial.parseFloat() sounds like it is receiving input from Serial and evaluating it as an Float.

You will find many functions with “intuitive” names e.g. itoa() integer to ascii
or atoi() ascii to integer

If you come across something that is not obvious, just Google it.
e.g. “parseInt()” and see for yourself.

David.

ok, got it, parseInt just deals with integers. Anything else is ignored.
But the only alternative command I can find is the basic serial.read, but this just returns a -1, or depending what I try and send it an bigger negative number, eg sending test returns -16.

I know I'm missing something obvious.

Benjo3000:
the alternative was serial.read, and that didn't do anything.

That however, was a pretty stupid statement.

Partly because serial.read is exactly what you use to read text from the input, and partly because saying it "didn't do anything" is so patently wrong.

Now, how about you go read the forum instructions, then go back and use the "More" -> "Modify" option on your first post to at least post your defective code properly?

Benjo3000:
But the only alternative command I can find is the basic serial.read, but this just returns a -1,
...
I know I'm missing something obvious.

Tried reading the documentation for serial.read?

There we go, first post edited. And yes, you'll hear a lot of stupid comments from me, I'm very ignorant in these matters. I have decided to ask the experts for assistance, as sometimes just googling "What command allows me to read a line of serial text" doesn't provide much in the way of useful advice.

I have read the documentation for serial.read now, and I see it reads the first byte, this still doesn't explain why it shows -16 instead of t for my example does it?

Benjo3000:
But the only alternative command I can find is the basic serial.read

So you didn't look too hard then.... Try this, there are plenty of commands to play with.....Serial - Arduino Reference

Regards,

Graham

Edit: TIP '\n' is going to be useful! :wink:

Here's a link to Robin2's excellent tutorial on Serial Input Basics.

second line shows a line of text received over serial.

Once you use the techniques of the tutorial to read the line of text into the Arduino from the keyboard you will have to display that character array on the lcd. If you can't figure out how to do that, come back with the code which has the appropriate Serial.read().

lcd_I2C_Parallel.setCursor( (1) - 1, (1) - 1 );
lcd_I2C_Parallel.setCursor( (1) - 1, (2) - 1 );

Why are you using this syntax for setCursor instead of the more simple form which just uses column and row with out the subtractions?

Benjo3000:
I have read the documentation for serial.read now, and I see it reads the first byte, this still doesn't explain why it shows -16 instead of t for my example does it?

Well, frankly, I very much doubt it does (show "-16"). The point is, it reads -1 if there is nothing to be read, or you can use serial.available which makes more sense but I have had some mysterious trouble with it in the past, possibly due to earlier compiler versions.

The real point is that without knowing what crazy code you wrote to get -16, we cannot help you with that. :grinning:

Oh, wait! You have not only marked up the code in the first post, you have changed it to a quite different version which does not understand how serial.read works!

Wow!

Good Morning!

Yes,

My previous code was rubbish, the setcursor syntax was generated by Ardublock, I have changed it to the simpler way now.

This is my current code. This one starts showing “On Duty” on the second line, top line is blank.
When serial data is sent to the board the screen is wiped blank, showing nothing. This is most likely due to me not having code which keeps the second line regardless of what the top line is doing.

And, can I just say, I know this most be extremely frustrating reading for all of you who could probably write this simple piece of code (and have it working) in about 3 minutes, but I am not a programmer, I am not a budding young hobby programmer just starting out, I have a full time job, and this “silly little piece of code” is just a very small part of a larger system, and I need to get it working. Thank you for your patience and assistance.

[/#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal.h>

// For these LCD controls to work you MUST replace the standard LCD library with 'New LCD' from...
// https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
// Direct download https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/LiquidCrystal_V1.2.1.zip
// Your project will not compile until this is done.
//
//                             RS  EN  d0  d1  d2  d3  LED 
LiquidCrystal lcd_I2C_Parallel(12, 11,  5,  4,  3,  2,  7, POSITIVE);

void setup()
{
  lcd_I2C_Parallel.begin (16, 2);
  lcd_I2C_Parallel.setBacklight(HIGH);
  Serial.begin(9600);
}

void loop()

{   if (Serial.available()) 
  {
    delay(100);
 lcd_I2C_Parallel.clear();
    while (Serial.available() > 0) 

  lcd_I2C_Parallel.setCursor(0,0);
  lcd_I2C_Parallel.write(Serial.read());
}
  {
  lcd_I2C_Parallel.setCursor(0,1);
  lcd_I2C_Parallel.print( "On Duty" );
}
}
code]

First off. ctrl-T is your friend. I just used ctrl-T to make your indentation readable.

void loop()
{
    if (Serial.available())
    {
        delay(100);
        lcd_I2C_Parallel.clear();
        while (Serial.available() > 0)

            lcd_I2C_Parallel.setCursor(0, 0);
        lcd_I2C_Parallel.write(Serial.read());
    }
    {
        lcd_I2C_Parallel.setCursor(0, 1);
        lcd_I2C_Parallel.print( "On Duty" );
    }
}

Now I change the logic:

void loop()
{
    if (Serial.available())
    {
        delay(100);                      //Allow some time to receive the whole string
        lcd_I2C_Parallel.clear();        //this sets cursor to 0, 0
        while (Serial.available() > 0)   //show what we received
            lcd_I2C_Parallel.write(Serial.read());
    }
    else 
    {
        lcd_I2C_Parallel.setCursor(0, 1);
        lcd_I2C_Parallel.print( "On Duty" );
    }
}

The Arduino Serial terminal sends all its input in one go. So your sketch should work ok.
A normal Terminal sends a character one at a time as you type. Your sketch would erase everything between each letter.

I suggest that you choose "simpler" names for your objects. e.g. lcd instead of lcd_I2C_Parallel
You only need to know which type of lcd you are using when you write the constructor().

Your program proper would work with every type of lcd. This is the beauty of C++.

David.

David, thank you so much.

I wish I had known about Ctrl-T, I've been bloody spacing and tabbing to try and neaten things up! This is how much of noob I am.

That code you wrote is almost perfect, the only problem is that its generating a strange character at the end of the received serial text. Like a 4 horizontal lines character.

Thank you again.

Edit: Ignore that, it was me sending a newline command.

Thanks for all the help everyone!

Well, the first problem is the use of

lcd_I2C_Parallel.clear();        //this sets cursor to 0, 0

in the loop().

This doesn't just zero the cursor, it clears the display. You don't want to clear the display unless you want to clear the display - which really, you don't.

So if you remove that, you don't need to wait for anything, you merely print each character as it comes.

The funny Line Feed character?

Well, that's how computers indicate the end of a line.

"Line Feed" means nothing to a LCD display - it just prints a character that maps to that code.

You have to decide what it means. You have to check the input for it.

What you probably want to do, is a little tricky. When a Line Feed is received, the next character needs to clear the line (which means, set the cursor and print a whole line of spaces) and then (set the cursor again and) print that character which began the next line to be displayed.

You may also have to ignore the Carriage Return character.


And of course, that code

        lcd_I2C_Parallel.setCursor(0, 1);
        lcd_I2C_Parallel.print( "On Duty" );

Needs to go in setup(), otherwise you will get an intense flicker as it gets written over and over again, hundreds of times each second.