I want to send a signal to my Arduino Mega as soon as I detect something. It worked fine with 5v, but for some reason, my camera doesn't work with 5v anymore. So, I switched to 3.3v. The camera worked and it even sent the signal to the board. The arduino board did what it was supposed to do and sent back a signal, when it was done, but the camera didn't receive anything...
Is that, because the communication only works with 5v? Or is it a problem with my code?
Here my OpenMV code:
Code: Select all
w = min(max(int(blob.w() * 1.2), 10), 160) # Not too small, not too big.
h = min(max(int(blob.h() * 1.2), 10), 160) # Not too small, not too big.
x = min(max(int(blob.x() + (blob.w()/4) - (w * 0.1)), 0), img.width()-1)
y = min(max(int(blob.y() + (blob.h()/4) - (h * 0.1)), 0), img.height()-1)
out = net.forward(img.binary([(100, 255)]), softmax=True, roi=(x,y,w,h))
max_idx = out.index(max(out))
score = int(out[max_idx]*100)
if (score < 50):
score_str = "??:??%"
else:
score_str = "%s:%d%% "%(labels[max_idx], score)
img.draw_string(0, 0, score_str, color=(0, 255, 0))
print(labels[max_idx])
if (score > 70):
if (labels[max_idx] == "H"):
print("HHHHH")
uart.write("h\r")
answerH = False
while (answerH == False):
if uart.any():
nachrichtVonArduino = uart.readchar()
nachrichtenKontrolle = 209 #ID for letter h
if (id(nachrichtVonArduino) == nachrichtenKontrolle):
print("H ist korrekt!")
answerH = True;
elif (labels[max_idx] == "S") or (labels[max_idx] == "s"): # or (labels[max_idx] == "5"):
print("SSSSS")
uart.write("s\r")
answerS = False
while (answerS == False):
if uart.any():
nachrichtVonArduino = uart.readchar()
nachrichtenKontrolle = 231 #ID for letter S
if (id(nachrichtVonArduino) == nachrichtenKontrolle):
print("S ist korrekt!")
answerS = True;
elif (labels[max_idx] == "U") or (labels[max_idx] == "u"): # or (labels[max_idx] == "v"):
print("UUUUUU")
uart.write("u\r")
answerU = False
while (answerU == False):
if uart.any():
nachrichtVonArduino = uart.readchar()
nachrichtenKontrolle = 235 #ID for letter U
if (id(nachrichtVonArduino) == nachrichtenKontrolle):
print("U ist korrekt!")
answerU = True;
print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected
# to the IDE. The FPS should increase once disconnected.
Code: Select all
// 104: ID for h
// 115: ID for s
// 117: ID for u
// white: TX1
// black: RX1
// yellow: GND
// red: 5v/3.3v
#include <Wire.h>
void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial1.begin(9600);
Serial.println("Auf gehts!");
pinMode(9, OUTPUT); //LED
}
void loop() {
// read from port 1, send to port 0:
// from Camera to Arduino
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
if (inByte == 104)
{
for(int i = 0; i < 5; i++)
{
digitalWrite(9, HIGH);
Serial.println("ON");
delay(500);
digitalWrite(9, LOW);
Serial.println("OFF");
delay(500);
}
// h detected, deploying 2 rescue kits
Serial.println("");
Serial.println("H detected! Rescue procedure started...");
Serial1.write("h");
}
else if (inByte == 115)
{
for(int i = 0; i < 5; i++)
{
digitalWrite(9, HIGH);
Serial.println("ON");
delay(500);
digitalWrite(9, LOW);
Serial.println("OFF");
delay(500);
}
// s detected, deploying 1 rescue kits
Serial.println("");
Serial.println("S detected! Rescue procedure started...");
Serial1.write("s");
}
else if (inByte == 117)
{
for(int i = 0; i < 5; i++)
{
digitalWrite(9, HIGH);
Serial.println("ON");
delay(500);
digitalWrite(9, LOW);
Serial.println("OFF");
delay(500);
}
// u detected, deploying 0 rescue kits
Serial.println("");
Serial.println("U detected! Rescue procedure started...");
Serial1.write("u");
}
}
}
Thank you very much,
Finn