当ESP用超声波传感器检测到物体时,我希望ESP32向Raspberry发出信号。收到信号后,Raspberry会拍照。
我的问题是我尝试使用LED“信号”中的信号代码,但无法正常工作。它始终显示,当Raspberry和ESP在镜像中连接此问题时:
mmal: mmal_vc_port_enable: failed to enable port vc.null_sink:in:0(OPQV): ENOSPC
mmal: mmal_port_enable: failed to enable connected port (vc.null_sink:in:0(OPQV))0x1d08dc0 (ENOSPC)
mmal: mmal_connection_enable: output port couldn't be enabled
Traceback (most recent call last):
File "camera.py", line 18, in <module>
cam = PiCamera()
File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 433, in __init__
self._init_preview()
File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 513, in _init_preview
self, self._camera.outputs[self.CAMERA_PREVIEW_PORT])
File "/usr/lib/python2.7/dist-packages/picamera/renderers.py", line 558, in __init__
self.renderer.inputs[0].connect(source).enable()
File "/usr/lib/python2.7/dist-packages/picamera/mmalobj.py", line 2212, in enable
prefix="Failed to enable connection")
File "/usr/lib/python2.7/dist-packages/picamera/exc.py", line 184, in mmal_check
raise PiCameraMMALError(status, prefix)
picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources
------------------
(program exited with code: 1)
Press return to continue
我已经尝试使用app.run(host = '0.0.0.0')
修复ID,但是它向我展示了相同的问题。
这是我的Python代码:
import time
import os # import the time
from picamera import PiCamera # import image from the camera into the Raspberry
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # define pins
GPIO.setup(11, GPIO.IN) # setup pin 11 as input
if __name__=='__main__':
while True:
if(GPIO.input(11) == GPIO.HIGH):
#Variables
cam = PiCamera()
# make the variable cam
#Define how newimagen is made of (Variable) # make the variable fname which give us the date and Time
os.chdir('/home/pi/Desktop/image/') # Define where we are working now
images = [i for i in os.listdir(os.getcwd()) if i.lower().startswith('image')] # define what images is :
# os.listdir returns a list containing of the entries in the directory os.getcwd...
# os.getcwd returns the current working directory of a process --> '/home/pi/Desktop/'
if images:
newest = max(images, key=os.path.getmtime) # max() is a method that returns the largest item of sth
# os.path.getmtime return the time of last modification
else:
newest = 'image0.jpg'
number = int(''.join([i for i in newest if i.isdigit()])) #number is the number of the newest image : image1 --> number = 1. This method look up if there is an image and which number it has
newimagen = 'image'+str(number+1)+'.jpg' # newimagen is the variable that decide which image it will be(image1 or image2...)
#Camera Code changing
cam.resolution = (2592,1944) # method to change the resoltuion
#Main Code
cam.capture('/home/pi/Desktop/image/'+newimagen)
这是我的Arduino代码:
// defines pins numbers
#define trigPin 12
#define echoPin 13
#define ledPin 14
// defines variables
long duration;
int distance;
boolean triggered = false;
double activateDistance = 10;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // Starts the serial communication
}
void loop()
{
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
if (distance <= activateDistance)
{
digitalWrite(ledPin, HIGH);
Serial.print("GOT");
delay(1000);
digitalWrite(ledPin,LOW);
}else{
digitalWrite(ledPin,LOW);
}
}
目前,它仅使LED点亮,我认为(朋友也是如此),可以使用相同的代码将信号发送到Raspberry。
如果这个社区的人们可以帮助我,那将是非常棒的。如有任何问题,请随时纠正我。
答案 0 :(得分:1)
尽量减少问题原因。
从我看到的错误来看,问题在于/search
模块无法正常工作,因此我认为最好测试您的pi并查看它是否与{{ 3}}:
PiCamera
如果它不起作用,那么您只能专注于真正的问题。
此外,我怀疑while循环中是否存在import time
import picamera
with picamera.PiCamera() as camera:
camera.start_preview()
time.sleep(10)
camera.stop_preview()
,请在循环之前将其移动并再次检查:
cam = PiCamera()