Skip to content

Added Teensy support.#28

Open
0Hogan wants to merge 3 commits intobmellink:masterfrom
0Hogan:teensy-support
Open

Added Teensy support.#28
0Hogan wants to merge 3 commits intobmellink:masterfrom
0Hogan:teensy-support

Conversation

@0Hogan
Copy link

@0Hogan 0Hogan commented Aug 22, 2022

Added support for the Teensy LC/3.0/3.1/3.2/3.5/3.6/4.0/4.1

I only had the opportunity to test with a FlySky receiver and a Teensy 4.1. If others could test on some of the other boards and/or other receivers, that would be ideal.

Hopefully this helps with #25 .

@starlight-traveler
Copy link

Hey, I was just wondering how you got around this error:

src/main.cpp: In function 'void setup()':
src/main.cpp:29:13: error: no matching function for call to 'IBusBM::begin(HardwareSerialIMXRT&)'
29 | ibus.begin(Serial1);
| ~~~~~~~~~~^~~~~~~~~
In file included from src/main.cpp:2:
.pio/libdeps/teensy41/IBusBM/src/IBusBM.h:61:10: note: candidate: 'void IBusBM::begin(HardwareSerial&, IntervalTimer*, int8_t, int8_t)'
61 | void begin(HardwareSerial &serial, IntervalTimer* timerid, int8_t rxPin=-1, int8_t txPin=-1);
| ^~~~~
.pio/libdeps/teensy41/IBusBM/src/IBusBM.h:61:10: note: candidate expects 4 arguments, 1 provided
*** [.pio/build/teensy41/src/main.cpp.o] Error 1

When I create a timer object and pass it by reference I still run into an issue with the arguments.

@Casseman
Copy link

@0Hogan i am trying to get this to work with the teensy 4.0 but i cant. Could you show an example of how you did an test code?

@Casseman
Copy link

Hey, I was just wondering how you got around this error:

src/main.cpp: In function 'void setup()':
src/main.cpp:29:13: error: no matching function for call to 'IBusBM::begin(HardwareSerialIMXRT&)'
29 | ibus.begin(Serial1);
| ~~~~~~~~~~^~~~~~~~~
In file included from src/main.cpp:2:
.pio/libdeps/teensy41/IBusBM/src/IBusBM.h:61:10: note: candidate: 'void IBusBM::begin(HardwareSerial&, IntervalTimer*, int8_t, int8_t)'
61 | void begin(HardwareSerial &serial, IntervalTimer* timerid, int8_t rxPin=-1, int8_t txPin=-1);
| ^~~~~
.pio/libdeps/teensy41/IBusBM/src/IBusBM.h:61:10: note: candidate expects 4 arguments, 1 provided
*** [.pio/build/teensy41/src/main.cpp.o] Error 1

When I create a timer object and pass it by reference I still run into an issue with the arguments.

@starlight-traveler what worked for me is doing adding IBus.begin(Serial2,1); instead of IBus.begin(Serial2);. This is on teensy 4.0, hope this helps :)

@SimonSchw
Copy link

SimonSchw commented Mar 23, 2025

Hi! Sadly this branch does not work for me out of the box as well.
Temp\.arduinoIDE-unsaved2025223-3936-12rq769.m5l5\sketch_mar23a\sketch_mar23a.ino:10:27: warning: invalid conversion from 'int' to 'IntervalTimer*' [-fpermissive] 10 | IBusServo.begin(Serial1,1); | ^ | | | int In file included from C:\Users\schwi\AppData\Local\Temp\.arduinoIDE-unsaved2025223-3936-12rq769.m5l5\sketch_mar23a\sketch_mar23a.ino:1: c:\dev\ArduFoilControl\libraries\IBusBM\src/IBusBM.h:61:55: note: initializing argument 2 of 'void IBusBM::begin(HardwareSerial&, IntervalTimer*, int8_t, int8_t)' 61 | void begin(HardwareSerial &serial, IntervalTimer* timerid, int8_t rxPin=-1, int8_t txPin=-1);

I tried your solution @Casseman on a teensy4.1 but without luck.

any help would be appreciated!

@starlight-traveler
Copy link

This code worked on a Teensy 4.1, I can't remember if I modified the library at all, so if this doesn't work let me know and I can attempt to reflash it:

/*
 Arduino FS-I6X
*/

// Include iBusBM Library
#include <IBusBM.h>
#include "IntervalTimer.h"

// Create iBus Object
IBusBM ibus;

IntervalTimer myTimer;

// Read the number of a given channel and convert to the range provided.
// If the channel is off, return the default value
int readChannel(byte channelInput, int minLimit, int maxLimit, int defaultValue) {
  uint16_t ch = ibus.readChannel(channelInput);
  if (ch < 100) return defaultValue;
  return map(ch, 1000, 2000, minLimit, maxLimit);
}

// Read the channel and return a boolean value
bool readSwitch(byte channelInput, bool defaultValue) {
  int intDefaultValue = (defaultValue) ? 100 : 0;
  int ch = readChannel(channelInput, 0, 100, intDefaultValue);
  return (ch > 50);
}

void setup() {
  // Start serial monitor
  Serial.begin(115200);

  // Attach iBus object to serial port
ibus.begin(Serial1, &myTimer, -1, -1);
}

void loop() {
  // Cycle through first 5 channels and determine values
  // Print values to serial monitor
  // Note IBusBM library labels channels starting with "0"
  for (byte i = 0; i < 5; i++) {
    int value = readChannel(i, -100, 100, 0);
    Serial.print("Ch");
    Serial.print(i + 1);
    Serial.print(": ");
    Serial.print(value);
    Serial.print(" | ");
  }

  // Print channel 6 (switch) boolean value
  Serial.print("Ch6: ");
  Serial.print(readSwitch(5, false));
  Serial.println();

  delay(10);
}

@SimonSchw

@SimonSchw
Copy link

SimonSchw commented Mar 24, 2025

This code worked on a Teensy 4.1, I can't remember if I modified the library at all, so if this doesn't ...

Thank you very much @starlight-traveler, works perfectly with the IntervalTimer and -1,-1.
Now I will try to get the telemetry channels to work too.
EDIT: telemetry channel works the same, just added another timer, no further problems.

Thanks again!

@pierrotm777
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants