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

圧力測定基板追加 #24

Merged
merged 6 commits into from
Mar 19, 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
10 changes: 10 additions & 0 deletions .github/workflows/arduino_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ jobs:
version: latest
- name: Adafruit BNO055
version: latest
- name: Adafruit LPS35HW
version: latest
- source-url: https://github.com/uChip/MCP342X.git
- source-url: https://github.com/core-rocket/CCP.git
- source-url: https://github.com/coryjfowler/MCP_CAN_lib.git
Expand Down Expand Up @@ -145,6 +147,14 @@ jobs:
vendor: rp2040
arch: rp2040
name: seeed_xiao_rp2040

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

include:
- code:
Expand Down
58 changes: 58 additions & 0 deletions Pressure/Pressure.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <SPI.h>
#include <string.h>
#include <CCP_MCP2515.h>
#include <Adafruit_LPS35HW.h>

Adafruit_LPS35HW lps35hw = Adafruit_LPS35HW();

#define CAN_INT D6
#define CAN_CS D7

// CAN
CCP_MCP2515 CCP(CAN_CS, CAN_INT);
char msgString[128];
char str_buf[7]; // 6+\0

void setup() {
delay(500);
Serial.begin(115200);
pinMode(CAN_CS, OUTPUT);
pinMode(CAN_INT, INPUT);
digitalWrite(CAN_CS, HIGH);

// CAN
CCP.begin();

while (!lps35hw.begin_I2C(0x5C)) {
//if (!lps35hw.begin_SPI(LPS_CS)) {
//if (!lps35hw.begin_SPI(LPS_CS, LPS_SCK, LPS_MISO, LPS_MOSI)) {
Serial.println("Couldn't find LPS35HW chip");
delay(10);
}
delay(10);
lps35hw.setDataRate(LPS35HW_RATE_75_HZ);
}

void loop() {
static uint32_t time = 0;
if (millis() - time >= 10) {
time = millis();
CCP.float_to_device(CCP_surface_pressure1_pressure_pa, lps35hw.readPressure());
}

if (!digitalRead(CAN_INT)) // データ受信確認
{
CCP.read_device();
if (CCP.id < 0x40) {
CCP.string(str_buf, 7);
sprintf(msgString, "%d,ID,%03x,time,%d000,string,%s,,,,", millis(), CCP.id, CCP.time16(), str_buf);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Never use sprintf. Use snprintf instead. [runtime/printf] [5]

} else if (CCP.id < 0x80) {
sprintf(msgString, "%d,ID,%03x,time,%lu,uint32,%lu,,,,", millis(), CCP.id, CCP.time32(), CCP.data_uint32());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Never use sprintf. Use snprintf instead. [runtime/printf] [5]

} else if (CCP.id < 0xC0) {
sprintf(msgString, "%d,ID,%03x,time,%lu,float,%8.2f,,,,", millis(), CCP.id, CCP.time32(), CCP.data_float());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Never use sprintf. Use snprintf instead. [runtime/printf] [5]

} else {
sprintf(msgString, "%d,ID,%03x,time,%d000,fp16_0,%8.2f,fp16_1,%8.2f,fp16_2,%8.2f", millis(), CCP.id, CCP.time16(), CCP.data_fp16_0(), CCP.data_fp16_1(), CCP.data_fp16_2());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Never use sprintf. Use snprintf instead. [runtime/printf] [5]

}
Serial.println(msgString);
}
}
51 changes: 51 additions & 0 deletions test/pressure_board_CAN_inspector/pressure_board_CAN_inspector.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <SPI.h>
#include <string.h>
#include <CCP_MCP2515.h>

#define CAN_INT D6
#define CAN_CS D7

// CAN
CCP_MCP2515 CCP(CAN_CS, CAN_INT);

// Other
char msgString[128];
char str_buf[7]; // 6+\0

void setup()
{
delay(500);
Serial.begin(115200);
pinMode(CAN_CS, OUTPUT);
pinMode(CAN_INT, INPUT);
digitalWrite(CAN_CS, HIGH);

// CAN
CCP.begin();
}

void loop()
{
if (!digitalRead(CAN_INT)) // データ受信確認
{
CCP.read_device();
if (CCP.id < 0x40)
{
CCP.string(str_buf, 7);
sprintf(msgString, "%d,ID,%03x,time,%d000,string,%s,,,,", millis(), CCP.id, CCP.time16(), str_buf);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Never use sprintf. Use snprintf instead. [runtime/printf] [5]

}
else if (CCP.id < 0x80)
{
sprintf(msgString, "%d,ID,%03x,time,%lu,uint32,%lu,,,,", millis(), CCP.id, CCP.time32(), CCP.data_uint32());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Never use sprintf. Use snprintf instead. [runtime/printf] [5]

}
else if (CCP.id < 0xC0)
{
sprintf(msgString, "%d,ID,%03x,time,%lu,float,%8.2f,,,,", millis(), CCP.id, CCP.time32(), CCP.data_float());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Never use sprintf. Use snprintf instead. [runtime/printf] [5]

}
else
{
sprintf(msgString, "%d,ID,%03x,time,%d000,fp16_0,%8.2f,fp16_1,%8.2f,fp16_2,%8.2f", millis(), CCP.id, CCP.time16(), CCP.data_fp16_0(), CCP.data_fp16_1(), CCP.data_fp16_2());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Never use sprintf. Use snprintf instead. [runtime/printf] [5]

}
Serial.println(msgString);
}
}
Loading