Hello, I'm currently working on my thesis, where I'm utilizing a custom-built Yagi Antenna to capture ADS-B messages, which I then decode using tools like pyModeS and RTL-SDR, among others. One of the challenges I'm facing is integrating my Python script with stepper motor control, possibly through UART communication.
My objective initially is to generate a simulated signal in Python to instruct the stepper motor to rotate either clockwise or counterclockwise. This is to prevent cable entanglement with my antenna setup on the platform.
Eventually, I aim to replace this simulated signal with a command like "track this ADS-B data package: XYZ, rotate CW/CCW until reaching the 180-degree limit" to optimize signal reception by following aircraft movements.
Another command I'm considering is to "Scan the airspace by rotating clockwise until the encoder indicates it's reached its limit. After that, rotate counterclockwise until the encoder signals the limit."
I have a rotating platform equipped with a stepper motor connected to a worm gear mechanism. To restrict rotation, I plan to incorporate an incremental rotary encoder from Baumer Electric. Datasheet of rotary encoder: https://www.baumer.com/medias/__secure__/Baumer_BRIH40_EcoMag_DS_EN.pdf?mediaPK=8800786513950
In the code below, I've started by using the rotary encoder as a control input for the stepper motor to familiarize myself with the hardware.
#include <Stepper.h>
// Define number of steps per revolution:
const int stepsPerRevolution = 200;
#define pwmA 3
#define pwmB 11
#define brakeA 9
#define brakeB 8
#define dirA 12
#define dirB 13
// Initialize the stepper library on the motor shield:
Stepper myStepper = Stepper(stepsPerRevolution, dirA, dirB);
volatile boolean TurnDetected; // volatile needed for Interrupts
volatile boolean rotationdirection; // CW or CCW rotation
// Rotary Encoder Module connections
const int PinCLK = 2; // Generating interrupts using CLK signal
const int PinDT = 3; // Reading DT signal
int StepsToTake = 1; // Controls the speed of the Stepper per Rotary click
// Interrupt routine runs if CLK goes from HIGH to LOW
void rotarydetect() {
// Read the state of the DT pin
rotationdirection = digitalRead(PinDT);
// Set the flag to indicate rotation detected
TurnDetected = true;
}
void setup() {
// Set the PWM and brake pins so that the direction pins can be used to control the motor:
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);
// Set the motor speed (RPMs):
myStepper.setSpeed(30);
pinMode(PinCLK, INPUT); // Set Pin to Input
pinMode(PinDT, INPUT);
// Enable pull-up resistor for CLK pin
digitalWrite(PinCLK, HIGH);
// Attach interrupt to the CLK pin
attachInterrupt(digitalPinToInterrupt(PinCLK), rotarydetect, FALLING);
}
void loop() {
if (TurnDetected) {
TurnDetected = false; // Reset flag
// Move the stepper motor based on the calculated StepsToTake and rotation direction
if (rotationdirection) {
myStepper.step(StepsToTake);
} else {
myStepper.step(-StepsToTake);
}
}
}
Do you have any suggestions on how I could approach this task? I'd greatly appreciate any input you can provide. Thank you in advance for your response.




