サーボ開発ボードを使用したNeoPixel LED制御
Kitronik Simply Servos Board(図1)は、プロジェクトで複数のサーボを使用する場合に、3V~12Vの適切な電源レールを提供します。内蔵の3V電源レギュレーションとピンヘッダにより、サーボを操作するためのRaspberry Pi Picoを簡単に追加できます。しかし、リード線が3本あり、5Vの電力を必要とし、かなりの電流を消費する可能性がある別のデバイスはどうでしょうか?AdafruitのNeoPixel LEDストリップのようなデバイスです!
図1:Kitronik Simply Servos Board。(画像提供:Kitronik)
最近、私のR/C戦闘機を夜間飛行可能なものに改造しようと考えました。マイクロコントローラを搭載し、NeoPixelストリップを電源に接続する方法を見つけることはできますが、サーボリードを使用して素早く簡単に改造できるとしたらどうでしょうか?Simply Servos Boardは、サーボ専用というわけではありません。このプラットフォームを選択することで、プロジェクトが簡素化され、カスタム配線や多数のコネクタの必要性が最小限に抑えられました。
飛行プラットフォームの詳細と戦闘機を改造する方法を紹介した楽しいビデオは、この記事の最後に記載したブログとビデオのリンクでご覧いただけます。R/Cトランスミッタからの入力に基づいてNeoPixelsを動作させるようPicoをプログラムするために、Arduino IDEが使用されました。今後は、機体側面にマーキー機能を使用し、スロットルを上げてより高速で追跡できるようにする予定です。夕方になって暗くなると、NeoPixelは明るすぎて目に負担をかけることがあります。補助チャンネルはLEDの調光に使用されます。最後に、暗闇で飛行機を着陸させるときは、着陸灯があると便利です。別のチャンネルを追加するのではなく、スロットルが着陸速度以下になると、底面のNeoPixelが明るい白に変わります。今回は基本的なプログラミングを行いましたが、機能の追加や改善の余地があります。
コピーArduino IDE Code:
//Rx throttle as LED speed control. Rx Aux 2 as dimmer. Channels 1 and 2 as inputs on Simply Servos.
//Remaining servo ports on board (channels 3-8, pins 4-9) used as NeoPixel outputs.
#include <neopixelconnect.h>
//Number of NeoPixels in each string
#define FIN_LEN 34 //Number of NeoPixels on each fin
#define BOT_LEN 28 //Number of NeoPixels on each bottom skid
#define AUX_LEN 61 //Number of NeoPixels on each auxiliary location
#define THRESH 60 //Landing versus flight throttle threshold
//Rx channel Pico GPIO inputs
#define THROT 2
#define AUX2 3
// Create an instance of NeoPixelConnect and initialize it for each strand of NeoPixels
// (pin, number of pixels in string, programmable IO location (0 or 1), programmable IO state machine usage (0-3))
NeoPixelConnect R_Aux(4, AUX_LEN, pio0, 0);
NeoPixelConnect L_Aux(5, AUX_LEN, pio1, 0);
NeoPixelConnect R_Bot(6, BOT_LEN, pio0, 1);
NeoPixelConnect L_Bot(7, BOT_LEN, pio1, 1);
NeoPixelConnect R_Fin(8, FIN_LEN, pio0, 2);
NeoPixelConnect L_Fin(9, FIN_LEN, pio1, 2);
uint8_t AuxSingLED; //Single LED variable on auxiliary string
//Function - Get intensity level from Rx Aux2 output
uint8_t get_pixel_intensity() {
return map(pulseIn(AUX2, HIGH), 900, 2200, 0, 255);
}
//Function - Get speed level from Rx Throttle output
uint8_t get_pixel_speed() {
return map(pulseIn(THROT, HIGH), 990, 1902, 100, 0);
}
void setup() {
pinMode(THROT, INPUT); //Set Pico GPIO pin 2 as input
pinMode(AUX2, INPUT); //Set Pico GPIO pin 3 as input
}
void loop() {
uint8_t LEDInten = get_pixel_intensity(); //Get NeoPixel intensity value
uint8_t LEDSpeed = get_pixel_speed(); //Get NeoPixel speed value
if (LEDSpeed < 10) LEDSpeed = 0; //Dampen lower speed limit
if (LEDSpeed < THRESH) { //Throttle high color
R_Bot.neoPixelFill(LEDInten, 0, 0, true); //Fill string with red
L_Bot.neoPixelFill(LEDInten, 0, 0, true); //Fill string with red
} else { //Throttle low color
R_Bot.neoPixelFill(LEDInten, LEDInten, LEDInten, true); //Fill string with white
L_Bot.neoPixelFill(LEDInten, LEDInten, LEDInten, true); //Fill string with white
}
R_Fin.neoPixelFill(0, LEDInten, 0, true); //Fill string with green
L_Fin.neoPixelFill(0, LEDInten, 0, true); //Fill string with green
R_Aux.neoPixelFill(0, 0, LEDInten, false); //Fill string with blue
R_Aux.neoPixelSetValue(AuxSingLED, LEDInten, 0, 0, false); //Set a NeoPixel to red
R_Aux.neoPixelSetValue(AuxSingLED - 1, LEDInten / 10, 0, 0, false); //Set trailing NeoPixel to dimmed red
R_Aux.neoPixelSetValue(AuxSingLED + 1, LEDInten / 10, 0, 0, true); //Set leading NeoPixel to dimmed red
L_Aux.neoPixelFill(0, 0, LEDInten, false); //Fill string with blue
L_Aux.neoPixelSetValue(AuxSingLED, LEDInten, 0, 0, false); //Set a NeoPixel to red
L_Aux.neoPixelSetValue(AuxSingLED - 1, LEDInten / 10, 0, 0, false); //Set trailing NeoPixel to dimmed red
L_Aux.neoPixelSetValue(AuxSingLED + 1, LEDInten / 10, 0, 0, true); //Set leading NeoPixel to dimmed red
AuxSingLED = AuxSingLED + 3; //Marquis - move R_Aux and L_Aux red LEDs along NeoPixel string 3 pixels at a time.
if (AuxSingLED >= AUX_LEN) AuxSingLED = 0; //If at end of string, return to start.
delay(LEDSpeed); //Set how long to delay code execution cycle depending upon throttle level.
}
Arduino IDE Code END:
</neopixelconnect.h>
リスト1:NeoPixelストリップを制御するためのArduino IDEコード。
プログラム全体は、遅延関数の排除により改善され、スロットルからの入力値または入力値マッピングを操作することでLEDをより高速に動作させることができます。残りのストリップは、希望するパターンや色に変更できます。パイロットは、航空機の方向と進路を決定するために、認識可能なライトパターンに依存していることを念頭に置いてください。夜間の飛行は楽しいと同時に挑戦でもあります。夜間飛行の練習は、飛行機とLEDを同時に見ることができる夕方の早い時間に行いましょう。
関連リソース:
ブログ:低コストのRC戦闘UAVの作り方

Have questions or comments? Continue the conversation on TechForum, Digi-Key's online community and technical resource.
Visit TechForum