Arduino + Sparkfun SerLCD + vb .net problem

Hello,
I'm trying to control a Sparkfun SerLCD using the SerialPort class in vb.net, but I'm having some issues sending control characters to the screen. I can send the 'clear screen command', but not anything else.

The LCD screen clears up when you send special command character '0xFE' followed by '0x01'. In Arduino language:

Serial.print(0xFE, BYTE);   //command flag, decimal 254
Serial.print(0x01, BYTE);   //clear command

In vb .net, the following works:

Using com1 As IO.Ports.SerialPort = My.Computer.Ports.OpenSerialPort("COM3")
com1.Write(ChrW(254) + ChrW(124))
com1.Close()

However, I cannot get the cursor positioning to work in vb! While in Arduino language the correct code is:

void selectLineOne(){  //puts the cursor at line 0 char 0.
   Serial.print(0xFE, BYTE);   //command flag, decimal 254
   Serial.print(128, BYTE);    //position
}

the following code does not work in vb, and I get two '??' questionmarks characters printed on the screen!

com1.Write(ChrW(254) + ChrW(128))

Any help? How can I transmit the 128 code to serial port in vb?
Thanks for reading.

Alex

If you've got the LCD connected to pins 0 and 1 then you shouldn't be connecting to the PC at the same time.

Move the LCD off of the hardware serial port and use http://arduino.cc/en/Reference/SoftwareSerial for talking to the LCD and the hardware Serial for talking to the PC.

Then just check to see if data is available from the hardware Serial and if it is write the data to the SoftwareSerial.

Thanks for the reply.
I have SerLCD connected to GND,5V and TX pin, as described here:Arduino Playground - SparkFunSerLCD. The Arduino program simply gets the serial data and writes it to the SoftwareSerial as you describe.

My vb .net program sends normal text (ASCII characters) and Arduino sends them correctly to the SerLCD display. That part works! My problem is sending the special characters from the vb program! When I send the com1.Write(ChrW(254) + ChrW(128)) command from vb, instead of the cursor moving to line1 as it should, i get questionmarks like this '??'.

I think it has to do with the vb commands, I tried both Chr() and ChrW() but with no luck..

Well, I can tell that ChrW is wrong, you want 8bit characters not unicode wide characters.

Question: is a Char in VB an integral type for which + is addition or is it a string type for which + is concat?

Does ths work?

com1.Write( Chr(254) )
com1.Write( Chr(128) )

Or perhaps coercing the data to a string type by explicit concat of a null string?

com1.Write( Chr(254) + "" + Chr(128)  )

-edit- I have no idea how ChrW() got into the code blocks originally. Lack of attention to detail on my part.

Thanks for reply!
You pointed me to the right direction, i've found the solution.

In order to send special characters in vb .net to SerLCD you should send them as hex:

Using com1 As IO.Ports.SerialPort = My.Computer.Ports.OpenSerialPort("COM3")
Dim data() As Byte = {&HFE, &H1} 'clear the screen
com1.Write(data, 0, data.Length)

Dim data2() As Byte = {&HFE, 128} 'move cursor to line 1
com1.Write(data2, 0, data.Length)

com1.Close()

:smiley: ;D