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());
}
}