TentoBug が 2025年01月04日16時16分20秒 に編集
方位?
タイトルの変更
SPRESENSEで関数ポインタを利用してLEDを光らせ高度?を表示・・・。
SPRESENSEで方位?を表示・・・。
本文の変更
# はじめに 2日目で挫折しそうになったで、文字化することにしました。 # 経過 1日目 1. チュートリアルにある動画で学ぶを視聴しました。 2. 開発環境のセットアップはでき、LEDも点灯はできました。 2日目 1. LCDをつけてSPIのサンプルプログラムを動かそうと思ったのですが、真っ黒。 2. 部品を外して配線だけ残して、LEDを2つつけました。 3. A3というのはDAでなくADということが分かりました。 4. Lチカと関数ポインタを利用して明るく暗くなりを繰り返します。 1週間目 1. SPIをあきらめてI2Cの設定をしました。
2. Arduino IDEのスケッチ例にあるgnssを改造してLCDに高度を表示するようにしました。
2. Arduino IDEのスケッチ例にあるgnssを改造してLCDに方位を表示するようにしました。
# 部品 || 部品 | 備考(敬称略) | |:---:|:---:|:---:| |U1、U3| SPRESENSE | | |U2| MM-TXS01 | サンハヤト | |U4| AE-AQM0802 | 秋月電子通商 | |D1| LED(赤) | | |D2| LED(黄) | | # 設計図  # ソースコード ```arduino:実験中
#define LED_PIN 13
#include <SFE_BMP180.h>
#include <time.h> #include <FFT.h> #include <GNSS.h> #include <Wire.h>/* I2C*/
#include <Flash.h> #include <File.h>
#define STRING_BUFFER_SIZE 128 /**< %Buffer size */ static SpGnss Gnss; /**< SpGnss object */
FFTClass<1, 32> FFT;
int duty=0; unsigned int warikomi(void){ digitalWrite(PIN_D22, HIGH); delayMicroseconds(duty); digitalWrite(PIN_D22, LOW);
delayMicroseconds(100-duty); return 100;
delayMicroseconds(500-duty); return 500;
} void setup() { /* ポートの設定 */ pinMode(PIN_D23, OUTPUT); pinMode(PIN_D22, OUTPUT); /* シリアル通信設定 */ Serial.begin(115200); sleep(3);
attachTimerInterrupt(warikomi,100);//100us
attachTimerInterrupt(warikomi,500);//us
/*LCDモジュール初期化*/ int i=0; char command[]={0x38,0x39,0x14,0x70,0x56,0x6C,0x38,0x0C,0x01}; Wire.begin(); Wire.beginTransmission(0x3E); Wire.write(command,9); Wire.endTransmission(); delay(200); Wire.beginTransmission(0x3E); Wire.write(0x40); Wire.write(0x31); Wire.endTransmission(); delay(200); /* Set serial baudrate. */ Serial.begin(115200); /* Set Debug mode to Info */ Gnss.setDebugMode(PrintInfo);
//Gnss.setInterval(SpInterval_1Hz);
int result; /* Activate GNSS device */ result = Gnss.begin();
Gnss.select(QZ_L1CA); Gnss.select(QZ_L1S); Gnss.select(GPS);
Gnss.select(QZ_L1S); Gnss.select(QZ_L1CA); Gnss.select(GPS);
/* Start positioning */ result = Gnss.start(COLD_START);
FFT.begin();
} static void print_pos(SpNavData *pNavData) { char StringBuffer[STRING_BUFFER_SIZE]; struct tm now;
struct tm anow; float ou[2]; q15_t hight[2];
int e=0; /* 日本時間の設定 日付?*/ now.tm_year =pNavData->time.year; now.tm_mon =pNavData->time.month; now.tm_mday =pNavData->time.day; now.tm_hour =pNavData->time.hour+9; now.tm_min =pNavData->time.minute; now.tm_sec =pNavData->time.sec; //mktime(&now);
hight[0]=pNavData->altitude; hight[1]=0; e=FFT.put(hight,32);//?? e+=FFT.get(ou,0); snprintf(StringBuffer, STRING_BUFFER_SIZE, "%02d:%02d:%02d,%f,%3.3f,%3.3f",
snprintf(StringBuffer, STRING_BUFFER_SIZE, "%02d:%02d:%02d,%f,%3.3f,%d",
now.tm_hour,// pNavData->time.minute, pNavData->time.sec,
pNavData->altitude,//高さ
pNavData->direction,
pNavData->velocity, //速さ
ou[0] );//FFT
duty );
Serial.print(StringBuffer); Serial.println(""); /* LCD2行目 */
snprintf(StringBuffer, STRING_BUFFER_SIZE, "%03.3f", pNavData->altitude);
snprintf(StringBuffer, STRING_BUFFER_SIZE, "%2d %3.2f", pNavData->numSatellites, pNavData->direction);
Wire.beginTransmission(0x3E); Wire.write(0x00); Wire.write(0x80+0x40); Wire.endTransmission();
delay(200);
delay(1);
Wire.beginTransmission(0x3E); Wire.write(0x40); Wire.write(StringBuffer,7); Wire.endTransmission();
delay(5);
delay(1);
/* LCD1行目 */ Wire.beginTransmission(0x3E); Wire.write(0x00); Wire.write(0x80); Wire.endTransmission();
delay(200);
delay(1);
Wire.beginTransmission(0x3E); Wire.write(0x40);
snprintf(StringBuffer, STRING_BUFFER_SIZE, "%2d", pNavData->numSatellites); Wire.write(StringBuffer,2);
snprintf(StringBuffer, STRING_BUFFER_SIZE, "%02d:%02d:%02d", now.tm_hour,// pNavData->time.minute, pNavData->time.sec); Wire.write(StringBuffer,8);
Wire.endTransmission();
delay(200);
delay(1);
}
int ad=0,cou;
int ad=0; int hugo=1; SpNavData NavData;
void loop() {
//1日目 digitalWrite(PIN_D23, HIGH); delay(500); digitalWrite(PIN_D23, LOW); delay(500); //2日目 //ad=analogRead(A3); //Serial.printf("%d %d\r\n",cou,duty); cou++; cou%=100; duty+=10; duty%=100; //??日目 LCDへ高度を表示 FF SpNavData NavData; Gnss.getNavData(&NavData); print_pos(&NavData); }
if(duty>499){ hugo=-1; }else{ if(duty<1)hugo=1; } duty+=hugo;
void setup() { pinMode(LED_PIN, OUTPUT);
//??日目 LCDへ方位を表示 FF /* Check update. */ if (Gnss.waitUpdate(-1)){ Gnss.getNavData(&NavData); print_pos(&NavData); }
}
void loop() { digitalWrite(LED_PIN, HIGH); delay(1000); digitalWrite(LED_PIN, LOW); delay(1000); }
``` # 考察
1. シリアルモニターに、はきだされるデータを「type COMX > 1.csv」でファイルにして、表計算ソフトでグラフ化しました。青がGNSSの高度なのですが、標高になるのだろうか? じっとしているのにバラツキがあるように感じるので、もう少し眺めてみようと思っています。 2. FFTのライブラリの使い方が??。うーん。 FFTClass<1, 32> FFT; e=FFT.put(hight,32); 3. 周波数分析に使う道具の使い方としては・・・・。周期的なものがあったら面白そうだしな・・・・。ばらつくか・・・。 4. とりあえず平均と偏差を求めよ。 
1. 同じ場所でグルグル回っても方位を示す数値がおかしいような気がしました。 2. 電池式にして屋外へ行くと緯度や経度が変わったら変わるような気がしてきたのですが、どうなのだろう。 3. LEDが変化していないな・・・。 
# 参考
https://elchika.com/promotion/spresense2024/library/#nav https://developer.sony.com/spresense/development-guides/arduino_developer_guide_ja.html#_signalprocessing_%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA
[https://elchika.com/promotion/spresense2024/library/#nav](https://elchika.com/promotion/spresense2024/library/#nav) [https://developer.sony.com/spresense/development-guides/arduino_developer_guide_ja.html#_signalprocessing_%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA](https://developer.sony.com/spresense/development-guides/arduino_developer_guide_ja.html#_signalprocessing_%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA)