Skip to content
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

add files #16

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/arduino_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ jobs:
vendor: rp2040
arch: rp2040
name: seeed_xiao_rp2040

- sketch-paths: Nose
libraries: |
-
board:
vendor: rp2040
arch: rp2040
name: seeed_xiao_rp2040

include:
- code:
Expand Down
3 changes: 3 additions & 0 deletions Nose/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
source/trash
pullreq-memo.txt
Binary file added Nose/24thISE_nose.qproj
Binary file not shown.
141 changes: 141 additions & 0 deletions Nose/Nose.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <MCP342X.h>
#include <CCP_MCP2515.h>

bool can_avairable = true;

#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

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
if (can_avairable) {
CCP.begin();
}
}

void loop() {
static int32_t result = 0x00;
static float temperature = 0.0;
static float barometic_pressure = 0.0;
static char adc_bytes[3] = { 0x00, 0x00, 0x00 };
static double voltage = 0.0;
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送信
if (can_avairable) {
CCP.uint32_to_device(CCP_nose_adc, voltage);
CCP.float_to_device(CCP_nose_temperature, temperature);
CCP.float_to_device(CCP_nose_barometic_pressure, barometic_pressure);
if (can_checkerflag) {
CCP.string_to_device(CCP_nose_status, "OK");
can_checkerflag = false;
}
}
//シリアル出力
SerialPrintSensors(adc_bytes, temperature, barometic_pressure, voltage);
}
}
if (can_avairable) {
CCP.read_device();
switch (CCP.id) {
case CCP_EMST_mesure:
if (CCP.str_match("STOP", 4)) {
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;
}
if (CCP.str_match("CLEAR", 5)) {
sleep_sensors = false;
}
break;
default:
break;
}
}
}

void GetBME280Data(float* temperature, float* barometic_pressure) {
*temperature = bme.readTemperature();
*barometic_pressure = bme.readPressure();
}

void DevideBytes(int32_t* _result, char* bytes) {
bytes[2] = static_cast<char>(*_result & 0xFF); //(char)から変更.C-style castを使うとunsafeなコードになるので
bytes[1] = static_cast<char>((*_result >> 8) & 0xFF);
bytes[0] = static_cast<char>((*_result >> 16) & 0xFF);
}

void ConvertToVoltage(char* bytes, double* voltage) {
double pga = 1;
double lsb = 2 * 2.048 / pow(2, 18);

byte msb = (bytes[0] >> 6) & 0x01;
uint32_t outputcode = bytes[2] | (bytes[1] << 8) | ((bytes[0] * 0x01) << 16);
if (msb == 0x00) { //正の値
*voltage = static_cast<double>(outputcode) * lsb / pga;
} else { //負の値
outputcode = ((~outputcode) & 0x01FFFF) + 1; //2の補数
*voltage = -static_cast<double>(outputcode) * lsb / pga;
}
}

void SerialPrintSensors(char* adc_bytes, float temperature, float barometic_pressure, double voltage) {
// if(timer100Hz) Serial.println("overrun");
Serial.print("time:");
Serial.print(micros());
Serial.print(",adc_bytes:");
Serial.print(adc_bytes[0], HEX);
Serial.print(adc_bytes[1], HEX);
Serial.print(adc_bytes[2], HEX);
Serial.print(",temperature:");
Serial.print(temperature, 10);
Serial.print(",");
Serial.print(",barometic_pressure:");
Serial.print(barometic_pressure, 10);
Serial.print(",voltage:");
Serial.println(voltage, 10);
}

bool TimerIsr(struct repeating_timer* t) {
timer100Hz = true;
return true;
}
72 changes: 72 additions & 0 deletions Nose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# ノーズ電装

## 概要
- This component has role of sensoring airspeed,temperature and barometic pressure.
- This component communicates with the main electrical compnent via the CAN protocol.
## ハードウェア
### BOM
#### MCU
- Seeduino Xiao RP2040

