Hello,
I am trying to capture vehicle speed through CAN, however Can0 object is unavailable.
Hardware:
Software & OS:
Pictures:
From web(OBDII to DB9):
Code:
Supply voltage to WaveShare CAN is 3.3V. Voltage between Can High and ground is also 3.3V. Same with CAN Low and ground. I have checked the voltages at pin3 and pin4 with respect to ground as well. They also read 3.3 V.
Not really sure what I am missing here. Any help is appreciated!!
--Mayo
I am trying to capture vehicle speed through CAN, however Can0 object is unavailable.
Hardware:
- Teensy 3.6
- WaveShare CAN
- Teensy Audio Shield
- DB9 Connector
Software & OS:
- Windows 10
- Arduino 1.8.7
Pictures:
From web(OBDII to DB9):
Code:
Code:
#include <FlexCAN.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
//#include <SD.h>
#include <SerialFlash.h>
AudioControlSGTL5000 sgtl5000_1;
float maxVol = 0.4;
float wheel_speed[] = {0.0, 0.0, 0.0, 0.0}; //LF, RF, LR, RR
class ExampleClass : public CANListener
{
public:
void printFrame(CAN_message_t &frame, int mailbox);
void gotFrame(CAN_message_t &frame, int mailbox); //overrides the parent version so we can actually do something
void updateSnd(CAN_message_t &frame, int mailbox);
};
void ExampleClass::printFrame(CAN_message_t &frame, int mailbox)
{
Serial.print("ID: ");
Serial.print(frame.id, HEX);
Serial.print(frame.id);
Serial.print(" Data: ");
for (int c = 0; c < frame.len; c++)
{
Serial.print(frame.buf[c], BIN);
Serial.write(' ');
}
Serial.write('\r');
Serial.write('\n');
}
void ExampleClass::gotFrame(CAN_message_t &frame, int mailbox)
{
printFrame(frame, mailbox);
updateSnd(frame, mailbox);
}
void ExampleClass::updateSnd(CAN_message_t &frame, int mailbox)
{
if (frame.id == 840) //wheel speeds 1
{
//parse wheel speed here//
wheel_speed[0] = ((frame.buf[1]) + (frame.buf[0] * 256)) * 0.03125;
wheel_speed[1] = ((frame.buf[3]) + (frame.buf[2] * 256)) * 0.03125;
//End Parse Wheel Speed//
}
if (frame.id == 842) //wheel speeds 2
{
//parse wheel speed here//
wheel_speed[2] = ((frame.buf[1]) + (frame.buf[0] * 256)) * 0.03125;
wheel_speed[3] = ((frame.buf[3]) + (frame.buf[2] * 256)) * 0.03125;
//End Parse Wheel Speed//
}
}
ExampleClass exampleClass;
void setup() {
// put your setup code here, to run once:
sgtl5000_1.enable();
sgtl5000_1.volume(maxVol);
Serial.begin(115200); //115200 bits/second
Can0.begin(500000); // Start CAN bus
//if using enable pins on a transceiver they need to be set on
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
Can0.attachObj(&exampleClass); //CAN bus handler
exampleClass.attachGeneralHandler();
if (Can0.available())
{
Serial.print("Successful connection to CAN");
}
else
{
Serial.println("CAN connection unsuccessful");
}
}
void loop() {
// put your main code here, to run repeatedly:
// Serial.print("Wheel Speed 0: ");
// Serial.println(wheel_speed[0]);
//
// Serial.print("Wheel Speed 1: ");
// Serial.println(wheel_speed[1]);
//
// Serial.print("Wheel Speed 2: ");
// Serial.println(wheel_speed[2]);
//
// Serial.print("Wheel Speed 3: ");
// Serial.println(wheel_speed[3]);
}
Supply voltage to WaveShare CAN is 3.3V. Voltage between Can High and ground is also 3.3V. Same with CAN Low and ground. I have checked the voltages at pin3 and pin4 with respect to ground as well. They also read 3.3 V.
Not really sure what I am missing here. Any help is appreciated!!
--Mayo