硬件:
Arduino UNO 板+USB數(shù)據(jù)線绪颖;
-
Adafruit_RGBLCDShield;
3.PC.
軟件:
1.Arduino IDE+安裝LCD第三方模塊Adafruit_RGBLCDShield;Github RGB LCD library page (http://adafru.it/aMi).
Download the Adafruit RGB LCD Shield Library from :https://github.com/adafruit/Adafruit-RGB-LCD-Shield- Library/archive/master.zip,
To install it, download the compressed ZIP file then install it. This guide (http://adafru.it/aYM) will help you.
2.Python 2.7.12+安裝pyserial模塊;
操作:
- 將lcd顯示屏與Arduino板接好線路玛歌。電源+GND+讀數(shù)據(jù)锅风。
- Arduino UNO 連接電腦份乒。
- 將下列程序燒進(jìn)板里,不要打開串口監(jiān)視器涧衙。
---------------------------------------------------------------------------------------------------------
include <Wire.h>
include <Adafruit_RGBLCDShield.h>
include <utility/Adafruit_MCP23017.h>
include<stdlib.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
char line[50] = ""; // 傳入的串行數(shù)據(jù)
void setup() {
Serial.begin(9600); // 打開串口,設(shè)置數(shù)據(jù)傳輸速率9600
lcd.begin(16, 2);
}
void loop() {
// 串口可用時(shí)操作
if (Serial.available() > 0) {
// 讀取傳入的數(shù)據(jù): 讀到 \n 為止般婆,或者最多 500 個(gè)字符
Serial.readBytesUntil('\n', line, 50);
//打印你得到的:
Serial.println(line);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(line);
}
// 每1秒做一個(gè)輸出
delay(1000);
Serial.println("Arduino: Hello, python!");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Hello, Python!");
}
-----------------------------------------------------------------------------------------------------------#
- 等燒完程序,運(yùn)行下列python程序:
---------------------------------------------------------------------------------------------
!/usr/bin/env python
-- coding: UTF-8 --
import time
import serial
ser = serial.Serial('COM3',9600)
line = ser.readline()
while line:
print(line.strip())
line = ser.readline()
# 每 3 秒向窗口寫當(dāng)前計(jì)算機(jī)時(shí)間
sep = int(time.strftime("%S")) % 3
if sep == 0:
ser.write("Hi, Arduino")
ser.close()
---------------------------------------------------------------------------------------#
運(yùn)行結(jié)果:
圖片無法添加朵逝。damn蔚袍。。