Need help with compilation error

Patrick69

New member
For context: The code is to control a servo motor through an RC controller (Brand: Radiomaster Boxer), however i got an error while compiling in Arduino IDE
Error is : 'SbusRx does not name a type'

Here's the code:

#include "sbus.h"
#include <Servo.h>
Servo ch[12]; //Create array for 12 servo
SbusRx sbusx(&Serial6); //Since Rx and Tx connected to pin 24 (TX6) & pin 25 (RX6)

unsigned long int timex; //need this to make blink status onboard LED
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
//attach the 12 servo to pin 0 - 12
for (int i = 0; i <12; i++){
ch.attach(i+2);
}
ch[11].attach(12);
sbusx.Begin();
timex=millis();
}
void loop() {
// put your main code here, to run repeatedly:
if (sbusx.Read()) {
digitalWrite(13,HIGH);
//get 12 channels from sbus and convert them as servo signal
//our RC channels have range 174 - 1811, and servo range 544 - 2400 (can read from Arduino site)
//but for safety purpose, we set the servo range to 700 - 2300, hence midpoint is 1500 ((2300 - 700) / 2)
//can get channel value using sbusx.rx_channels
for (int i=0;i<12; i++) {
int val = map(sbusx.rx_channels(), 174, 1811, 700, 2300);
ch.writeMicroseconds(val);
}
} else {
blinks(true);
}
}
void blinks(bool en_blink) {
if (en_blink) {
if ((millis()-timex)>1000) { //its same as delay (1000)
digitalWrite(13,!digitalRead(13));
timex = millis();
}
}
}
 
It might help to have additional information, like where is the sbus library located?
Did you download it using the library manager? If so which version?
Is it this one? https://github.com/bolderflight/sbus

Also please when you post code use the code button </> to insert it as it makes it a lot easier to read:
Code:
#include "sbus.h"
#include <Servo.h>
Servo ch[12];            //Create array for 12 servo
SbusRx sbusx(&Serial6);  //Since Rx and Tx connected to pin 24 (TX6) & pin 25 (RX6)

unsigned long int timex;  //need this to make blink status onboard LED
void setup() {
    // put your setup code here, to run once:
    pinMode(13, OUTPUT);
    digitalWrite(13, LOW);
    //attach the 12 servo to pin 0 - 12
    for (int i = 0; i < 12; i++) {
        ch.attach(i + 2);
    }
    ch[11].attach(12);
    sbusx.Begin();
    timex = millis();
}
void loop() {
    // put your main code here, to run repeatedly:
    if (sbusx.Read()) {
        digitalWrite(13, HIGH);
        //get 12 channels from sbus and convert them as servo signal
        //our RC channels have range 174 - 1811, and servo range 544 - 2400 (can read from Arduino site)
        //but for safety purpose, we set the servo range to 700 - 2300, hence midpoint is 1500 ((2300 - 700) / 2)
        //can get channel value using sbusx.rx_channels
        for (int i = 0; i < 12; i++) {
            int val = map(sbusx.rx_channels(), 174, 1811, 700, 2300);
            ch.writeMicroseconds(val);
        }
    } else {
        blinks(true);
    }
}
void blinks(bool en_blink) {
    if (en_blink) {
        if ((millis() - timex) > 1000) {  //its same as delay (1000)
            digitalWrite(13, !digitalRead(13));
            timex = millis();
        }
    }
}

