-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from core-rocket/pressure_can
圧力測定基板追加
- Loading branch information
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} else if (CCP.id < 0x80) { | ||
sprintf(msgString, "%d,ID,%03x,time,%lu,uint32,%lu,,,,", millis(), CCP.id, CCP.time32(), CCP.data_uint32()); | ||
} else if (CCP.id < 0xC0) { | ||
sprintf(msgString, "%d,ID,%03x,time,%lu,float,%8.2f,,,,", millis(), CCP.id, CCP.time32(), CCP.data_float()); | ||
} 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()); | ||
} | ||
Serial.println(msgString); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
test/pressure_board_CAN_inspector/pressure_board_CAN_inspector.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
else if (CCP.id < 0x80) | ||
{ | ||
sprintf(msgString, "%d,ID,%03x,time,%lu,uint32,%lu,,,,", millis(), CCP.id, CCP.time32(), CCP.data_uint32()); | ||
} | ||
else if (CCP.id < 0xC0) | ||
{ | ||
sprintf(msgString, "%d,ID,%03x,time,%lu,float,%8.2f,,,,", millis(), CCP.id, CCP.time32(), CCP.data_float()); | ||
} | ||
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()); | ||
} | ||
Serial.println(msgString); | ||
} | ||
} |