How to send data from ASP.Net C# to Arduino through Serial and print it on LCD? -
i have asp.net page login/register operations. i'm trying show user name on lcd when user logs in. hardware i'm using lcd keypad shield not lcd if matters. , lovely arduino uno.
c# side
i tried storing username in char array , send arduino 1 one serial.write() gives error if don't give string it. wanted send whole name @ once then, serial.read() seems reading 1 @ time.
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 = 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(); (int = 0; < outgoing.length; i++) { sp.open(); sp.write(outgoing[i].tostring()); sp.close(); } response.redirect("default.aspx"); } } }
arduino side
#include <liquidcrystal.h> 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()>0){ if(index<10){ y=1; incomingchar=serial.read(); usrname[index]=incomingchar; lcd.setcursor(x,y); lcd.print(usrname[index]); index++; x++; } } }
both codes not give errors or warnings. when upload program arduino , run login page, succesfully redirected page stated nothing shows on lcd.
actually see after login site. have no idea why there white cells, show when plug in board. when upload example program keypad shield cells turn normal.
i found out order of pin numbers mattered. changed liquidcrystal lcd(4,5,6,7,8,9);
line liquidcrystal lcd(8,9,4,5,6,7);
can see desired output , there no white cells on startup too.
Comments
Post a Comment