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

Nose software1 #12

Merged
merged 27 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3185e41
nose software develop start, try mcp3421
nihinihikun Dec 26, 2023
23b9a6d
adc covert to voltage, successed
nihinihikun Dec 27, 2023
d75e37a
test rp2040 and mcp3421
nihinihikun Dec 27, 2023
37b76f5
add readme to leave note
nihinihikun Dec 27, 2023
3f9322f
Create bme280test.ino
nihinihikun Dec 28, 2023
6ffb118
mcp3421とBME280統合
nihinihikun Dec 28, 2023
c1504fd
Create nose1.ino
nihinihikun Dec 28, 2023
2807d40
overruntest
nihinihikun Dec 29, 2023
baac4f9
Update arduino_ci.yml
771-8bit Dec 30, 2023
918a4f8
Update arduino_ci.yml
771-8bit Dec 30, 2023
68883fb
Update arduino_ci.yml
771-8bit Dec 30, 2023
1861f6e
Update arduino_ci.yml
771-8bit Dec 30, 2023
5e1f8e0
ファイル整理
nihinihikun Dec 31, 2023
9f18972
add status check
nihinihikun Jan 3, 2024
cc9d769
delete missing spaces
nihinihikun Jan 13, 2024
b7cf0ff
delete extra variables
nihinihikun Jan 13, 2024
0df9e7f
Update arduino_ci.yml
771-8bit Jan 13, 2024
e4688e0
Update arduino_ci.yml
771-8bit Jan 13, 2024
5c8b4d6
Update arduino_ci.yml
771-8bit Jan 13, 2024
0fced30
Merge branch 'main' into nose_software1
771-8bit Jan 13, 2024
a400766
Update arduino_ci.yml
771-8bit Jan 13, 2024
30499e9
Merge branch 'nose_software1' of https://github.com/core-rocket/24th-…
771-8bit Jan 13, 2024
2ef5251
Merge branch 'main' into nose_software1
771-8bit Jan 13, 2024
1884bef
Update arduino_ci.yml
771-8bit Jan 13, 2024
5886f89
delete Nose Build CI
771-8bit Jan 13, 2024
f13216a
modify C-style castings
nihinihikun Jan 13, 2024
ef97a3f
Merge branch 'nose_software1' of https://github.com/core-rocket/24th-…
nihinihikun Jan 13, 2024
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
16 changes: 15 additions & 1 deletion .github/workflows/arduino_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,17 @@ jobs:
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
flags: --linelength=50 # Optional
flags: --extensions=h,hpp,c,cpp,cc,cu,hh,ipp,ino
filter: "-readability/braces\
,-whitespace/braces\
,-whitespace/comments\
,-whitespace/indent\
,-whitespace/newline\
,-whitespace/operators\
,-whitespace/parens\
,-whitespace/tab\
,-whitespace/line_length\
,-build/header_guard\
" # Optional

build:
Expand All @@ -108,6 +111,9 @@ jobs:
version: latest
- name: Adafruit BNO055
version: latest
- name: MCP342x
version: latest
- source-url: https://github.com/core-rocket/CCP.git

strategy:
fail-fast: false
Expand All @@ -129,6 +135,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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
139 changes: 139 additions & 0 deletions Nose/Nose.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#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

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() {
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);
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;
}
#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)) {
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;
default:
break;
}
#endif
}

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

void DevideBytes(int32_t* _result, char* bytes) {
bytes[2] = (char)(*_result & 0xFF);
nihinihikun marked this conversation as resolved.
Show resolved Hide resolved
bytes[1] = (char)((*_result >> 8) & 0xFF);
nihinihikun marked this conversation as resolved.
Show resolved Hide resolved
bytes[0] = (char)((*_result >> 16) & 0xFF);
nihinihikun marked this conversation as resolved.
Show resolved Hide resolved
}

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 = (double)(outputcode)*lsb / pga;
nihinihikun marked this conversation as resolved.
Show resolved Hide resolved
} else { //負の値
outputcode = ((~outputcode) & 0x01FFFF) + 1; //2の補数
*voltage = -(double)(outputcode)*lsb / pga;
nihinihikun marked this conversation as resolved.
Show resolved Hide resolved
}
}

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;
}
nihinihikun marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
59 changes: 59 additions & 0 deletions docs/Nose/softwarememo.ipynb
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
}
48 changes: 48 additions & 0 deletions test/Nose/BME_high_rate/BME_high_rate.ino
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;

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() {
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();
}
78 changes: 78 additions & 0 deletions test/Nose/BME_mcp3421/BME_mcp3421.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <MCP342X.h>

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme;
MCP342X myADC;

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() {
printValues();

static int32_t result;
byte bytes[4];
myADC.startConversion();
myADC.getResult(&result);
ConvertToVoltage(&result, &voltage);
Serial.print("voltage:");
Serial.println(voltage, 10);
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) {
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);
nihinihikun marked this conversation as resolved.
Show resolved Hide resolved
bytes[0] = (char)((*_result >> 24) & 0xFF); //ライブラリの関数内で8bit右シフトしたときに発生したものなので無視
nihinihikun marked this conversation as resolved.
Show resolved Hide resolved
double pga = 1;
double lsb = 2 * 2.048 / pow(2, 18);

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;
nihinihikun marked this conversation as resolved.
Show resolved Hide resolved
} else { //負の値
outputcode = ((~outputcode) & 0x01FFFF) + 1; //2の補数
*voltage = -(double)(outputcode)*lsb / pga;
nihinihikun marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading
Loading