I use Matrix Creator to control 2 servos, but only one active and the other does not move. I try to create 2 objects on matrix_hal :: MatrixIOBus is bus1, bus2 created 2 of them. I do not know if the matrix can control a servo or not. you help, thank you very much!
The code below is just a test, I just created an object on matrix_hal :: MatrixIOBus.thank you very much!
#include <iostream>
#include "matrix_hal / gpio_control.h"
#include "matrix_hal / matrixio_bus.h"
float angle, angle1;
int main ()
{
matrix_hal :: MatrixIOBus bus;
if (! bus.Init ()) return false;
// if (! bus.Init ()) std :: cout << "error SerR" << std :: endl;
matrix_hal :: GPIOControl SerR, SerV;
SerR.Setup (& bus);
SerV.Setup (& bus);
while (1)
{
std :: cout << "Chose angle:" << std :: endl;
std :: cin >> angle;
std :: cin >> angle1;
SerR.SetMode (0,1);
SerR.SetFunction (0,1);
SerV.SetMode (2.1);
SerV.SetFunction (2,1);
SerR.SetServoAngle (angle, 1., 0);
SerV.SetServoAngle (angle1,1., 2);
}
return 0;
}
I think the issue is related to that you just need one instance of GPIOControl
, to select different Servos you use the pin parameter for it.
Here is the code with some changes, its hust a guide, I didnt build it .
Let me know how it goes.
#include <iostream>
#include "matrix_hal / gpio_control.h"
#include "matrix_hal / matrixio_bus.h"
#define SERVO_0_PIN = 0
#define SERVO_1_PIN = 1
#define GPIO_INPUT_MODE = 0
#define GPIO_OUTPUT_MODE = 1
#define GPIO_BANK_0 = 0 // From pin 0 - 3
#define GPIO_BANK_1 = 1 // From pin 4 - 7
#define GPIO_BANK_2 = 2 // From pin 8 - 11
#define GPIO_BANK_3 = 3 // From pin 12 - 15
#define GPIO_FUNCTION = 0 // General GPIO I/O
#define PWM_FUNCTION = 1 // PWM I/O
float angle_0, angle_1;
int main ()
{
matrix_hal :: MatrixIOBus bus;
if (! bus.Init ()) {
std :: cout << "Error!" << std :: endl;
return false;
}
matrix_hal :: GPIOControl gpio_ctrl;
gpio_ctrl.Setup(& bus);
gpio_ctrl.SetMode(SERVO_0_PIN, GPIO_OUTPUT_MODE);
gpio_ctrl.SetMode(SERVO_1_PIN, GPIO_OUTPUT_MODE);
gpio_ctrl.SetFunction(SERVO_0_PIN, PWM_FUNCTION);
gpio_ctrl.SetFunction(SERVO_1_PIN, PWM_FUNCTION);
while (1) {
std :: cout << "Chose angle:" << std :: endl;
std :: cin >> angle_0; // in degrees
std :: cin >> angle_1; // in degrees
gpio_ctrl.Set9GServoAngle(angle_0, SERVO_0_PIN);
gpio_ctrl.Set9GServoAngle(angle_1, SERVO_1_PIN);
// For non standart servo look for the min pulse
// in the datasheet and use it in the
// 2nd parameter in SetServoAngle():
// int min_pulse_ms = ???
// gpio_ctrl.SetServoAngle(angle_0, min_pulse_ms, SERVO_0_PIN);
// gpio_ctrl.SetServoAngle(angle_1, min_pulse_ms, SERVO_1_PIN);
}
return 0;
thx you,it’ worked.!
thank you, it worked. I created 2 objects of 2 servo pins so it did not work. happy one day, thank you so much!