Skip to content

Commit

Permalink
TEST for RPM Pulse Sensing
Browse files Browse the repository at this point in the history
  • Loading branch information
WonITKorea committed Feb 2, 2024
1 parent ac14dfa commit f64918d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sketch": "code\\DAQ_System\\DAQ_System.ino",
"sketch": "code\\DAQ_System\\testPico\\testPico.ino",
"board": "rp2040:rp2040:rpipico",
"port": "COM18",
"output": "../build",
Expand Down
13 changes: 7 additions & 6 deletions code/DAQ_System/DAQ_System.ino
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ void setup()
// accel.setRange(ADXL345_RANGE_8_G);
// accel.setRange(ADXL345_RANGE_4_G);
accel.setRange(ADXL345_RANGE_2_G);
Serial.println("——————————————————————————————————————————————————————————————————————————————");
Serial.println("* SKIDAQ " + String(FW_Version) + " *");
Serial.println("* By Rick Spooner https://github.com/WonITKorea *");
Serial.println("* Based on Open-Ecu-Sim-OBD2-FW *");
Serial.println("* By Rick Spooner https://github.com/spoonieau *");
Serial.println("——————————————————————————————————————————————————————————————————————————————");
Serial.println("-----ADXL345 STATUS-----");
/* Display some basic information on this sensor */
displaySensorDetails();
Expand All @@ -244,12 +250,6 @@ void setup()
delay(3000);
digitalWrite(obled, LOW);
}
Serial.println("——————————————————————————————————————————————————————————————————————————————");
Serial.println("* SKIDAQ " + String(FW_Version) + " *");
Serial.println("* By Rick Spooner https://github.com/WonITKorea *");
Serial.println("* Based on Open-Ecu-Sim-OBD2-FW *");
Serial.println("* By Rick Spooner https://github.com/spoonieau *");
Serial.println("——————————————————————————————————————————————————————————————————————————————");
delay(3000);
}

Expand Down Expand Up @@ -326,6 +326,7 @@ byte mode9Supported0x00PID[8] = {0x06, 0x49, 0x00, 0x28, 0x28, 0x00, 0x00, 0x00}
// ——————————————————————————————————————————————————————————————————————————————
void loop()
{
Serial.printf("%d\n", RPulse.read());

////Build setting return msg
byte obd_Std_Msg[8] = {4, 65, 0x1C, (byte)(obd_Std)};
Expand Down
140 changes: 14 additions & 126 deletions code/DAQ_System/testPico/testPico.ino
Original file line number Diff line number Diff line change
@@ -1,133 +1,21 @@
/*!
* @file receiveInterrupt.ino
* @brief CAN-BUS Shield, receive data with interrupt mode when in interrupt mode,
* @n the data coming can't be too fast, must >20ms, or else you can use check mode
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author Arduinolibrary
* @maintainer [qsjhyy]([email protected])
* @version V1.0
* @date 2022-05-25
* @url https://github.com/DFRobot/DFRobot_MCP2515
*/
#include "DFRobot_MCP2515.h"
#include <ADCInput.h>

const int SPI_CS_PIN = 17;
DFRobot_MCP2515 CAN(SPI_CS_PIN); // Set CS pin
ADCInput RPulse(A0);
// For stereo/dual mikes, could use thi
// ADCInput(A0, A1);

unsigned char flagRecv = 0;
unsigned char len = 0;
unsigned char buf[8];
char str[20];
String BuildMessage = "";
void setup() {
Serial.begin(115200);

void setup()
{
Serial.begin(115200);
RPulse.begin(8000);

while (CAN.begin(CAN_500KBPS))
{ // init can bus : baudrate = 500k
Serial.println("DFROBOT's CAN BUS Shield init fail");
Serial.println("Please Init CAN BUS Shield again");
delay(3000);
}
Serial.println("DFROBOT's CAN BUS Shield init ok!\n");

attachInterrupt(20, MCP2515_ISR, FALLING); // start interrupt
}

void MCP2515_ISR()
{
flagRecv = 1;
while (1) {
Serial.printf("%d\n", RPulse.read());
// For stereo/dual mikes, use this
// Serial.printf("%d %d\n", mike.
}
}
#define INT32U unsigned long int
INT32U canId = 0x000;
unsigned char pidchk[8] = {2, 1, 0, 0, 0, 0, 0, 0};
unsigned char milClr[8] = {2, 1, 1, 0, 0, 0, 0, 0};
unsigned char coolTemp[8] = {2, 1, 5, 0, 0, 0, 0, 0};
unsigned char rpmm[8] = {2, 1, 12, 0, 0, 0, 0, 0};
unsigned char ambtemp[8] = {2, 1, 70, 0, 0, 0, 0, 0};
void loop()
{

char Order = Serial.read();
if (Order == '1')
{
CAN.sendMsgBuf(0x02, 0, 8, pidchk);
Order = 0;
}
else if (Order == '2')
{
CAN.sendMsgBuf(0x02, 0, 8, milClr);
Order = 0;
}
else if (Order == '3')
{
CAN.sendMsgBuf(0x02, 0, 8, coolTemp);
Order = 0;
}
else if (Order == '4')
{
CAN.sendMsgBuf(0x02, 0, 8, rpmm);
Order = 0;
}
else if (Order == '5')
{
CAN.sendMsgBuf(0x02, 0, 8, ambtemp);
Order = 0;
}
else if (Order == 0)
{
}
if (flagRecv)
{ // check if get data

flagRecv = 0; // clear flag

// iterate over all pending messages
// If either the bus is saturated or the MCU is busy,
// both RX buffers may be in use and after having read a single
// message, MCU does clear the corresponding IRQ conditon.
while (CAN_MSGAVAIL == CAN.checkReceive())
{
// read data, len: data length, buf: data buf
CAN.readMsgBuf(&len, buf);
canId = CAN.getCanId();
if (canId == 0x7E8)
{
if (buf[0] == 4 && buf[1] == 65)
{
switch (buf[2])
{
case 70:
Serial.print("Ambient Temperature: ");
Serial.println(buf[3]);
break;
case 63:
Serial.println("Status Cleared.");
break;
case 5:
Serial.print("Coolant Temperature: ");
Serial.println(buf[3], OCT);
break;
case 12:
Serial.print("TachoMeter: ");
Serial.println(buf[3], OCT);
break;

default:
break;
}
}
} else if (canId)
// print the data
for (int i = 0; i < len; i++)
{
BuildMessage = BuildMessage + buf[i] + ",";
}
Serial.println(BuildMessage);
BuildMessage = "";
Serial.println(" ");
}
}
void loop() {
/* Nothing here */
}

0 comments on commit f64918d

Please sign in to comment.