Pages: [1]   Go Down
Author Topic: Writing to different Arduino LCD line from Visual Basic Input  (Read 501 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

  I'm creating a program that takes text from Visual Basic, and writes it on an Arduino's LCD. The only issue is that I need the write the second line to the second line of the LCD, and at the moment both lines come out on the first line of the LCD. Does anyone know how to move the LCD cursor to the second line for the second write?

Here is the Arduino code:
Code:
#include <LiquidCrystal.h>
#include <string.h>
// These are the pins our LCD uses.
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  // initalize the lcd, and button input at zero.
  int lcd_key     = 0;
  int adc_key_in  = 0;
int read_LCD_buttons()
 
  void setup()
{
Serial.begin(9600); //Set the serial monitor.
lcd.begin(16, 2); //Set the LCD
}
char line1;
void loop()
 {

 if (Serial.available() > 0) { //If the serial monitor is open it will read a value.
 line1 = Serial.read();
 delay(10);
 Serial.print(line1);
 lcd.print(line1);
}
 }

Here is the relevant part of the VB code:
    
Code:
Public Delegate Sub MessageDelegate(ByVal Data As String)
    Private Sub Apply_Click_Serial(sender As System.Object, e As System.EventArgs) Handles Apply.Click
        SerialPort1.WriteLine(Output1Text.Text)
        SerialPort1.Write(Output2Text.Text)
    End Sub
    Private Sub connect_Click(sender As System.Object, e As System.EventArgs) Handles connect.Click
        If Not SerialPort1.IsOpen Then
            SerialPort1.PortName = "COM3"
            SerialPort1.Open()
        End If
    End Sub
« Last Edit: December 05, 2012, 03:00:44 pm by BruceMacD » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46255
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a setCursor() method in the LiquidCrystal library.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you , but how would we use with our current code that prints one character every time it circles in the loop?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31550
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you , but how would we use with our current code that prints one character every time it circles in the loop?
You make your code so that it dosn't. One way would be to use an escape sequence. When you see a certain character, one of the non printing ones, then the next few characters call up the set cursor method with those characters setting the position.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you think a character array would work better?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31550
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you think a character array would work better?
I have no idea how it would work at all. Cair to explain?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm thinking about finding away to store the characters for line 1 in an array , then a separate character array for line 2. The problem with this is I don't know how to set a character array to variable length in c (as the text to write to the LCD will change).
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31550
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You still have th same problem of knowing what array you are recieving and sorting a header from the actual data.
As for a C array just send the characters and end it with a null, this will give you a C string.
Logged

Pages: [1]   Go Up
Jump to: