openmv 與arduino 第一次通訊
openmv 與 arduino 第一次 通訊成功
幾個筆記
mv程式碼
import sensor, image, time
import json
from pyb import UART
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # use RGB565.
sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
sensor.skip_frames(10) # Let new settings take affect.
sensor.set_auto_whitebal(False) # turn this off.
clock = time.clock() # Tracks FPS.
uart = UART(3, 9600)
while(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
img.lens_corr(1.5)
for code in img.find_qrcodes():
message = code.payload()
uart.write(message)
print(code)
else:
print(“not found!”)
arduino程式碼
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10,11);//RX=2,TX=3
void setup()
{
//硬體串列埠波特率
Serial.begin(9600);
//軟體串列埠波特率
mySerial.begin(9600);
pinMode(7, OUTPUT);
}
void loop()
{
//如果硬體串列埠有資料
if(Serial.available())
{
//從硬體串列埠讀出一位元組,寫入軟體串列埠
mySerial.write(Serial.read());
if(Serial.read()==123)
{
digitalWrite(7, HIGH);
}
}
//如果軟體串列埠有資料
if(mySerial.available())
{
//從軟體串列埠讀出一位元組,寫入硬體串列埠
Serial.write(mySerial.read());
}
}