使用matlab在LCD I2C arduino中打印

时间:2017-04-25 20:53:22

标签: matlab arduino display i2c lcd

我厌倦了找到如何使用matlab运行这个用arduino编写的代码代码会将信息打印到LCD I2C中它在arduino中工作得很好但是在matlab中有一种方法可以在matlab中运行这段代码或加载arduino代码在matlab中运行...

//load libraries
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

//Define variables 

#define I2C_ADDR          0x3F        //Define I2C Address where the PCF8574A is
#define BACKLIGHT_PIN      3
#define En_pin             2
#define Rw_pin             1
#define Rs_pin             0
#define D4_pin             4
#define D5_pin             5
#define D6_pin             6
#define D7_pin             7

//Initialise the LCD
LiquidCrystal_I2C      lcd(I2C_ADDR, En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()
 {
    //Define the LCD as 16 column by 2 rows 
    lcd.begin (16,2);

    //Switch on the backlight
    lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
    lcd.setBacklight(HIGH);

    //goto first column (column 0) and first line (Line 0)
    lcd.setCursor(0,0);

    //Print at cursor Location
    lcd.print("Finally!");

    //goto first column (column 0) and second line (line 1)
    lcd.setCursor(0,1);
    lcd.print("Work :)");

 }


void loop(){ }

1 个答案:

答案 0 :(得分:0)

  1. 在Arduino IDE中开发您需要的所有程序/草图

  2. 在Arduino IDE中,通过File - &gt;打开详细输出。偏好设置

  3. 将程序上传到Arduino(例如您在此处粘贴的程序)。

  4. 上传完成后,记录编译输出的最后一行。如果我的程序名为blink1,那么我将此行保存到blink1_cmd.txt

    reference image

    在参考图片中注意最后一行是:

    C:\ArduinoIDE\hardware/tools/avr/bin/avrdude -CC:\ArduinoIDE\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -carduino -P\\.\COM9 -b115200 -D -Uflash:w:C:\Users\PAULJO~1\AppData\Local\Temp\build6145494704296263461.tmp\blink1.cpp.hex:i
    
  5. 找到与您的程序相关联的HEX文件并将其保存在其他位置。在上面的情况:

    C:\Users\PAULJO~1\AppData\Local\Temp\build6145494704296263461.tmp\blink1.cpp.hex
    

    我把它移到了:

    C:\Users\PAULJO~1\Documents\MATLAB\TestCode\Arduino\ArduinoIdeProgramming\blink1.cpp.hex
    
  6. 在文本文件中,更新HEX文件路径。

  7. 从文本文件中复制整行。

  8. 在Matlab命令窗口中:

    [status,cmdout] = dos(' paste code here ')
    

    你应该得到一个输出:

    avrdude done. Thank you.
    
  9. 根据需要重复其他程序。