enter image description here

I am trying to send some integers to an LCD. But it is not working. I have tried in Proteus. Please help. I have uploaded MATLAB and Arduino code below.

MATLAB code:

clear all
clc

 answer=1; % this is where we'll store the user's answer
 arduino=serial('COM1','BaudRate',9600); % create serial communication object on port COM4

fopen(arduino); % initiate arduino communication

while answer
fprintf(arduino,'%s',char(answer)); % send answer variable content to arduino
answer=input('Enter led value 1 or 2 (1=ON, 2=OFF, 0=EXIT PROGRAM): '); % ask user to enter value for variable answer
end

fclose(arduino); % end communication with arduino

Arduino code:

#include <LiquidCrystal.h>
int matlabData;
LiquidCrystal lcd(12,11,5,4,3,2);

void setup() {
  lcd.begin(16,2);
  Serial.begin(9600);
}

void loop() {
  if(Serial.available()>0) {
    matlabData=Serial.read();
    lcd.print(matlabData);
  }
}
share|improve this question

migrated from electronics.stackexchange.com Jan 12 at 21:09

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

1  
What exactly is not working? The LCD? Setting up the COM port on the host? Receiving serial data on the arduino? What have you tried? – polwel Jan 12 at 9:39
    
lcd shows nothing.I have given the input with the help of MATLAB but still lcd shows nothing. – Chandan Gogoi Jan 12 at 9:42
    
Not a Matlab expert, but if you enter '1', doesn't `input' yield the int 1? If sou, you are trying to display not the character '1', but the byte 1. – polwel Jan 12 at 9:46
    
First, try to write anything to the LCD. Not serial data, just 'hello world'. See if that works. – polwel Jan 12 at 9:47
    
With the help of ARDUINO,it works.But if I use matlab,it doesn't work.I am gonna upload a pic,take a look.... – Chandan Gogoi Jan 12 at 9:51

you can use Matlab's Arduino support package, it allows you to control the arduino directly without having to write a code in Arduino IDE. I never used it with an LCD though. here is a link that might help: https://www.mathworks.com/hardware-support/arduino-matlab.html

share|improve this answer
    
I already have installed all the packages required for arduino.This is working for led only.With the help of matlab I can easily control a led.But in case of lcd,I am facing this problem. – Chandan Gogoi Jan 12 at 9:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.