title: How to send data from ASP.Net C# to Arduino through Serial and print it on LCD?
body: <p>I have an ASP.Net page for login/register operations. What I'm trying to do is show the user name on LCD when the user logs in. The hardware I'm using is LCD Keypad Shield not just LCD if that matters. And the lovely Arduino UNO.</p>
  
  <p>C# side</p>
  
  <p>I tried storing the username in a char array and send to arduino one by one but the Serial.Write() gives error if I don't give a string to it. I wanted to send the whole name at once then, but Serial.Read() seems to be reading one at a time.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Web.Security;
  using System.IO.Ports;
  using System.Text;
  using System.ComponentModel;
  using System.Windows;
  
  namespace EComm
  {
      public partial class Login : System.Web.UI.Page
      {
          SerialPort sp;
          protected void Page_Load(object sender, EventArgs e)
          {
              sp = new SerialPort();
              sp.PortName = "COM13";
              sp.BaudRate = 9600;
              txtPass.TextMode = TextBoxMode.Password;
          }
  
          protected void Button1_Click(object sender, EventArgs e)
          {
              DBDataContext db = new DBDataContext();
              db.Connection.Open();
              var users = from allusers in db.Users select allusers;
              foreach (User _user in users)
              {
                  if (txtUser.Text == _user.UserName.Trim())
                      if (txtPass.Text == _user.UserPassword.Trim())
                      {
                          Session["User"] = _user.UserName;
                          String outgoing = Session["User"].ToString();
                          for (int i = 0; i &lt; outgoing.Length; i++)
                          {
                              sp.Open();
                              sp.Write(outgoing[i].ToString());
                              sp.Close();
                          }
                          Response.Redirect("Default.aspx");
                      }
              }
          }
  </code></pre>
  
  <p>Arduino side</p>
  
  <pre><code>#include &lt;LiquidCrystal.h&gt;
  char usrName[10];
  char incomingChar;
  byte index=0;
  
  LiquidCrystal lcd(4,5,6,7,8,9);
  int baud = 9600; 
  int x=0;
  int y=0;
  
  void setup()
  {
   lcd.begin(16,2);
   lcd.setCursor(x,y); 
   Serial.begin(baud);
  }
  
  void loop()
  {
      while(Serial.available()&gt;0){
      if(index&lt;10){
        y=1;
        incomingChar=Serial.read();
        usrName[index]=incomingChar;
        lcd.setCursor(x,y);
        lcd.print(usrName[index]);
        index++;
        x++;
      }
  }
  }
  </code></pre>
  
  <p>Both codes do not give any errors or warnings. When I upload the program to Arduino and run the login page, I am succesfully redirected to the page stated but nothing shows up on the LCD.</p>
  
  <p>Actually this is what I see after I login to the site. I have no idea why there are white cells, they just show up when I plug in the board. But when I upload an example program for keypad shield those cells just turn to normal.</p>
  
  <p><img src="https://i.stack.imgur.com/3cRjG.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/FsHXY.jpg" alt="enter image description here"></p>