Not printing to serial?

#include <string.h>
#define IBUS_BUFFSIZE 32
#define IBUS_MAXCHANNELS 10 // I am using only 10 channels because my TX (FlySky i6) supports max 10 channels
#include <Servo.h>
static uint8_t ibusIndex = 0;
static uint8_t ibus[IBUS_BUFFSIZE] = {0};
static uint16_t rcValue[IBUS_MAXCHANNELS];

static boolean rxFrameDone;

int ch_width_1;
int ch_width_2;
int ch_width_3;
int ch_width_4;
int ch_width_5;
int ch_width_6;
int ch_width_7;
int ch_width_8;
int ch_width_9;
int ch_width_10;

Servo ch1;
Servo ch2;
Servo ch3;
Servo ch4;
Servo ch5;
Servo ch6;
Servo ch7;
Servo ch8;
Servo ch9;
Servo ch10;

void setup()
{
  Serial.begin(9600);
  ch1.attach(2);
  ch2.attach(3);
  ch3.attach(4);
  ch4.attach(5);
  ch5.attach(6);
  ch6.attach(7);
  ch7.attach(8);
  ch8.attach(9);
  ch9.attach(10);
  ch10.attach(11);
  
}

void loop()
{
  readRx();

}

void readRx()
{
  rxFrameDone = false;

  if (Serial.available())
  {
    uint8_t val = Serial.read();
    // Look for 0x2040 as start of packet
    if (ibusIndex == 0 && val != 0x20)
    {
      ibusIndex = 0;
      return;
    }
    if (ibusIndex == 1 && val != 0x40)
    {
      ibusIndex = 0;
      return;
    }

    if (ibusIndex == IBUS_BUFFSIZE)
    {
      ibusIndex = 0;
      int high = 3;
      int low = 2;
      for (int i = 0; i < IBUS_MAXCHANNELS; i++)
      {
        rcValue[i] = (ibus[high] << 8) + ibus[low];
        high += 2;
        low += 2;
      }
      ch_width_1 = map(rcValue[0], 1000, 2000, 1000, 2000);
      ch1.writeMicroseconds(ch_width_1);

      Serial.println(ch_width_1);
      Serial.print("     ");

      ch_width_2 = map(rcValue[1], 1000, 2000, 1000, 2000);
      ch2.writeMicroseconds(ch_width_2);

      Serial.println(ch_width_2);
      Serial.print("     ");

      ch_width_3 = map(rcValue[2], 1000, 2000, 1000, 2000);
      ch3.writeMicroseconds(ch_width_3);

      Serial.print(ch_width_3);
      Serial.print("     ");

      ch_width_4 = map(rcValue[3], 1000, 2000, 1000, 2000);
      ch4.writeMicroseconds(ch_width_4);

      Serial.print(ch_width_4);
      Serial.print("     ");

      ch_width_5 = map(rcValue[4], 1000, 2000, 1000, 2000);
      ch5.writeMicroseconds(ch_width_5);

      Serial.print(ch_width_5);
      Serial.print("      ");

      ch_width_6 = map(rcValue[5], 1000, 2000, 1000, 2000);
      ch6.writeMicroseconds(ch_width_6);

      Serial.print(ch_width_6);
      Serial.print("      ");

      ch_width_7 = map(rcValue[6], 1000, 2000, 1000, 2000);
      ch7.writeMicroseconds(ch_width_7);

      Serial.print(ch_width_7);
      Serial.print("      ");


      ch_width_8 = map(rcValue[7], 1000, 2000, 1000, 2000);
      ch8.writeMicroseconds(ch_width_8);
      Serial.print(ch_width_8);
      Serial.print("     ");

      ch_width_9 = map(rcValue[8], 1000, 2000, 1000, 2000);
      ch9.writeMicroseconds(ch_width_9);

 Serial.print(ch_width_9);
 Serial.print("     ");

      ch_width_10 = map(rcValue[9], 1000, 2000, 1000, 2000);
      ch10.writeMicroseconds(ch_width_10);

 Serial.print(ch_width_10);
 Serial.println("     ");

      //rxFrameDone = true;
      return;
    }
    else
    {
      ibus[ibusIndex] = val;
      ibusIndex++;
    }
  }
}

not printing any tips?

Your topic was MOVED to its current forum category which is more appropriate than the original as it is not an Introductory Tutorial

If you just put

 Serial.println("Jello Whirled!");

in your setup() function, does that pirnt?

Check the baud setting in the serial monitor window.

Add printing that does not depend on your logic - if statements aren't printing, they prolly aren't getting execute.

a7

777= yes. i put it right after serial.begin and yes it prints

My guess is that you get into a loop here setting ibusIndex to 0 then 1, 0 then 1, 0 then 1....

that makes sence. ive got an idea,BRB

OK, now put one as the first line of readTx:

 Serial.println("entering readRX");

and so forth. Poor man's debugging.

It looks like you could put a delay(300); in your loop() function just to cut down on the copiusity of the printing.

Step by step. Where you are, and the values of key variables.

HTH

a7

im wanting to add "if" statments triggering a relay with a couple ibus channels. any good reading that could take me to my next step?

Have you received anything from your iBus connection?

What Arduino board are you working with? If you only have one serial port, you can't use that for both debugging and getting characters from another serial source.

If you have only one real port, it is possible that you could use a SoftwareSerial port to talk or listen to you iBus.

What is the iBus baud rate? I think it is true TTL serial protocol, not inverted like sbus.

Or is the other way 'round?

Until you can receive anything, it makes no sense to try to parse and handle specific transmissions.

a7

good point. def needed a SoftwareSerial port to talk or listen to you iBus. im 80 percent self taught and 20 percent YOUTUBE. this is my first time using forum. thank you for being so quick and insightful

I just checked my suspicion that iBus operates at 115200 baud.

I have not used SoftwareSerial, I will let someone else say it works (or does not) at that high rate.

There are Arduino boards with multiple "real" UARTs, perhaps one of them would be a better choice for your device.

a7

thank you, i changed the code with a ibus 10ch read i found online. im not a fan of copy and paste but i have alot more to do with my odrive HoverBot i created so copy and paste works till i get further in my project,

BTW im using arduino mega. i just needed a way for rc controller to tell arduino to talk to my Odrive v3.6 differential drive. the arduino and odrive talk threw uart. i needed a way when hitting a switch on my rc controller can tell odrive to auto configure and then trigger a 4 Relay for lights and to switch to secondary battery on the go while switching itself

Then you do not need SoftwareSerial.
You'll use one of your other UARTs (Serial1, Serial2, Serial3).

Will ibusIndex ever be anything except 0?

I think it might. It looks like it should. I did not run the code, so.

Try tracing the code starting with ibusIndex 0 and assuming that the next two characters you read are exactly 0x20 and 0x40.

Simplified logic here:

  if (Serial.available())
  {
    uint8_t val = Serial.read();
    // Look for 0x2040 as start of packet
    if (ibusIndex == 0 && val != 0x20)
    {
      ibusIndex = 0;
      return;
    }
    if (ibusIndex == 1 && val != 0x40)
    {
      ibusIndex = 0;
      return;
    }

    if (ibusIndex == IBUS_BUFFSIZE)
    {
      // do a buncha stuff but ultimately
      return;
    }
    else
    {
      ibus[ibusIndex] = val;
      ibusIndex++;
    }
  }

HTH

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.