#### Sensor
- AE-BME280
- MPXV5050DP
#### ADC
- MCP3421
#### CAN
- MCP25625
#### Component
##### Capacitor
- [100uF16V 電解コン](https://akizukidenshi.com/catalog/g/gP-05002/)
- [100uF10V 3216](https://akizukidenshi.com/catalog/g/gP-15633/)
- [1uF25V 1608](https://akizukidenshi.com/catalog/g/gP-14526/)
- [0.01uF50V 1608](https://akizukidenshi.com/catalog/g/gP-13387/)
- [470pF50V 1608](https://akizukidenshi.com/catalog/g/gP-09268/)
##### Resisiter
- [100k 1/10W 1608](https://akizukidenshi.com/catalog/g/gR-11792/)
- [49.9k 1/10W 1608](https://akizukidenshi.com/catalog/g/gR-11804/)
- [4.7k 1/10W 1608](https://akizukidenshi.com/catalog/g/gR-14121/)

### 回路
<img src="images/circuit.png" width="100%">

### PCB
<img src="images/PCB1.png" width="300"><img src="images/PCB2.png" width="400">
## ソフトウェア
### 依存関係
- Wire.h
- CCP.h

## 基礎知識

### ベルヌーイの定理
<img src="images/basic_knowledge/image.png" width="50%">

$$p_1+\frac{1}{2} \rho v_1^2+\rho g z_1=p_2+\frac{1}{2}\rho v_2^2+\rho g z_2=\mathrm{const.}$$

https://www.cradle.co.jp/glossary/ja_H/detail0038.html

ここで空気密度$\rho$について考える.大気の標準組成は

- $O_2=20.99$ %
- $N_2=78.04$ %
- $CO_2=0.03$ %
- $Ar=0.94$ %

そこから求まる大気の分子量は
$$M=28.966[\mathrm{g/mol}]$$
となる.気体の質量密度は,
$$\rho=M\frac{n}{V}=\frac{MP}{RT}$$
ここで,$R=8.314[\mathrm{Nmmol^{-1}K^{-1}}]$,とすると,
$$\rho=\frac{28.966\times P}{8.314\times T}$$
とわかる.

http://sasaki.g1.xrea.com/powerpoint/vaporization-heat/03-Air-density.pdf








Binary file added Nose/images/PCB1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Nose/images/PCB2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Nose/images/basic_knowledge/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Nose/images/circuit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Nose/quadcept_libraries/MCP3421.qcom
Binary file not shown.
89 changes: 89 additions & 0 deletions Nose/quadcept_libraries/MCP3421A3T-E_CH.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<!--/803335/842757/2.50/6/3/Integrated Circuit/-->
<quadcept_library>
<setting unit="mil" />
<textstyle name="Default" height="47.244094488189" strokewidth="7.8740157480315" charwidth="47.244094488189" />
<textstyle name="Dimension" height="19.6850393700787" strokewidth="0" charwidth="19.6850393700787" />
<textstyle name="H127W0635TH00762" height="50" strokewidth="3" charwidth="25" />
<textstyle name="H15W15TH02" height="59.0551181102362" strokewidth="7.8740157480315" charwidth="59.0551181102362" />
<padstyle name="r140_60" surface="True" plated="False" isvia="False" nopaste="False" nomask="True" complex="False" holesize="0">
<padshape layer="TOP" shape="rectangle" width="23.622047244094" height="55.11811023622" />
<padshape layer="TOP_SOLDER_MASK" shape="rectangle" width="31.496062992126" height="62.992125984251" />
<padshape layer="TOP_SOLDER_PASTE" shape="rectangle" width="23.622047244094" height="55.11811023622" />
</padstyle>
<footprint name="SOT95P270X145-6N" originx="0" originy="0" pickpointx="0" pickpointy="0">
<pcbpin number="1" name="1" style="r140_60" originx="-49.212598425196" originy="37.401574803149" rotation="90" />
<pcbpin number="2" name="2" style="r140_60" originx="-49.212598425196" originy="0" rotation="90" />
<pcbpin number="3" name="3" style="r140_60" originx="-49.212598425196" originy="-37.401574803149" rotation="90" />
<pcbpin number="4" name="4" style="r140_60" originx="49.212598425196" originy="-37.401574803149" rotation="90" />
<pcbpin number="5" name="5" style="r140_60" originx="49.212598425196" originy="0" rotation="90" />
<pcbpin number="6" name="6" style="r140_60" originx="49.212598425196" originy="37.401574803149" rotation="90" />
<line layer="TOP_PLACE_BOUND" originx="-86.614173228345" originy="70.866141732283" endx="86.614173228345" endy="70.866141732283" width="1.9685039370079" />
<line layer="TOP_PLACE_BOUND" originx="86.614173228345" originy="70.866141732283" endx="86.614173228345" endy="-70.866141732283" width="1.9685039370079" />
<line layer="TOP_PLACE_BOUND" originx="86.614173228345" originy="-70.866141732283" endx="-86.614173228345" endy="-70.866141732283" width="1.9685039370079" />
<line layer="TOP_PLACE_BOUND" originx="-86.614173228345" originy="-70.866141732283" endx="-86.614173228345" endy="70.866141732283" width="1.9685039370079" />
<line layer="TOP_ASSEMBLY" originx="-30.511811023622" originy="57.086614173228" endx="30.511811023622" endy="57.086614173228" width="3.9370078740157" />
<line layer="TOP_ASSEMBLY" originx="30.511811023622" originy="57.086614173228" endx="30.511811023622" endy="-57.086614173228" width="3.9370078740157" />
<line layer="TOP_ASSEMBLY" originx="30.511811023622" originy="-57.086614173228" endx="-30.511811023622" endy="-57.086614173228" width="3.9370078740157" />
<line layer="TOP_ASSEMBLY" originx="-30.511811023622" originy="-57.086614173228" endx="-30.511811023622" endy="57.086614173228" width="3.9370078740157" />
<line layer="TOP_ASSEMBLY" originx="-30.511811023622" originy="19.685039370078" endx="6.8897637795275" endy="57.086614173228" width="3.9370078740157" />
<line layer="TOP_SILKSCREEN" originx="-7.8740157480314" originy="57.086614173228" endx="7.8740157480314" endy="57.086614173228" width="7.8740157480314" />
<line layer="TOP_SILKSCREEN" originx="7.8740157480314" originy="57.086614173228" endx="7.8740157480314" endy="-57.086614173228" width="7.8740157480314" />
<line layer="TOP_SILKSCREEN" originx="7.8740157480314" originy="-57.086614173228" endx="-7.8740157480314" endy="-57.086614173228" width="7.8740157480314" />
<line layer="TOP_SILKSCREEN" originx="-7.8740157480314" originy="-57.086614173228" endx="-7.8740157480314" endy="57.086614173228" width="7.8740157480314" />
<line layer="TOP_SILKSCREEN" originx="-76.771653543306" originy="62.992125984251" endx="-21.653543307086" endy="62.992125984251" width="7.8740157480314" />
</footprint>
<symbol name="MCP3421A3T-E_CH" originx="0" originy="0">
<line originx="200" originy="100" endx="900" endy="100" width="0" />
<line originx="900" originy="-300" endx="900" endy="100" width="0" />
<line originx="900" originy="-300" endx="200" endy="-300" width="0" />
<line originx="200" originy="100" endx="200" endy="-300" width="0" />
<sympin number="1" originx="200" originy="0" rotation="180" length="100" width="7.8740157480315" flipped="False">
<text name="pinname" originx="230" originy="0" style="Default" rotation="0" justify="left" flipped="False" hidden="False" data="VIN+" />
<text name="pindes" originx="140" originy="20" style="Default" rotation="0" justify="lowerright" flipped="False" hidden="False" data="1" />
</sympin>
<sympin number="2" originx="200" originy="-100" rotation="180" length="100" width="7.8740157480315" flipped="False">
<text name="pinname" originx="230" originy="-100" style="Default" rotation="0" justify="left" flipped="False" hidden="False" data="VSS" />
<text name="pindes" originx="140" originy="-80" style="Default" rotation="0" justify="lowerright" flipped="False" hidden="False" data="2" />
</sympin>
<sympin number="3" originx="200" originy="-200" rotation="180" length="100" width="7.8740157480315" flipped="False">
<text name="pinname" originx="230" originy="-200" style="Default" rotation="0" justify="left" flipped="False" hidden="False" data="SCL" />
<text name="pindes" originx="140" originy="-180" style="Default" rotation="0" justify="lowerright" flipped="False" hidden="False" data="3" />
</sympin>
<sympin number="6" originx="900" originy="0" rotation="0" length="100" width="7.8740157480315" flipped="False">
<text name="pinname" originx="870" originy="0" style="Default" rotation="0" justify="right" flipped="False" hidden="False" data="VIN-" />
<text name="pindes" originx="960" originy="20" style="Default" rotation="0" justify="lowerleft" flipped="False" hidden="False" data="6" />
</sympin>
<sympin number="5" originx="900" originy="-100" rotation="0" length="100" width="7.8740157480315" flipped="False">
<text name="pinname" originx="870" originy="-100" style="Default" rotation="0" justify="right" flipped="False" hidden="False" data="VDD" />
<text name="pindes" originx="960" originy="-80" style="Default" rotation="0" justify="lowerleft" flipped="False" hidden="False" data="5" />
</sympin>
<sympin number="4" originx="900" originy="-200" rotation="0" length="100" width="7.8740157480315" flipped="False">
<text name="pinname" originx="870" originy="-200" style="Default" rotation="0" justify="right" flipped="False" hidden="False" data="SDA" />
<text name="pindes" originx="960" originy="-180" style="Default" rotation="0" justify="lowerleft" flipped="False" hidden="False" data="4" />
</sympin>
</symbol>
<component name="MCP3421A3T-E_CH" designatorprefix="IC" height="57.086614173228" footprint="SOT95P270X145-6N">
<comppin designator="1" sympin="1" pinswap="0" gateswap="0" gate="1" group="1" side="" type="Any" name="VIN+" />
<comppin designator="2" sympin="2" pinswap="0" gateswap="0" gate="1" group="1" side="" type="Any" name="VSS" />
<comppin designator="3" sympin="3" pinswap="0" gateswap="0" gate="1" group="1" side="" type="Any" name="SCL" />
<comppin designator="4" sympin="4" pinswap="0" gateswap="0" gate="1" group="1" side="" type="Any" name="SDA" />
<comppin designator="5" sympin="5" pinswap="0" gateswap="0" gate="1" group="1" side="" type="Any" name="VDD" />
<comppin designator="6" sympin="6" pinswap="0" gateswap="0" gate="1" group="1" side="" type="Any" name="VIN-" />
<attached_symbol gate="1" name="MCP3421A3T-E_CH" />
<pinmap designator="1" footprintpin="1" />
<pinmap designator="2" footprintpin="2" />
<pinmap designator="3" footprintpin="3" />
<pinmap designator="4" footprintpin="4" />
<pinmap designator="5" footprintpin="5" />
<pinmap designator="6" footprintpin="6" />
<text name="Datasheet" originx="0" originy="0" style="Default" rotation="0" justify="" flipped="False" hidden="True" data="http://www.microchip.com/mymicrochip/filehandler.aspx?ddocname=en520102" />
<text name="Description" originx="0" originy="0" style="Default" rotation="0" justify="" flipped="False" hidden="True" data="Analog to Digital Converters - ADC 18-B delta-sigma ADC Sngl Ch 4sps" />
<text name="Manufacturer_Name" originx="0" originy="0" style="Default" rotation="0" justify="" flipped="False" hidden="True" data="Microchip" />
<text name="Manufacturer_Part_Number" originx="950" originy="200" style="Default" rotation="0" justify="left" flipped="False" hidden="False" data="MCP3421A3T-E/CH" />
<text name="Mouser Part Number" originx="0" originy="0" style="Default" rotation="0" justify="" flipped="False" hidden="True" data="579-MCP3421A3T-E/CH" />
<text name="Mouser Price/Stock" originx="0" originy="0" style="Default" rotation="0" justify="" flipped="False" hidden="True" data="https://www.mouser.co.uk/ProductDetail/Microchip-Technology/MCP3421A3T-E-CH?qs=hH%252BOa0VZEiCiOakdR18pNw%3D%3D" />
<text name="Arrow Part Number" originx="0" originy="0" style="Default" rotation="0" justify="" flipped="False" hidden="True" data="MCP3421A3T-E/CH" />
<text name="Arrow Price/Stock" originx="0" originy="0" style="Default" rotation="0" justify="" flipped="False" hidden="True" data="https://www.arrow.com/en/products/mcp3421a3t-ech/microchip-technology?region=nac" />
</component>
</quadcept_library>
Binary file added Nose/quadcept_libraries/MPXVseries.qcom
Binary file not shown.
Binary file added Nose/quadcept_libraries/a.qcom
Binary file not shown.
Binary file added Nose/quadcept_libraries/xiao_original.qcom
Binary file not shown.
Binary file not shown.
Loading