a23_neopixel1
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
* easy-CでNeoPixelを制御するためのメモ#1
-(by [[K]], 2024.02.10)
** (1)
-資料1: https://garretlab.web.fc2.com/arduino.cc/docs/tut...
-資料2: https://cediablog.com/arduino-unor4wifi-review/
-資料3: https://maicommon.ciao.jp/ss/Arduino_g/serial/ind...
-資料4: https://maicommon.ciao.jp/ss/Arduino_g/intrupt/in...
-資料5: https://maicommon.ciao.jp/ss/Arduino_g/
-資料6: https://qiita.com/hsgucci/items/eee5894e3651d0a8c...
-資料7: https://www.zep.co.jp/nbeppu/article/z-pico-da2/
-資料8: https://ysin1128.hatenablog.com/entry/2021/08/25/...
-資料9: https://ysin1128.hatenablog.com/entry/2021/12/10/...
-資料10: https://kats-eye.net/info/2018/11/07/neopixel/
-資料11: https://learn.adafruit.com/adafruit-neopixel-ube...
-資料12: https://ja.librosnews.com/getting-started-with-n...
-資料1~6: Arduino UNO 向けの資料
-資料7~9: ラズベリーパイ pico 向けの資料
-ラズベリーパイ pico はモデルHがよい。なぜならピンが最初...
-Arduino UNO でも ラズパイpico でも、どちらでもできそう。...
-Arduino UNO R3 の場合、処理能力が十分かどうかは少し心配。
-しかしArduino UNO R4 Wifiで試したところうまくいかなかっ...
** (2)
-NeoPixelは1つにつき60mAを要すると書いてあります(資料11...
//-まず[資料1]でArduino IDEをインストール。Arduino UNO R4...
** (3)
-必要なもの:
--Arduino UNO R3 (AmazonでUSBケーブル付きで1230円くらい...
--WS2812B 7LED (Amazonなら2個で550円くらい・互換品)
--300~500オームの抵抗(家にあったものを流用)
//--1000uFのコンデンサ(Amazonなら10個で500円くらい)
--結線用のジャンプワイヤ・はんだ
--(これでUSB電源だけでも合計500mA弱まではいける?)
-資料10を参考にして、Arduino側やNeoPixelを準備
~
-Arduino UNO R3側のコード(スケッチ)
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit ...
#endif
#define Pin 6 // (GP6 for RaspberryPiPico)
#define NumPixels 7
Adafruit_NeoPixel pixels(NumPixels, Pin, NEO_GRB + NEO_K...
void setup() {
Serial.begin(115200);
pixels.begin();
}
void loop() {
for (;;) {
int c = Serial.read();
if (c < 0) {
delay(3);
continue;
}
if (c == 0xf1) {
pixels.clear();
continue;
}
if (c == 0xf2) {
pixels.show();
continue;
}
if (c == 0xf3) {
while (Serial.available() < 3) {}
int i = Serial.read() << 8; i |= Serial.read(); //...
int n = Serial.read();
while (n > 0) {
while (Serial.available() < 3) {}
int r = Serial.read();
int g = Serial.read();
int b = Serial.read();
pixels.setPixelColor(i, pixels.Color(r, g, b));
i++; n--;
}
}
}
}
-Arduinoでのシリアル通信の資料: https://miraiworks.org/?p...
~
-PC側のコード(ひとまずテスト用にC言語で書いています、ま...
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
int main()
{
HANDLE comPort = CreateFile(_T("COM3"), GENERIC_READ...
// シリアルポートを開き、ハンドルを取得(※10番以...
DCB dcb; // シリアルポートの構成情報が入る構造体
GetCommState(comPort, &dcb); // 現在の設定値を読み込み
dcb.BaudRate = 115200; // 速度
dcb.ByteSize = 8; // データ長
dcb.Parity = NOPARITY; // パリティ
dcb.StopBits = ONESTOPBIT; // ストップビット長
dcb.fOutxCtsFlow = FALSE; // 送信時CTSフロー
dcb.fRtsControl = RTS_CONTROL_ENABLE; // RTSフロー
SetCommState(comPort, &dcb); // 変更した設定値を書き...
Sleep(3000); // とりあえず安定させるために待つ.
static unsigned char a[] = {
0xf1, 0xf3, 0x00, 0x00, 3, 1, 0, 0, 0, 1, 0, 0, ...
// 電力さえ心配なければ[255 0 0]などでももちろん...
};
DWORD n;
WriteFile(comPort, a, sizeof a, &n, NULL);
CloseHandle(comPort);
}
-WindowsからCOMポートで通信する資料: https://www.salutewe...
-Arduinoとの通信パラメータの資料: https://www.arduino.cc/...
--これでSerial.begin()のデフォルトパラメータが SERIAL_8N1...
** (4)
-上記のコードだと Arduino UNO R3 では問題なく動くけど、Ra...
-原因は DCB の設定が足りてないこと。
--参考: https://ysin1128.hatenablog.com/entry/2021/08/25...
-ということで、DTRフローの設定もやる。このコードはたぶん ...
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
int main()
{
HANDLE comPort = CreateFile(_T("COM3"), GENERIC_READ...
// シリアルポートを開き、ハンドルを取得(※10番以...
DCB dcb; // シリアルポートの構成情報が入る構造体
GetCommState(comPort, &dcb); // 現在の設定値を読み込み
dcb.BaudRate = 115200; // 速度
dcb.ByteSize = 8; // データ長
dcb.Parity = NOPARITY; // パリティ
dcb.StopBits = ONESTOPBIT; // ストップビット長
dcb.fOutxCtsFlow = FALSE; // 送信時CTSフロー
dcb.fRtsControl = RTS_CONTROL_ENABLE; // RTSフロー
dcb.fDtrControl = DTR_CONTROL_ENABLE; // DTRフロー ←...
SetCommState(comPort, &dcb); // 変更した設定値を書き...
Sleep(3000); // とりあえず安定させるために待つ.
static unsigned char a[] = {
0xf1, 0xf3, 0x00, 0x00, 3, 1, 0, 0, 0, 1, 0, 0, ...
// 電力さえ心配なければ[255 0 0]などでももちろん...
};
DWORD n;
WriteFile(comPort, a, sizeof a, &n, NULL);
CloseHandle(comPort);
}
終了行:
* easy-CでNeoPixelを制御するためのメモ#1
-(by [[K]], 2024.02.10)
** (1)
-資料1: https://garretlab.web.fc2.com/arduino.cc/docs/tut...
-資料2: https://cediablog.com/arduino-unor4wifi-review/
-資料3: https://maicommon.ciao.jp/ss/Arduino_g/serial/ind...
-資料4: https://maicommon.ciao.jp/ss/Arduino_g/intrupt/in...
-資料5: https://maicommon.ciao.jp/ss/Arduino_g/
-資料6: https://qiita.com/hsgucci/items/eee5894e3651d0a8c...
-資料7: https://www.zep.co.jp/nbeppu/article/z-pico-da2/
-資料8: https://ysin1128.hatenablog.com/entry/2021/08/25/...
-資料9: https://ysin1128.hatenablog.com/entry/2021/12/10/...
-資料10: https://kats-eye.net/info/2018/11/07/neopixel/
-資料11: https://learn.adafruit.com/adafruit-neopixel-ube...
-資料12: https://ja.librosnews.com/getting-started-with-n...
-資料1~6: Arduino UNO 向けの資料
-資料7~9: ラズベリーパイ pico 向けの資料
-ラズベリーパイ pico はモデルHがよい。なぜならピンが最初...
-Arduino UNO でも ラズパイpico でも、どちらでもできそう。...
-Arduino UNO R3 の場合、処理能力が十分かどうかは少し心配。
-しかしArduino UNO R4 Wifiで試したところうまくいかなかっ...
** (2)
-NeoPixelは1つにつき60mAを要すると書いてあります(資料11...
//-まず[資料1]でArduino IDEをインストール。Arduino UNO R4...
** (3)
-必要なもの:
--Arduino UNO R3 (AmazonでUSBケーブル付きで1230円くらい...
--WS2812B 7LED (Amazonなら2個で550円くらい・互換品)
--300~500オームの抵抗(家にあったものを流用)
//--1000uFのコンデンサ(Amazonなら10個で500円くらい)
--結線用のジャンプワイヤ・はんだ
--(これでUSB電源だけでも合計500mA弱まではいける?)
-資料10を参考にして、Arduino側やNeoPixelを準備
~
-Arduino UNO R3側のコード(スケッチ)
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit ...
#endif
#define Pin 6 // (GP6 for RaspberryPiPico)
#define NumPixels 7
Adafruit_NeoPixel pixels(NumPixels, Pin, NEO_GRB + NEO_K...
void setup() {
Serial.begin(115200);
pixels.begin();
}
void loop() {
for (;;) {
int c = Serial.read();
if (c < 0) {
delay(3);
continue;
}
if (c == 0xf1) {
pixels.clear();
continue;
}
if (c == 0xf2) {
pixels.show();
continue;
}
if (c == 0xf3) {
while (Serial.available() < 3) {}
int i = Serial.read() << 8; i |= Serial.read(); //...
int n = Serial.read();
while (n > 0) {
while (Serial.available() < 3) {}
int r = Serial.read();
int g = Serial.read();
int b = Serial.read();
pixels.setPixelColor(i, pixels.Color(r, g, b));
i++; n--;
}
}
}
}
-Arduinoでのシリアル通信の資料: https://miraiworks.org/?p...
~
-PC側のコード(ひとまずテスト用にC言語で書いています、ま...
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
int main()
{
HANDLE comPort = CreateFile(_T("COM3"), GENERIC_READ...
// シリアルポートを開き、ハンドルを取得(※10番以...
DCB dcb; // シリアルポートの構成情報が入る構造体
GetCommState(comPort, &dcb); // 現在の設定値を読み込み
dcb.BaudRate = 115200; // 速度
dcb.ByteSize = 8; // データ長
dcb.Parity = NOPARITY; // パリティ
dcb.StopBits = ONESTOPBIT; // ストップビット長
dcb.fOutxCtsFlow = FALSE; // 送信時CTSフロー
dcb.fRtsControl = RTS_CONTROL_ENABLE; // RTSフロー
SetCommState(comPort, &dcb); // 変更した設定値を書き...
Sleep(3000); // とりあえず安定させるために待つ.
static unsigned char a[] = {
0xf1, 0xf3, 0x00, 0x00, 3, 1, 0, 0, 0, 1, 0, 0, ...
// 電力さえ心配なければ[255 0 0]などでももちろん...
};
DWORD n;
WriteFile(comPort, a, sizeof a, &n, NULL);
CloseHandle(comPort);
}
-WindowsからCOMポートで通信する資料: https://www.salutewe...
-Arduinoとの通信パラメータの資料: https://www.arduino.cc/...
--これでSerial.begin()のデフォルトパラメータが SERIAL_8N1...
** (4)
-上記のコードだと Arduino UNO R3 では問題なく動くけど、Ra...
-原因は DCB の設定が足りてないこと。
--参考: https://ysin1128.hatenablog.com/entry/2021/08/25...
-ということで、DTRフローの設定もやる。このコードはたぶん ...
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
int main()
{
HANDLE comPort = CreateFile(_T("COM3"), GENERIC_READ...
// シリアルポートを開き、ハンドルを取得(※10番以...
DCB dcb; // シリアルポートの構成情報が入る構造体
GetCommState(comPort, &dcb); // 現在の設定値を読み込み
dcb.BaudRate = 115200; // 速度
dcb.ByteSize = 8; // データ長
dcb.Parity = NOPARITY; // パリティ
dcb.StopBits = ONESTOPBIT; // ストップビット長
dcb.fOutxCtsFlow = FALSE; // 送信時CTSフロー
dcb.fRtsControl = RTS_CONTROL_ENABLE; // RTSフロー
dcb.fDtrControl = DTR_CONTROL_ENABLE; // DTRフロー ←...
SetCommState(comPort, &dcb); // 変更した設定値を書き...
Sleep(3000); // とりあえず安定させるために待つ.
static unsigned char a[] = {
0xf1, 0xf3, 0x00, 0x00, 3, 1, 0, 0, 0, 1, 0, 0, ...
// 電力さえ心配なければ[255 0 0]などでももちろん...
};
DWORD n;
WriteFile(comPort, a, sizeof a, &n, NULL);
CloseHandle(comPort);
}
ページ名: