简体   繁体   English

使用Matlab在LCD I2C Arduino中打印

[英]Print in LCD I2C arduino by using matlab

I get tired to find how to run this code written in arduino using matlab the code will print a message into LCD I2C it work fine in arduino but in matlab is there a way to run this code in matlab or load the arduino code in matlab and run... 我很疲倦地发现如何使用Matlab运行用arduino编写的代码,该代码将在LCD I2C中打印一条消息,在arduino中可以正常工作,但是在matlab中,有一种方法可以在matlab中运行此代码或在matlab中加载arduino代码跑...

//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. Develop in the Arduino IDE all of the programs/sketches that you will need 在Arduino IDE中开发您需要的所有程序/草图

  2. In the Arduino IDE, turn ON verbose output via File -> Preferences 在Arduino IDE中,通过File-> Preferences打开详细输出

  3. Upload program to Arduino (for example the one you have pasted here). 将程序上传到Arduino(例如,您在此处粘贴的程序)。

  4. When upload is finished, record the last line of the compilation output. 上传完成后,记录编译输出的最后一行。 If my program is called blink1, then I saved this line to blink1_cmd.txt 如果我的程序叫做blink1,那么我将这一行保存到blink1_cmd.txt

    参考图片

    notice in the refernce picture the last line is: 注意参考图片中的最后一行是:

     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. Find the HEX file associated with your program and save it elsewhere. 查找与您的程序关联的HEX文件,并将其保存在其他位置。 in the case above: 在上述情况下:

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

    And I moved it to: 我将其移至:

     C:\\Users\\PAULJO~1\\Documents\\MATLAB\\TestCode\\Arduino\\ArduinoIdeProgramming\\blink1.cpp.hex 
  6. In your text file, update the HEX file path. 在您的文本文件中,更新HEX文件路径。

  7. Copy the entire line from the text file. 从文本文件复制整行。

  8. In the Matlab command window: 在Matlab命令窗口中:

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

    You should get an output of: 您应该得到以下输出:

     avrdude done. Thank you. 
  9. Repeat as necessary for the other programs. 对其他程序根据需要重复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM