arduino程序
// OpenMV Cam UART3_TX(P4) ----> Arduino Uno UART_RX(5)
// OpenMV Cam UART3_RX(P5) ----> Arduino Uno UART_TX(6)
// OpenMV Cam gnd----> Arduino Uno gnd
#include <SoftwareSerial.h>
SoftwareSerial BTserial(5,6); // 建立SoftwareSerial对象,RX引脚5, TX引脚6
int b=0;
void setup() {
Serial.begin(9600);
BTserial.begin(9600); // HC-06 默认波特率 9600
}
void loop() {
int a = 1;
if (a = 1) //a区,收到A板发出的消息,左采摘
{ switch (b) {
case 0:
delay(3000);
BTserial.write("8"); b = 30; //给openmv发一次消息
Serial.println("transmit");
delay(1000);
}
if (BTserial.available()) //读取open mv的消息
{ char c = BTserial.read();
Serial.println(c);
delay(1000);
if (c == 'n')
{
delay(1000);
Serial.println("end");
b = 0; //b恢复
}
}
}
}
openmv程序
# OpenMV Cam UART3_TX(P4) ----> Arduino Uno UART_RX(5)
# OpenMV Cam UART3_RX(P5) ----> Arduino Uno UART_TX(6)
import time
from pyb import UART
uart = UART(3, 9600,timeout=10000000,read_buf_len=1)
while True :
receive = uart.read(1) #读到一个数据,把一个数据赋值给receive
print(receive) #读到8会变成b'8'
time.sleep_ms(200)
if receive == b'8' :#与arduino通讯A区8=b'\x08' 左边光电
print("receive")
time.sleep_ms(2000)
uart.write('n')#发送完成信号
print("transmit")
break