1

I have a FS-IA6B, Flysky FS-I6 and Raspberry Pi Zero. I want to read all channels from FS-IA6B. I use C language.

I connected the power to the FS-IA6B and 4 channels to the pins on Raspberry Pi to 25, 24, 23 and 21. I randomly get zeros and ones, just one number from the DigitalRead() function.

I use libraries WiringPi and pigpio how can I get the necessary data from the control panel?

It's working code for Arduino, but what is interrupts?

#include <EnableInterrupt.h>

#define SERIAL_PORT_SPEED 57600
#define RC_NUM_CHANNELS  4

#define RC_CH1  0
#define RC_CH2  1
#define RC_CH3  2
#define RC_CH4  3

#define RC_CH1_INPUT  A0
#define RC_CH2_INPUT  A1
#define RC_CH3_INPUT  A2
#define RC_CH4_INPUT  A3

uint16_t rc_values[RC_NUM_CHANNELS];
uint32_t rc_start[RC_NUM_CHANNELS];
volatile uint16_t rc_shared[RC_NUM_CHANNELS];

void rc_read_values() {
  noInterrupts();
  memcpy(rc_values, (const void *)rc_shared, sizeof(rc_shared));
  interrupts();
}

void calc_input(uint8_t channel, uint8_t input_pin) {
  if (digitalRead(input_pin) == HIGH) {
    rc_start[channel] = micros();
  } else {
    uint16_t rc_compare = (uint16_t)(micros() - rc_start[channel]);
    rc_shared[channel] = rc_compare;
  }
}

void calc_ch1() { calc_input(RC_CH1, RC_CH1_INPUT); }
void calc_ch2() { calc_input(RC_CH2, RC_CH2_INPUT); }
void calc_ch3() { calc_input(RC_CH3, RC_CH3_INPUT); }
void calc_ch4() { calc_input(RC_CH4, RC_CH4_INPUT); }

void setup() {
  Serial.begin(SERIAL_PORT_SPEED);

  pinMode(RC_CH1_INPUT, INPUT);
  pinMode(RC_CH2_INPUT, INPUT);
  pinMode(RC_CH3_INPUT, INPUT);
  pinMode(RC_CH4_INPUT, INPUT);

  enableInterrupt(RC_CH1_INPUT, calc_ch1, CHANGE);
  enableInterrupt(RC_CH2_INPUT, calc_ch2, CHANGE);
  enableInterrupt(RC_CH3_INPUT, calc_ch3, CHANGE);
  enableInterrupt(RC_CH4_INPUT, calc_ch4, CHANGE);
}

void loop() {
  rc_read_values();

  Serial.print("CH1:"); Serial.print(rc_values[RC_CH1]); Serial.print("\t");
  Serial.print("CH2:"); Serial.print(rc_values[RC_CH2]); Serial.print("\t");
  Serial.print("CH3:"); Serial.print(rc_values[RC_CH3]); Serial.print("\t");
  Serial.print("CH4:"); Serial.println(rc_values[RC_CH4]);

  delay(200);
}

One more, I found information about interrupts and how FS-IA6B sends data.

Step 2 : about PPM and PWM:

And Arduino code:

After I wrote this code, it is almost the same, but I didn't use "interrupts".

#include "SBUS.h"
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <pigpio.h>
#include <wiringPi.h>

#define THROTTLE_SIGNAL_IN 0 // INTERRUPT 0 = DIGITAL PIN 2 - use the interrupt number in attachInterrupt
#define THROTTLE_SIGNAL_IN_PIN 2 // INTERRUPT 0 = DIGITAL PIN 2 - use the PIN number in digitalRead

#define NEUTRAL_THROTTLE 1500 // this is the duration in microseconds of neutral throttle on an electric RC Car

int trothle, start_micros;
uint16_t rc_compare;

void calc(int pin);

int main(void){
    wiringPiSetup();

    // pinMode(21, INPUT);
    // pinMode(22, INPUT);
    // pinMode(23, INPUT);
    // pinMode(24, INPUT);
    pinMode(25, INPUT);

    // if(gpioInitialise() < 0){
 //        fprintf(stderr, "pigpio initialisation faled\n");
 //        return 1;
 //    }

    // gpioSetMode(21, PI_INPUT);
    // gpioSetMode(22, PI_INPUT);
    // gpioSetMode(23, PI_INPUT);
    // gpioSetMode(24, PI_INPUT);
    // gpioSetMode(25, PI_INPUT);

    while(1){
        calc(25);
        printf("Throttle ch1%3d: %d\n", digitalRead(25), rc_compare); 
        // printf("\e[1;1H\e[2J");
        delay(250);
    }

    return 0;
}


void calc(int pin){
    if (digitalRead(pin) == 1)
    {
        start_micros = micros();
    }else{
        rc_compare = (uint16_t)(micros() - start_micros);
    }
}

But I get random digits.

How can I get normal values from the remote?

EsmaeelE
  • 2,331
  • 6
  • 22
  • 31
goose
  • 109
  • 1
  • 10

0 Answers0