-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nose software1 #12
Nose software1 #12
Changes from 14 commits
3185e41
23b9a6d
d75e37a
37b76f5
3f9322f
6ffb118
c1504fd
2807d40
baac4f9
918a4f8
68883fb
1861f6e
5e1f8e0
9f18972
cc9d769
b7cf0ff
0df9e7f
e4688e0
5c8b4d6
0fced30
a400766
30499e9
2ef5251
1884bef
5886f89
f13216a
ef97a3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vscode |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#include <Wire.h> | ||
#include <Adafruit_BME280.h> | ||
#include <MCP342X.h> | ||
#include <CCP_MCP2515.h> | ||
|
||
#define CAN_AVAIRABLE | ||
|
||
#define CAN0_CS 0 | ||
#define CAN0_INT 1 | ||
#define LED_YELLOW LED_BUILTIN | ||
#define LED_BLUE PIN_LED_RXL | ||
|
||
#define SEALEVELPRESSURE_HPA (1013.25) | ||
|
||
Adafruit_BME280 bme; | ||
MCP342X myADC; | ||
CCP_MCP2515 CCP(CAN0_CS, CAN0_INT);//CAN | ||
|
||
unsigned long delayTime; | ||
nihinihikun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const int clockFrequency = 400000;//I2C bus speed | ||
bool timer100Hz = false; | ||
bool sleep_sensors = false; | ||
bool can_checkerflag = false; | ||
struct repeating_timer st_timer; | ||
|
||
void setup() { | ||
Serial.begin(1843200); | ||
Wire.setSDA(6); | ||
Wire.setSCL(7); | ||
Wire.setClock(clockFrequency); | ||
Wire.begin(); | ||
bme.begin(0x76); | ||
myADC.configure( MCP342X_MODE_CONTINUOUS | | ||
MCP342X_CHANNEL_1 | | ||
MCP342X_SIZE_18BIT | | ||
MCP342X_GAIN_1X | ||
); | ||
add_repeating_timer_us(10000, TimerIsr, NULL, &st_timer);//100Hz | ||
#ifdef CAN_AVAIRABLE | ||
CCP.begin(); | ||
#endif | ||
} | ||
|
||
void loop() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
static int32_t result; | ||
static float temperature; | ||
static float barometic_pressure; | ||
static char adc_bytes[3]; | ||
static double voltage; | ||
if(timer100Hz){ | ||
timer100Hz = false; | ||
if(!sleep_sensors){ | ||
//差圧センサ関連 | ||
myADC.startConversion(); | ||
myADC.getResult(&result); | ||
DevideBytes(&result, adc_bytes); | ||
ConvertToVoltage(adc_bytes, &voltage); //3つのバイトを電圧に変換 | ||
//BME280関連 | ||
GetBME280Data(&temperature, &barometic_pressure); | ||
//CAN送信 | ||
#ifdef CAN_AVAIRABLE | ||
CCP.uint32_to_device(CCP_nose_adc,voltage); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
CCP.float_to_device(CCP_nose_temperature, temperature); | ||
CCP.float_to_device(CCP_nose_barometic_pressure, barometic_pressure); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
if(can_checkerflag){ | ||
CCP.string_to_device(CCP_nose_status,"OK"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
can_checkerflag = false; | ||
} | ||
#endif | ||
|
||
//シリアル出力 | ||
SerialPrintSensors(adc_bytes, temperature, barometic_pressure, voltage); | ||
} | ||
} | ||
#ifdef CAN_AVAIRABLE | ||
CCP.read_device(); | ||
switch (CCP.id) | ||
{ | ||
case CCP_EMST_mesure: | ||
if(CCP.str_match("STOP",4)){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
sleep_sensors = true; | ||
}else if(CCP.str_match("CLEAR", 5)){ | ||
sleep_sensors = false; | ||
} | ||
break; | ||
case CCP_nose_adc: | ||
if(CCP.str_match("CHECK", 5)){ | ||
can_checkerflag = true; | ||
} | ||
if(CCP.str_match("KILL", 4)){ | ||
sleep_sensors = true; | ||
} | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
default: | ||
break; | ||
} | ||
#endif | ||
} | ||
|
||
void GetBME280Data(float* temperature,float* barometic_pressure){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
*temperature=bme.readTemperature(); | ||
*barometic_pressure=bme.readPressure(); | ||
} | ||
|
||
void DevideBytes(int32_t* _result,char* bytes){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
bytes[2] = (char)(*_result & 0xFF); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
bytes[1] = (char)((*_result >> 8) & 0xFF); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
bytes[0] = (char)((*_result >> 16) & 0xFF); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
} | ||
|
||
void ConvertToVoltage(char* bytes,double* voltage){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
double pga=1; | ||
double lsb=2*2.048/pow(2,18); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
|
||
byte msb=(bytes[0]>>6)&0x01; | ||
uint32_t outputcode=bytes[2]|(bytes[1]<<8)|((bytes[0]*0x01)<<16); | ||
if(msb==0x00){//正の値 | ||
*voltage=(double)(outputcode)*lsb/pga; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
}else{//負の値 | ||
outputcode=((~outputcode)&0x01FFFF)+1;//2の補数 | ||
*voltage=-(double)(outputcode)*lsb/pga; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
} | ||
} | ||
|
||
void SerialPrintSensors(char* adc_bytes,float temperature,float barometic_pressure,double voltage){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
// if(timer100Hz) Serial.println("overrun"); | ||
Serial.print("time:"); | ||
Serial.print(micros()); | ||
Serial.print(",adc_bytes:"); | ||
Serial.print(adc_bytes[0],HEX); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
Serial.print(adc_bytes[1],HEX); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
Serial.print(adc_bytes[2],HEX); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
Serial.print(",temperature:"); | ||
Serial.print(temperature,10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
Serial.print(","); | ||
Serial.print(",barometic_pressure:"); | ||
Serial.print(barometic_pressure,10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
Serial.print(",voltage:"); | ||
Serial.println(voltage,10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
} | ||
|
||
bool TimerIsr(struct repeating_timer *t){ | ||
timer100Hz = true; | ||
return true; | ||
} | ||
nihinihikun marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# ノーズソフトメモ" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 使用ライブラリ\n", | ||
"- [MCP3421](https://github.com/uChip/MCP342X)\n", | ||
"- " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## rp2040を使う上での注意点\n", | ||
"\n", | ||
"- USB認識をしなくなったら,BOOTボタンを押しながらUSB接続し,RP2040のドライブにリセット用のuf2ファイルをドラック&ドロップ\n", | ||
"- Wire.hを使う前に,rp2040はI2Cがいくつもあるので,どのGPIOを使うか宣言する必要がある.\n", | ||
"```\n", | ||
"#define PIN1_SDA 6\n", | ||
"#define PIN1_SCL 7\n", | ||
"Wire.setSDA(PIN1_SDA);\n", | ||
"Wire.setSCL(PIN1_SCL);\n", | ||
"Wire.begin(); \n", | ||
"```\n", | ||
"といったように" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <Wire.h> | ||
#include <Adafruit_BME280.h> | ||
|
||
|
||
#define SEALEVELPRESSURE_HPA (1013.25) | ||
|
||
Adafruit_BME280 bme; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
|
||
unsigned long delayTime; | ||
nihinihikun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const int clockFrequency = 400000;//I2C bus speed | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
unsigned status; | ||
Wire.setSDA(6); | ||
Wire.setSCL(7); | ||
Wire.setClock(clockFrequency); | ||
Wire.begin(); | ||
status = bme.begin(0x76); | ||
} | ||
|
||
|
||
void loop() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
printValues(); | ||
delay(5); | ||
} | ||
|
||
|
||
void printValues() { | ||
Serial.print("Temperature = "); | ||
Serial.print(bme.readTemperature()); | ||
Serial.println(" °C"); | ||
|
||
Serial.print("Pressure = "); | ||
|
||
Serial.print(bme.readPressure() / 100.0F); | ||
Serial.println(" hPa"); | ||
|
||
Serial.print("Approx. Altitude = "); | ||
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); | ||
Serial.println(" m"); | ||
|
||
Serial.print("Humidity = "); | ||
Serial.print(bme.readHumidity()); | ||
Serial.println(" %"); | ||
|
||
Serial.println(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include <Wire.h> | ||
#include <Adafruit_BME280.h> | ||
#include <MCP342X.h> | ||
|
||
#define SEALEVELPRESSURE_HPA (1013.25) | ||
|
||
Adafruit_BME280 bme; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
MCP342X myADC; | ||
|
||
unsigned long delayTime; | ||
nihinihikun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const int clockFrequency = 400000;//I2C bus speed | ||
|
||
double voltage; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
unsigned status; | ||
Wire.setSDA(6); | ||
Wire.setSCL(7); | ||
Wire.setClock(clockFrequency); | ||
Wire.begin(); | ||
status = bme.begin(0x76); | ||
myADC.configure( MCP342X_MODE_CONTINUOUS | | ||
MCP342X_CHANNEL_1 | | ||
MCP342X_SIZE_18BIT | | ||
MCP342X_GAIN_1X | ||
); | ||
} | ||
|
||
|
||
void loop() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
printValues(); | ||
|
||
static int32_t result; | ||
byte bytes[4]; | ||
myADC.startConversion(); | ||
myADC.getResult(&result); | ||
ConvertToVoltage(&result,&voltage); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
Serial.print("voltage:"); | ||
Serial.println(voltage,10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
delay(5); | ||
} | ||
|
||
|
||
void printValues() { | ||
Serial.print("Temperature = "); | ||
Serial.print(bme.readTemperature()); | ||
Serial.println(" °C"); | ||
|
||
Serial.print("Pressure = "); | ||
|
||
Serial.print(bme.readPressure() / 100.0F); | ||
Serial.println(" hPa"); | ||
|
||
Serial.print("Approx. Altitude = "); | ||
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); | ||
Serial.println(" m"); | ||
|
||
Serial.print("Humidity = "); | ||
Serial.print(bme.readHumidity()); | ||
Serial.println(" %"); | ||
|
||
Serial.println(); | ||
} | ||
|
||
void ConvertToVoltage(int32_t* _result,double* voltage){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
byte bytes[4]; | ||
bytes[3] = (char)(*_result & 0xFF); | ||
nihinihikun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bytes[2] = (char)((*_result >> 8) & 0xFF); | ||
nihinihikun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bytes[1] = (char)((*_result >> 16) & 0xFF); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
bytes[0] = (char)((*_result >> 24) & 0xFF); //ライブラリの関数内で8bit右シフトしたときに発生したものなので無視 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
double pga=1; | ||
double lsb=2*2.048/pow(2,18); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
byte msb=(bytes[1]>>6)&0x01; | ||
uint32_t outputcode=bytes[3]|(bytes[2]<<8)|((bytes[1]*0x01)<<16); | ||
if(msb==0x00){//正の値 | ||
*voltage=(double)(outputcode)*lsb/pga; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
}else{//負の値 | ||
outputcode=((~outputcode)&0x01FFFF)+1;//2の補数 | ||
*voltage=-(double)(outputcode)*lsb/pga; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cpplint] reported by reviewdog 🐶 |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[cpplint] reported by reviewdog 🐶
Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]