組み上がったらパソコンとArduino Nanoをつなげて
「スケッチ」をArduino Nanoへ書き込む作業をします
「スケッチ」とは要はプログラム自体を指します
準備、書き込み作業はArduino IDEというアプリを使用します
Windows版、MacOS版ともにあります
最近何かと話題のM1(ARM64) Macでも使用可能です
筆者はMacで行いました
Windows10では何故かうまくいかなかった・・・
んー、USBシリアルドライバの問題かな?
Arduino IDEをインストールしたあとは
設定してサンプルのBlinkを試せ、と説明にはあるのですが
購入した当初から1秒毎に点滅しているので
そもそもうまくいったかどうかがわからないという・・・
設定すべき項目は環境設定から「行番号を表示」にすると
どこに何が書いてあるかがわかりやすいのと
「ツール」の「ボード」を「Arduino Nano」に
「プロセッサ」を「ATmega328P」に
シリアルポートはそれっぽいのを選んでください
設定が終わったあとは
「ファイル」の「スケッチ例」から「01.Basic」の
「Blink」を選択し
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
34、36行目のオレンジの部分
1000(ms)<1秒>の部分を200<0.2秒>とか300<0.3秒>にして
「マイコンボードに書き込む」を選ぶと
Arduino NanoのRX LEDが赤く点灯し
その後、L LEDがより素早く点滅するようになります
こうやって正常に動いているか確認するんですね・・・
これで正常に書き込めることがわかったら
いよいよ、DMXUSBとFlash LEDを組み込んでいきます
「ツール」の「ライブラリを管理」から
検索ボックスでFastLEDと入力し出てきたものをインストール
同様にDMXUSBについてもインストールします
その過程で「elapsedMillis」もインストールしないと
マイコンボードに書き込む際にコンポーネントが足りないと
怒られてしまいますので、ついでに入れておきましょう
「ファイル」の「新規ファイル」で作成し、以下をペーストします
元のコードテキストはこちらにありますのでご参照を
/* DMXUSB_FastLED.ino
* Originally created 11/25/2017 by Perry Naseck (DaAwesomeP)
* This is an example sketch for the DMXUSB Arduino/Teensy library to drive adressable LEDs with the FastLED library.
* https://github.com/DaAwesomeP/dmxusb/
*
* Copyright 2017-present Perry Naseck (DaAwesomeP)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// The example uses code from the FastLED Blink example here:
// https://github.com/FastLED/FastLED/blob/master/examples/Blink/Blink.ino
// More information about FastLED here: https://github.com/FastLED/FastLED
#include "DMXUSB.h"
#include <FastLED.h>
// DMXUSB should receive and transmit data at the highest, most reliable speed possible
// Recommended Arduino baud rate: 115200 (limits maximum framerate and/or number of channels
// Recommended Teensy USB baud rate: 12000000 (12 Mb/s)
// DMX baud rate: 250000
// MIDI baud rate: 31250
#define DMXUSB_BAUDRATE 115200
// Number of LEDs on the strip
#define NUM_LEDS 16
// For LED chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN. For LED chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 7
#define CLOCK_PIN 13
// Define the array of LEDs
CRGB leds[NUM_LEDS];
// receive a DMX transmission
void showLEDs(int universe, char buffer[512]) {
for (int index=0; index < 512; index++) { // for each channel, universe starts at 0
int value = buffer[index]; // DMX value 0 to 255
int LEDchannel = (universe*510) + index; // Find the LED number; can't fit a 3-channel fixture on the remaining two channels
if (LEDchannel <= (NUM_LEDS*3)-1) { // If DMX channel (LEDchannel starts at 0) is in range of LEDs (3 channels per LED for RGB)
int colorChannel = LEDchannel % 3; // Find the color channel of the LED addressed
int ledID = (LEDchannel - colorChannel) / 3; // Find the FastLED index of the LED addressed
if (colorChannel == 2) leds[ledID].b = value; // If the channel is red, write the red value of the LED
if (colorChannel == 1) leds[ledID].r = value; // If the channel is green, write the red value of the LED
if (colorChannel == 0) leds[ledID].g = value; // If the channel is blue, write the blue value of the LED
}
}
FastLED.show(); // Display the frame after processing all channels
}
DMXUSB DMXPC(
// Stream serial,
Serial,
// int baudrate,
DMXUSB_BAUDRATE,
// int mode,
// With mode==1, the library processes two universes for a total of 1024 DMX channels
1,
// void (*dmxInCallback)(int universe, unsigned int index, char buffer[512])
showLEDs
);
void setup() {
Serial.begin(DMXUSB_BAUDRATE);
// Uncomment/edit one of the following lines for your leds arrangement.
// FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
// FastLED.addLeds<APA104, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
}
void loop() {
DMXPC.listen();
}
htosakiさんのnoteでも紹介されていますが
編集するべき行は4箇所のみです
上から36行目あたりのオレンジ色の部分はLEDの個数を指定します
私の環境では16個のLEDテープがあるので16になっていますが
WS2812B Stick8でしたら8個ですので、8でOKです
次、41行目あたりの緑色の部分は
データを送るピンの番号を指定します
前回、「D7」を使用するようにしましたので
DATA PIN 7が指定されています
55行目あたり紫色の3行
これはOP-Zのカラー指定にあわせるために
このようになっています
最後に84行目あたり
赤色の行は使用するLEDの型番に合わせてあげる必要性があります
元は「//」でコメントアウト(その行はプログラム的には無視される)
されていますので、「//」を削除して
使用していないLEDの行は削除するか「//」でコメントアウトしましょう
ここまで終わりましたら
「マイコンボードに書き込む」で完了です
さぁ、このあとはいよいよOP-Zにつないで実際に光らせます!!!