설명이 안 되는 현상
젯슨 나노를 부팅해 줄 때마다 업로드 되어있던 코드가 실행되어야 하는데 그렇지 않는 현상이 발생하였다.
/dev의 권한이 문제인지 어떠한 이유로 시리얼 통신이 먹통이 되어버린다.
재부팅을 할 때마다 업로드 하는건 여간 힘들다.
왜냐하면 젯슨나노에 모니터를 연결해야하고 연결했다 하더라도 아두이노 프로그램을 실행하고 클릭을 몇 변 해야하기 때문이다.
해결법
이렇게 원인을 알 수 없을때는 우회하는 방법을 생각해야 하는 것 같다.
해결책을 위해 사용한 것은 arduino-cli이다.
CLI환경에서 아두이노 작업을 가능하게 해준다.
CLI에서 아두이노에 명령을 내릴 수 있다면 쉘 스크립트로 자동화도 된다는 뜻이며, 더 나아가 부팅을 할 때도 자동실행되게 할 수 있다.
arduino-cli를 설치해야 하는데 본인의 아키텍처에 맞는 파일을 다운받는다.
나같은 경우 젯슨나노에서 설치를 해야해서 arm64아키텍처의 파일을 다운받았다.
아래 홈페이지에서 아키텍처별 파일을 다운받을 수 있다.
https://arduino.github.io/arduino-cli/0.32/installation/
Installation - Arduino CLI
Installation Several options are available for installation of Arduino CLI. Instructions for each are provided below: Install via Homebrew (macOS/Linux) The Arduino CLI is available as a Homebrew formula since version 0.5.0: brew update brew install arduin
arduino.github.io
sudo apt update
sudo apt install -y curl git
cd 를 입력하고 실행해준다.
sudo curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh
만약 Permission 문제가 발생한다면 아래 커맨드를 cli에 입력해준다
sudo chmod 777 /usr/local/bin/
실행해본다.
별 내용 뜨지 않는다.
어떤 내용이 있으며 어떤 인수를 주면 어떻게 작동을 하는지 정보가 뜬다.
arduino-cli
쉘 스크립트 작성
사실 이 내용도 위에서 arduino-cli를 입력하면 나오는 정보이다.
나는 쉘 스크립트를 아래와 같이 작성했다.
#!/bin/bash
# 아두이노 스케치 파일 경로
front_sketch="mecanum-ros2/arduino_code/motor_control_front_final_float/motor_control_front_final_float.ino"
rear_sketch="mecanum-ros2/arduino_code/motor_control_rear_final_float/motor_control_rear_final_float.ino"
# 아두이노 보드 타입
board_type_1="arduino:avr:mega"
board_type_2="arduino:avr:mega"
# 아두이노 포트
front_port="/dev/ttyACM0"
rear_port="/dev/ttyACM1"
# 아두이노 스케치 컴파일 및 업로드
arduino-cli compile --fqbn $board_type_2 $front_sketch
arduino-cli upload -p $front_port -b $board_type_1 $front_sketch
arduino-cli compile --fqbn $board_type_1 $rear_sketch
arduino-cli upload -p $rear_port -b $board_type_2 $rear_sketch
이후 쉘 스크립트를 실행해본다.
. auto_arduino.sh
# 본인이 설정한 쉘 스크립트 이름으로 실행한다.
크론탭으로 자동실행 등록하기
crontab -e
1. /bin/nano #선택
#새로운 스케줄을 등록한다.
#창이 열리면 제일 아래줄에
@reboot /home/jetson/mecanum-ros2/auto_arduino.sh
#@reboot 뒤에 본인의 쉘 스크립트 파일 주소 입력