Good afternoon, I want the rotor handling program for the arduous nano to be able to install a 1602 LCD, I manage to do it but it breaks the link with hamlib and gives that error of -5 try various shapes and even use chatgpt but always breaks the link with hamlib. I really don’t know why it happens, if someone could do it and share the code it is appreciated and if someone else tells me that program structure error happens.
Hi,
The way it goes, you share your code and others can look at it and might see some issue that is fixable.
If it’s a git repo you cloned I suggest you fork it, create a branch in it and commit your changes. Different experiments should live in separate branches, then it’s much easier to swap between them. Also much easier to see what changes has been made and track them.
My first guess is some form of timeout caused by using delay() or functions blocking for a long time.
Second guess is the LCD library messes with the serial port, in that case pay attention to the order of initialization.
fixed the firmware now I will see if everything works I share the code, it is for arduino nano.
/*!
- @file stepper_motor_controller.ino
- Este es el firmware original con la adición de un LCD I2C.
*/
#define SAMPLE_TIME 0.1 ///< Control loop in s
#define RATIO 13 ///< Gear ratio of rotator gear box default 54
#define MICROSTEP 8 ///< Set Microstep default 8
#define MIN_PULSE_WIDTH 20 ///< In microsecond for AccelStepper
#define MAX_SPEED 1200 ///< In steps/s, consider the microstep default 3200
#define MAX_ACCELERATION 1000 ///< In steps/s^2, consider the microstep default 1600
#define SPR 800L ///< Step Per Revolution, consider the microstep default 1600
#define MIN_M1_ANGLE 0 ///< Minimum angle of azimuth
#define MAX_M1_ANGLE 360 ///< Maximum angle of azimuth
#define MIN_M2_ANGLE 0 ///< Minimum angle of elevation
#define MAX_M2_ANGLE 180 ///< Maximum angle of elevation
#define DEFAULT_HOME_STATE HIGH ///< Change to LOW according to Home sensor
#define HOME_DELAY 12000 ///< Time for homing Deceleration in millisecond
#include <AccelStepper.h>
#include <Wire.h>
#include “globals.h”
#include “easycomm.h”
#include “rotator_pins.h”
//#include <rs485.h>
#include “endstop.h”
//#include <watchdog.h>
#include <LiquidCrystal_I2C.h> // Biblioteca para manejar LCD por I2C
#define LCD_ADDRESS 0x27 // Dirección del LCD I2C
#define LCD_COLUMNS 16 // Número de columnas del LCD
#define LCD_ROWS 2 // Número de filas del LCD
LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_COLUMNS, LCD_ROWS);
uint32_t t_run = 0; // run time of uC
easycomm comm;
AccelStepper stepper_az(1, M1IN1, M1IN2);
AccelStepper stepper_el(1, M2IN1, M2IN2);
endstop switch_az(SW1, DEFAULT_HOME_STATE), switch_el(SW2, DEFAULT_HOME_STATE);
//wdt_timer wdt;
enum _rotator_error homing(int32_t seek_az, int32_t seek_el);
int32_t deg2step(float deg);
float step2deg(int32_t step);
void setup() {
// Configuración del LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" LW2DYB "); // Texto centrado en pantalla superior
// Homing switch
switch_az.init();
switch_el.init();
// Serial Communication
comm.easycomm_init();
// Stepper Motor setup
stepper_az.setEnablePin(MOTOR_EN);
stepper_az.setPinsInverted(false, false, true);
stepper_az.enableOutputs();
stepper_az.setMaxSpeed(MAX_SPEED);
stepper_az.setAcceleration(MAX_ACCELERATION);
stepper_az.setMinPulseWidth(MIN_PULSE_WIDTH);
stepper_el.setPinsInverted(false, false, true);
stepper_el.enableOutputs();
stepper_el.setMaxSpeed(MAX_SPEED);
stepper_el.setAcceleration(MAX_ACCELERATION);
stepper_el.setMinPulseWidth(MIN_PULSE_WIDTH);
// Initialize WDT
// wdt.watchdog_init();
}
void loop() {
// Actualización del LCD
lcd.setCursor(0, 1);
lcd.print("AZ: “);
lcd.print(step2deg(stepper_az.currentPosition()), 1); // Una cifra decimal
lcd.print(” EL: ");
lcd.print(step2deg(stepper_el.currentPosition()), 1); // Una cifra decimal
// Código original
rotator.switch_az = switch_az.get_state();
rotator.switch_el = switch_el.get_state();
comm.easycomm_proc();
control_az.input = step2deg(stepper_az.currentPosition());
control_el.input = step2deg(stepper_el.currentPosition());
if (rotator.rotator_status != error) {
if (rotator.homing_flag == false) {
rotator.control_mode = position;
rotator.rotator_error = homing(deg2step(-MAX_M1_ANGLE), deg2step(-MAX_M2_ANGLE));
if (rotator.rotator_error == no_error) {
rotator.rotator_status = idle;
rotator.homing_flag = true;
} else {
rotator.rotator_status = error;
rotator.rotator_error = homing_error;
}
} else {
stepper_az.moveTo(deg2step(control_az.setpoint));
stepper_el.moveTo(deg2step(control_el.setpoint));
rotator.rotator_status = pointing;
stepper_az.run();
stepper_el.run();
if (stepper_az.distanceToGo() == 0 && stepper_el.distanceToGo() == 0) {
rotator.rotator_status = idle;
}
}
} else {
stepper_az.stop();
stepper_az.disableOutputs();
stepper_el.stop();
stepper_el.disableOutputs();
if (rotator.rotator_error != homing_error) {
rotator.rotator_error = no_error;
rotator.rotator_status = idle;
}
}
}
/**************************************************************************/
enum _rotator_error homing(int32_t seek_az, int32_t seek_el) {
bool isHome_az = false;
bool isHome_el = false;
stepper_az.moveTo(seek_az);
stepper_el.moveTo(seek_el);
while (isHome_az == false || isHome_el == false) {
if (switch_az.get_state() == true && !isHome_az) {
stepper_az.moveTo(stepper_az.currentPosition());
isHome_az = true;
}
if (switch_el.get_state() == true && !isHome_el) {
stepper_el.moveTo(stepper_el.currentPosition());
isHome_el = true;
}
if ((stepper_az.distanceToGo() == 0 && !isHome_az) ||
(stepper_el.distanceToGo() == 0 && !isHome_el)) {
return homing_error;
}
stepper_az.run();
stepper_el.run();
}
uint32_t time = millis();
while (millis() - time < HOME_DELAY) {
stepper_az.run();
stepper_el.run();
}
stepper_az.setCurrentPosition(0);
stepper_el.setCurrentPosition(0);
control_az.setpoint = 0;
control_el.setpoint = 0;
return no_error;
}
int32_t deg2step(float deg) {
return (RATIO * SPR * deg / 360);
}
float step2deg(int32_t step) {
return (360.00 * step / (SPR * RATIO));
}
Is there any way that the gpredict sends the name of the satellite to the hamlib and it sends it to the arduino one?
I’d say no, hamlib only recieves the pointing afaict.