Я пытаюсь, чтобы мой ESP-32 посылал высокий сигнал на Raspberry pi 3 B +.Я уже пробовал использовать разные контакты, но результат всегда одинаков.Малиновые вещи он всегда получает высокий вклад.Цель состоит в том, чтобы малина сфотографировалась, когда ESP 32 посылает высокую производительность.Прежде чем спросить, как ESP должен знать, когда он должен отправить вывод.Ну, это когда он обнаруживает объект.
Здесь вы можете увидеть мой код 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 18 as input
if __name__=='__main__':
#Variable
cam = Picamera() # makes the variable cam
while True:
if(GPIO.input(11) == GPIO.HIGH):
#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
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) # method that take a photo and then save it on the local desktop as the name of newimagen
Здесь мой код Arduino
// Define SensorS pins
#define trigPin 15
#define echoPin 2
//Define SensorXL pins
#define trigPinXL 14
#define echoPinXL 13
//Define Raspberry Pin
#define RaspiPin 26
//Define Motor pins
#define motorIn3 16 //Input 3
#define motorIn1 17 //Input 1
#define motorIn4 18 //Input 4
#define motorIn2 19 //Input 2
// Defines variables
long duration;
int distance;
// Define ActivateDistance
const int activateDistance = 40;
const int activateDistance2 =40;
void setup()
{
// Sets the trigPin as an Output
pinMode(trigPin, OUTPUT);
pinMode(trigPinXL, OUTPUT);
// Sets the echoPin as an Input
pinMode(echoPin, INPUT);
pinMode(echoPinXL, INPUT);
// sets the Motorpins as outputs:
pinMode(motorIn1, OUTPUT);
pinMode(motorIn2, OUTPUT);
pinMode(motorIn3, OUTPUT);
pinMode(motorIn4, OUTPUT);
//Sets Raspberry Pin as output
pinMode(RaspiPin, OUTPUT);
// Starts the serial communication
Serial.begin(9600);
}
void stop()
{
// stop motor without duration
Serial.println("STOP");
digitalWrite(motorIn1, LOW);
digitalWrite(motorIn2, LOW);
digitalWrite(motorIn3, LOW);
digitalWrite(motorIn4, LOW);
}
void left(int duration)
{
//Motor goes to left
Serial.println("LEFT");
digitalWrite(motorIn1, LOW);
digitalWrite(motorIn2, HIGH);
digitalWrite(motorIn3, HIGH);
digitalWrite(motorIn4, LOW);
delay(duration);
stop();
}
void right(int duration)
{
//Motor goes to left
Serial.println("RIGHT");
digitalWrite(motorIn1, HIGH);
digitalWrite(motorIn2, LOW);
digitalWrite(motorIn3, LOW);
digitalWrite(motorIn4, HIGH);
delay(duration);
stop();
}
void forward(int duration)
{
//Motor goes forward
Serial.println("FORWARD");
digitalWrite(motorIn2, HIGH);
digitalWrite(motorIn4, HIGH);
digitalWrite(motorIn3, LOW);
digitalWrite(motorIn1, LOW);
delay(duration);
stop();
}
long get_distance(void)
{
//get distance from sensor
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
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;
return distance;
}
long get_distanceXL(void)
{
//get distance from sensor
// Clears the trigPin
digitalWrite(trigPinXL, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPinXL, HIGH);
delayMicroseconds(10);
digitalWrite(trigPinXL, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPinXL, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
return distance;
}
int turn = 0;
void loop()
{
// check sensor
if (get_distance() <= activateDistance)
{
Serial.println("Found an Obstacle!!!");
// go right for 1 second
right(1000);
while(turn<4)
{
//turn on the Raspberry Pin
digitalWrite(RaspiPin, HIGH);
if(get_distanceXL()>activateDistance2)
{
//go left for 1 second
left(1000);
forward(1500);
turn = turn + 1;
}
else
//go forward for 1 second
forward(1000);
}
//turn off the Raspberry Pin
digitalWrite(RaspiPin, LOW);
}
else
// go forward for 1 second
forward(1000);
}
Я открыл свойТерминал и увидел эту проблему.Я не уверен, поможет ли это с моей проблемой:
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))0x1d13d20 (ENOSPC)
mmal: mmal_connection_enable: output port couldn't be enabled
Traceback (most recent call last):
File "/home/pi/Desktop/camera.py", line 12, in <module>
cam = PiCamera() # makes the variable cam
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