Adapt this other FlySky IBUS library to Teensy family

pierrotm777

Well-known member
Hello,

I have another need, adapt this IbusBM library for the Teensy family.
This library use a halfduplex serial wiring with the flysky receiver.
I need only to translate the telemetry code but if the servo code can be updated, that would be fun .

Thanks for your help,

Pierre
 

Attachments

  • IBusBM.zip
    479.7 KB · Views: 7
At first glance this doesn't look like it would be anywhere near as easy to convert because it uses timer interrupts.
I'll have a deeper look but don't get your hopes up :unsure:

Pete
 
At first glance this doesn't look like it would be anywhere near as easy to convert because it uses timer interrupts.
I'll have a deeper look but don't get your hopes up :unsure:

Pete
I hope to send telemetry to a FlySky receiver as a FS-IA6B or FS-IA10B , these receiver are not expensive and I like to use them with telemetry.
The main link is on github here.
May be it's possible as with a ESP32 to disable the timer, see here ?
 
I was just in the process of modifying two of the examples to disable the timer. Now to add pins to a T4.0 so that I can try a T4.0 and T4.1 chatting to each other with the ibus_sensor and ibus_singlemonitor examples.

Pete
 
Not yet. The examples compile but ibus_sensor indicates it is sending info but ibus_singlemonitor only prints zeros.
Need to ponder it more. It may be something to do with the half-duplex protocol and I haven't wired the two processors together properly.

Pete
 
Not yet. The examples compile but ibus_sensor indicates it is sending info but ibus_singlemonitor only prints zeros.
Need to ponder it more. It may be something to do with the half-duplex protocol and I haven't wired the two processors together properly.

Pete
Ok, Do you use a diode or a 1k between Rx and Tx ?
 
I use 1k, but I've just determined that the ibus_sensor sketch isn't sending anything.
More digging required.

Pete
 
I may have figured it out. I've attached a zip of the src directory from IBusBM library. It contains IBusBM.cpp and IBusBM.h although only IBusBM.cpp has changed. It turned out to be much easier than I had imagined.
I wrote my own sketch to test the library and it seems to work with a T4.0 and T4.1 connected via their Serial1 with T4.0 Tx-> T4.1 Rx
and T4.1 Tx-> T4.0 Rx.

Pete
 

Attachments

  • src.zip
    5.8 KB · Views: 6
Hello el_supremo,

This is my test code without telemetry on my handset.
I use a 1k resistor.

Any idea why, do I need to change something ?


C++:
#include <IBusBM.h>

/*
  Simulate two sensor and send information back over the iBUS to the receiver (and back to transmitter
  as telemetry).
 
  - serial   - monitor output (debug output to PC, this is through the build-in USB)
  - serial1 - connected RX of the serial port to the ibus receiver pin
    Connect the (TX) pin also to the RX/ibus connection using an 1.2k Ohm reistor or 1N4148 diode
    (cathode=white ring of the diode at the side of TX2)

  sensor types defined in IBusBM.h:
 
  #define IBUSS_INTV 0 // Internal voltage (in 0.01)
  #define IBUSS_TEMP 1 // Temperature (in 0.1 degrees, where 0=-40'C)
  #define IBUSS_RPM  2 // RPM
  #define IBUSS_EXTV 3 // External voltage (in 0.1V)

*/

IBusBM IBus;

void setup() {
  // initialize serial port for debug
  Serial.begin(115200);

  // iBUS connected to serial3
  IBus.begin(Serial3);


  Serial.println("Start iBUS sensor");

  // adding 2 sensors
  IBus.addSensor(IBUSS_RPM);
  IBus.addSensor(IBUSS_TEMP);
}


#define TEMPBASE 400    // base value for 0'C

// sensor values
uint16_t speed=0;
uint16_t temp=TEMPBASE+200; // start at 20'C

void loop() {
  IBus.setSensorMeasurement(1,speed);
  speed += 10;                           // increase motor speed by 10 RPM
  IBus.setSensorMeasurement(2,temp++); // increase temperature by 0.1 'C every loop
  Serial.print("Speed=");
  Serial.print(speed);
  Serial.print(" Temp=");
  Serial.println((temp-TEMPBASE)/10.);
  delay(500);
}
 
el_supremo,

I try to change uint32_t sensorValue to float sensorValue, but I have some compilation errors.
C++:
Compiling library "IBusBM"
"C:\\Users\\pierrot\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\5.4.1/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=157 -DARDUINO=10607 -DARDUINO_TEENSY40 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\pierrot\\AppData\\Local\\arduino\\sketches\\5C653F9B6E75F2D2E283496364283CB8/pch" "-IC:\\Users\\pierrot\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.57.3\\cores\\teensy4" "-Ic:\\tmp\\Arduino_Compilateur\\arduino-1.8.19\\MyArduinoSketch\\libraries\\IBusBM\\src" "c:\\tmp\\Arduino_Compilateur\\arduino-1.8.19\\MyArduinoSketch\\libraries\\IBusBM\\src\\IBusBM.cpp" -o "C:\\Users\\pierrot\\AppData\\Local\\arduino\\sketches\\5C653F9B6E75F2D2E283496364283CB8\\libraries\\IBusBM\\IBusBM.cpp.o"
c:\tmp\Arduino_Compilateur\arduino-1.8.19\MyArduinoSketch\libraries\IBusBM\src\IBusBM.cpp: In member function 'void IBusBM::loop()':
c:\tmp\Arduino_Compilateur\arduino-1.8.19\MyArduinoSketch\libraries\IBusBM\src\IBusBM.cpp:249:52: error: invalid operands of types 'float' and 'int' to binary 'operator&'
                 stream->write(t = s->sensorValue & 0x0ff);
                                                    ^
c:\tmp\Arduino_Compilateur\arduino-1.8.19\MyArduinoSketch\libraries\IBusBM\src\IBusBM.cpp:251:54: error: invalid operands of types 'float' and 'int' to binary 'operator>>'
                 stream->write(t = (s->sensorValue >> 8) & 0x0ff);
                                                      ^
c:\tmp\Arduino_Compilateur\arduino-1.8.19\MyArduinoSketch\libraries\IBusBM\src\IBusBM.cpp:254:56: error: invalid operands of types 'float' and 'int' to binary 'operator>>'
                   stream->write(t = (s->sensorValue >> 16) & 0x0ff);
                                                        ^
c:\tmp\Arduino_Compilateur\arduino-1.8.19\MyArduinoSketch\libraries\IBusBM\src\IBusBM.cpp:256:56: error: invalid operands of types 'float' and 'int' to binary 'operator>>'
                   stream->write(t = (s->sensorValue >> 24) & 0x0ff);
                                                        ^
Utilisation de la bibliothèque IBusBM version 1.1.4 dans le dossier: C:\tmp\Arduino_Compilateur\arduino-1.8.19\MyArduinoSketch\libraries\IBusBM
exit status 1

Compilation error: exit status 1

Do you have an idea how to use float please ?
 

Attachments

  • IBusBM.h
    3.8 KB · Views: 4
  • IBusBM.cpp
    11.2 KB · Views: 4
Another lib this method
 

Attachments

  • iBUSSensors.h
    2.6 KB · Views: 7
  • iBUSTelemetry.cpp
    13.7 KB · Views: 7
  • iBUSTelemetry.h
    2.6 KB · Views: 8
Back
Top