動作
Feature #39
已結束是由 宏益 廖 於 約 1 年 前更新
- 檔案 clipboard-202309281419-gcvfy.png clipboard-202309281419-gcvfy.png 已新增
- 檔案 clipboard-202309281421-i5lzk.png 已新增
- 檔案 clipboard-202309281422-dgpwc.png clipboard-202309281422-dgpwc.png 已新增
- 檔案 clipboard-202309281515-cqwdw.png clipboard-202309281515-cqwdw.png 已新增
- 檔案 clipboard-202309281517-s1ijy.png clipboard-202309281517-s1ijy.png 已新增
- 檔案 clipboard-202309281524-lag57.png clipboard-202309281524-lag57.png 已新增
- 檔案 clipboard-202309281525-wltlr.png clipboard-202309281525-wltlr.png 已新增
- 檔案 clipboard-202309281526-fyy6u.png clipboard-202309281526-fyy6u.png 已新增
- 檔案 clipboard-202309281528-2vseo.png clipboard-202309281528-2vseo.png 已新增
- 檔案 clipboard-202309281553-l0von.png clipboard-202309281553-l0von.png 已新增
是由 宏益 廖 於 約 1 年 前更新
*PlatformIO環境建置¶
https://youtu.be/tc3Qnf79Ny8?si=YHI-0SoWeARC6mx1
>>>""Ctrl+左鍵""這個功能很重要一定要會用
------------------------------------------------------------------------------------------------------------------------------------------------¶
匯入函數庫(直接丟src資料夾)
============================================================================================
*接線¶
如圖(若使用DBK請將上方針腳用短路夾short)
============================================================================================
*程式(從Beginner.ino改)¶
#include <ArduinoAdaptor.h>
#include <NSP32.h>
using namespace NanoLambdaNSP32;
/***********************************************************************************
* modify this section to fit your need *
***********************************************************************************/
const unsigned int PinRst = 27; // pin Reset
const unsigned int PinReady = 17; // pin Ready
/***********************************************************************************/
ArduinoAdaptor adaptor(PinRst); // master MCU adaptor
NSP32 nsp32(&adaptor, NSP32::ChannelSpi); // NSP32 (using SPI channel)
void PinReadyTriggerISR() {
// make sure to call this function when receiving a ready trigger from NSP32
nsp32.OnPinReadyTriggered();
}
void setup() {
// initialize "ready trigger" pin for accepting external interrupt (falling edge trigger)
pinMode(PinReady, INPUT_PULLUP); // use pull-up
attachInterrupt(digitalPinToInterrupt(PinReady), PinReadyTriggerISR, FALLING); // enable interrupt for falling edge
// initialize serial port for "Serial Monitor"
Serial.begin(115200);
// initialize NSP32
nsp32.Init();
Serial.println("Init");
// =============== standby ===============
nsp32.Standby(0);
Serial.println("Standby");
// =============== wakeup ===============
nsp32.Wakeup();
Serial.println("Wakeup");
// =============== hello ===============
nsp32.Hello(0);
Serial.println("Hello");
// =============== get sensor id ===============
nsp32.GetSensorId(0);
Serial.println("GetSensorId");
char szSensorId[15]; // sensor id string buffer
nsp32.ExtractSensorIdStr(szSensorId); // now we have sensor id string in szSensorId[]
Serial.print(F("sensor id = "));
Serial.println(szSensorId);
// =============== get wavelength ===============
nsp32.GetWavelength(0);
WavelengthInfo infoW;
nsp32.ExtractWavelengthInfo(&infoW); // now we have all wavelength info in infoW, we can use e.g. "infoW.Wavelength" to access the wavelength data array
Serial.print(F("Elements of wavelength = "));
//Serial.println(infoW.Wavelength[0]);
for(int i = 0; i < 75; i++){
Serial.printf("%d ",infoW.Wavelength[i]);
}
// =============== spectrum acquisition ===============
nsp32.AcqSpectrum(0, 32, 3, false); // integration time = 32; frame avg num = 3; disable AE
// "AcqSpectrum" command takes longer time to execute, the return packet is not immediately available
// when the acquisition is done, a "ready trigger" will fire, and nsp32.GetReturnPacketSize() will be > 0
while (nsp32.GetReturnPacketSize() <= 0) {
// TODO: can go to sleep, and wakeup when "ready trigger" interrupt occurs
nsp32.UpdateStatus(); // call UpdateStatus() to check async result
}
SpectrumInfo infoS;
nsp32.ExtractSpectrumInfo(&infoS); // now we have all spectrum info in infoW, we can use e.g. "infoS.Spectrum" to access the spectrum data array
Serial.print(F("Elements of spectrum = "));
//Serial.println(infoS.Spectrum[0], 6);
for(int i = 0; i < 75; i++){
Serial.printf("%.6f ",infoS.Spectrum[0], 6);
}
}
void loop() {
}
============================================================================================¶
*注意事項¶
============================================================================================¶
*結果¶
------------------------------------------------------------------------------------------------------------------------------------------------¶
動作