I am working on a project where I have a stepper motor controlling a camera slider. The slider is programmed to stop at a petri dish as the camera moves along. I have a functioning stepper motor currently but I am having trouble writing a code for the arduino to tell the raspberry pi to take a photo of the petri dish. That also entails a code on the raspberry pi side in which it recieves this "take the photo command" and then proceeds to take a photo. I'm not sure whether to also add information being sent to the arduino from the pi after the photo has been taken to have the stepper motor continue onto the next petri dish. Currently the stepper motor is programmed to stop for 15 seconds before continuing which bypasses this extra code. If anyone could help me out/ have a generalized code that I can use and tweak this would be greatly appreciated!! Any thoughts is appreciated as well! Thank you in advance!
Are you looking for code for the Pi to react to the command from the Arduino or for Arduino code to send the command ?
The easiest way would be for the Arduino to change the state of one of its pins connected to a pin on the Pi and for the Pi to detect the change of state and take the picture
Thank you for your response, its greatly appreciated! I like that idea of directly connecting the raspberry pi to the arduino with a wire and then having that pin be programmed to be "high/low" after the stepper motor stops. Would it be possible to then have the raspberry pi camera switch that same pin off once the picture is taken? That way the arduino knows that the picture has been taken?
Using a second pin on both devices for confirmation would be easier and more robust or you could implement a serial connection between the devices and implement 2 way communication or even wireless communication
as @UKHeliBob says use two wires
what Arduino are you using?
the Raspberry PI is a 3.3V device - if you are using a 5V arduino you will require` level converters or you will damage the PI
I don't want this to be super complicated whichever method is easiest I will probably use. Do you recommend bidirectional communication using serial as easier? I may be able to get away with just the arduino telling the raspberry pi to take the photo and then having a set amount of seconds before the stepper continues to the next dish. Thank you!
Hi-
I'm very new at coding and was using a tutorial that used an arduino for the stepper and gave me base code for that. Thats the only reason the arduino is being used here and at this point I don't have much time to change the set up unfortunately!!
Hi,
Yes, I want the pi to tell the arduino to move the stepper motor. But I also need something to initiate the taking of the picture as well. Once the stepper stops at the petri dish, it will need to somehow tell the pi to take the picture first which is how I am thinking of this
the UNO is a 5V device - it may be simpler to switch to a 3.3V Arduino
probably a pair of digital IO lines for communication is the simplest approach rather than using serial commands
what language do you use to program the PI?
Yes, a second line from the Arduino to the pi to indicate the motor has stopped moving would seem like a good idea. But as noted, you need to reduce that from 5V to 3.3V which can easily be done with a couple of resistors (e.g. 10K & 22K)
Okay, thank you! I have decided to just do one line going from the arduino to the raspberry pi through a wire. When the wire is high, the raspberry pi will take the photo. instead of having a signal go back to the arduino to say the photo has been taken, I will just have the arduino wait a certain number of seconds before continuing. I have used a bidirectional level shiftor and followed this tutorial: Using a Logic-level Shifter with Raspberry Pi 2023 | Little Bird
to account for the difference of 5V to 3.3V.
Does anyone know if I need a pull up resistor for this circuit?