개발 기록/Coding&Debugging

아두이노 컴파일 시 error: cannot convert 'USBSerial*' to 'HardwareSerial*' in assignment 문제

LiDARian 2021. 9. 3. 13:00
반응형

 

 

error: cannot convert 'USBSerial*' to 'HardwareSerial*' in assignment

 

최근 팀프로젝트를 하는 중, 아두이노에서 .ino파일과 .cpp, .h 파일을 동시에 컴파일 하는 일이 있었다. 그런데 이런 에러가 떴다.

 

In file included from
/home/pjs/Arduino/libraries/Rosserial_Arduino_Library/src/ros.h:39:0,
from /tmp/arduino_modified_sketch_218835/h_Position.ino:20:
/home/pjs/Arduino/libraries/Rosserial_Arduino_Library/src/ArduinoHardware.h: In constructor 'ArduinoHardware::ArduinoHardware()':
/home/pjs/Arduino/libraries/Rosserial_Arduino_Library/src/ArduinoHardware.h:55:16: error: cannot convert 'USBSerial*' to 'HardwareSerial*' in assignment
iostream = &Serial;

 

아니 이러시는 이유가 있으실 거 아니에요

 

군대 다녀온 기간을 뺀 대학 2년동안 수많은 아두이노 에러들을 봐왔으나, 이런 에러는 처음이었다.

 

아무래도 Rosserial 라이브러리에서 문제가 있는 모양인데, 스스로 해결할 방법이 마땅치 않아 열심히 구글링 해봤다.

 

그 결과 두가지 글을 찾았다.

 

Serial Port problems with <ros.h> on arduino IDE · Issue #90 · ROBOTIS-GIT/OpenCM9.04 (github.com)

 

Serial Port problems with on arduino IDE · Issue #90 · ROBOTIS-GIT/OpenCM9.04

Hello everyone, I'm trying to control a dynamixel ax-12a with the OpenCM9.04 board and I'm programming the board using the arduino IDE. I was using the Dynamixel Workbench library for comma...

github.com

 

error: cannot convert 'USBSerial*' to 'HardwareSerial*' in assignment · Issue #120 · ROBOTIS-GIT/OpenCR (github.com)

 

error: cannot convert 'USBSerial*' to 'HardwareSerial*' in assignment · Issue #120 · ROBOTIS-GIT/OpenCR

Hi, ROBOTIS, While following the textbook - ROS robot programming written by @robotpilot, I got stuck in 9.2.6. rosserial (p.274) with the following error Arduino: 1.8.5 (Linux), Board: "OpenC...

github.com

 

...하지만 영어로 읽는 건 불편하니, 직접 핵심 내용을 번역해서 알려드리겠다.

 


 

 


해결 방법

 

우선 자신의 컴퓨터에서 ../rosserial_arduino/src/ros_lib/ArduinoHardware.h 로 들어가서 44번째 줄을 보자. 아래와 같이 되어있을 것이다.

 

#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__MKL26Z64__)
  #if defined(USE_TEENSY_HW_SERIAL)
    #define SERIAL_CLASS HardwareSerial // Teensy HW Serial
  #else
    #include <usb_serial.h>  // Teensy 3.0 and 3.1
    #define SERIAL_CLASS usb_serial_class
  #endif
#elif defined(_SAM3XA_)
  #include <UARTClass.h>  // Arduino Due
  #define SERIAL_CLASS UARTClass
#elif defined(USE_USBCON)
  // Arduino Leonardo USB Serial Port
  #define SERIAL_CLASS Serial_
#elif (defined(__STM32F1__) and !(defined(USE_STM32_HW_SERIAL))) or defined(SPARK) 
  // Stm32duino Maple mini USB Serial Port
  #define SERIAL_CLASS USBSerial
#else 
  #include <HardwareSerial.h>  // Arduino AVR
  #define SERIAL_CLASS HardwareSerial
#endif

 

이 부분에 #endif 바로 위에 다음 코드를 추가해주자.

#elif defined(__OPENCM904__) 
  #include <USBSerial.h>  // Teensy 3.0 and 3.1
  #define SERIAL_CLASS USBSerial

 

그러면 더 이상 에러가 발생하지 않는다.

 

적합한 보드에 대한 정의가 되어있지 않아서 동작하지 않았던 모양이다.

 

에러 해결 완료!


 

 


공대생지식창고 오픈카톡방

https://open.kakao.com/o/swnAyLyc

 

공대생지식창고님의 오픈프로필

공대생에게 도움이 될만한 글을 씁니다. www.knowledgeforenginners.tistory.com

open.kakao.com

 

공대생지식창고 Github

engineerJPark (github.com)

 

engineerJPark - Overview

engineerJPark has 2 repositories available. Follow their code on GitHub.

github.com

 

 

반응형