2017-04-25 90 views
0

我厭倦了尋找如何運行這段代碼寫在使用MATLAB中的代碼將打印一條消息到LCD I2C的Arduino它的Arduino,但在MATLAB做工精細,有沒有辦法來運行這個代碼MATLAB或加載Arduino的代碼在MATLAB和運行...打印在LCD I2C的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(){ } 

回答

0
  1. 在Arduino的IDE開發的所有程序/草圖,你將需要

  2. 在Arduino的IDE,通過文件打開詳細的輸出 - >首選項

  3. 上傳程序Arduino的(例如,你在這裏粘貼的一個)。

  4. 當上傳完成時,記錄編譯輸出的最後一行。如果我的計劃被稱爲blink1,然後我救了這條線blink1_cmd.txt在refernce圖片

    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. 重複所必需的其他程序。