Also it helps if you post the actual messages from the compiler, like:
Code:
"C:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++17 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -Wno-psabi -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=160 -DARDUINO=10607 -DARDUINO_TEENSY_MICROMOD -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\kurte\\AppData\\Local\\Temp\\arduino\\sketches\\4D5D29D37D251B46D19F607C211FE5CD/pch" "-IC:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\0.60.2\\cores\\teensy4" "-Ic:\\Users\\kurte\\Documents\\Arduino\\libraries\\Bolder_Flight_Systems_SBUS\\src" "-IC:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\0.60.2\\libraries\\Servo" "C:\\Users\\kurte\\AppData\\Local\\Temp\\arduino\\sketches\\4D5D29D37D251B46D19F607C211FE5CD\\sketch\\sketch_sep30a.ino.cpp" -o "C:\\Users\\kurte\\AppData\\Local\\Temp\\arduino\\sketches\\4D5D29D37D251B46D19F607C211FE5CD\\sketch\\sketch_sep30a.ino.cpp.o"
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved2024830-17016-mt3mqc.ll2b\sketch_sep30a\sketch_sep30a.ino:4:1: error: 'SbusRx' does not name a type
    4 | SbusRx sbusx(&Serial6);  //Since Rx and Tx connected to pin 24 (TX6) & pin 25 (RX6)
      | ^~~~~~
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved2024830-17016-mt3mqc.ll2b\sketch_sep30a\sketch_sep30a.ino: In function 'void setup()':
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved2024830-17016-mt3mqc.ll2b\sketch_sep30a\sketch_sep30a.ino:13:12: error: request for member 'attach' in 'ch', which is of non-class type 'Servo [12]'
   13 |         ch.attach(i + 2);
      |            ^~~~~~
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved2024830-17016-mt3mqc.ll2b\sketch_sep30a\sketch_sep30a.ino:16:5: error: 'sbusx' was not declared in this scope
   16 |     sbusx.Begin();
      |     ^~~~~
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved2024830-17016-mt3mqc.ll2b\sketch_sep30a\sketch_sep30a.ino: In function 'void loop()':
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved2024830-17016-mt3mqc.ll2b\sketch_sep30a\sketch_sep30a.ino:21:9: error: 'sbusx' was not declared in this scope
   21 |     if (sbusx.Read()) {
      |         ^~~~~
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved2024830-17016-mt3mqc.ll2b\sketch_sep30a\sketch_sep30a.ino:29:16: error: request for member 'writeMicroseconds' in 'ch', which is of non-class type 'Servo [12]'
   29 |             ch.writeMicroseconds(val);
      |                ^~~~~~~~~~~~~~~~~
Multiple libraries were found for "Servo.h"
  Used: C:\Users\kurte\AppData\Local\Arduino15\packages\teensy\hardware\avr\0.60.2\libraries\Servo
  Not used: C:\Users\kurte\AppData\Local\Arduino15\libraries\Servo
Using library Bolder Flight Systems SBUS at version 8.1.4 in folder: C:\Users\kurte\Documents\Arduino\libraries\Bolder_Flight_Systems_SBUS
Using library Servo at version 1.1.2 in folder: C:\Users\kurte\AppData\Local\Arduino15\packages\teensy\hardware\avr\0.60.2\libraries\Servo
exit status 1

Compilation error: 'SbusRx' does not name a type
 
That error is because the class is defined in the namespace bfs:

Two possible solutions.

a) Change the line:
Code:
SbusRx sbusx(&Serial6, false);  //Since Rx and Tx connected to pin 24 (TX6) & pin 25 (RX6)
to
Code:
bfs::SbusRx sbusx(&Serial6, false);  //Since Rx and Tx connected to pin 24 (TX6) & pin 25 (RX6)

b) Add a using statement:
Code:
using namespace bfs;
SbusRx sbusx(&Serial6, false);  //Since Rx and Tx connected to pin 24 (TX6) & pin 25 (RX6)
 
That error is because the class is defined in the namespace bfs:

Two possible solutions.

a) Change the line:
Code:
SbusRx sbusx(&Serial6, false);  //Since Rx and Tx connected to pin 24 (TX6) & pin 25 (RX6)
to
Code:
bfs::SbusRx sbusx(&Serial6, false);  //Since Rx and Tx connected to pin 24 (TX6) & pin 25 (RX6)

b) Add a using statement:
Code:
using namespace bfs;
SbusRx sbusx(&Serial6, false);  //Since Rx and Tx connected to pin 24 (TX6) & pin 25 (RX6)
Thank you! I'll try it out. I'll make sure to use the code </> button and how the way I post next time if i have any more questions.
 
Back
Top