Teensy 3.2 Canbus - Which FlexCan do I use?

Status
Not open for further replies.

Rezo

Well-known member
Hi all,

Ove the last couple of months (on and off) I've been developing a project around OBD/UDS canbus based data display for my car (MQB VW)
I started off with an Arduino Uno and an Elecfreaks Canbus shield as well as an I2c OLED display (SH1106) and later on an SPI (SSD1351) RGB OLED.
The Uno is a little slow to say the least - as I am requesting and displaying 6-10 PID's at a time and I need a high sample rate and display rate to display realtime engine data.

I decided to try out the Teensy 3.2, being that it is a lot faster than the Uno, and has built in Can capabilities.
I purchased a few TJA1050 transceivers, hooked them up to the Teensy with a 5v supply (via USB) and tried out SK Pang's OBD sketch (https://github.com/skpang/Teensy_CAN-Bus_ECU_reader) using Collin80's FlexCan library - but it was not picking up anything at 500KBs (where the Uno was).

I did a lot of research and every time it came to the 3.2 and canbus, Collin's fork of FlexCan was suggested.
I stumbled across this article (https://ironsource.com/streaming-can-bus-data-with-teensy/) and tried it out (with the TJA in place as well as without) but still - nothing in the Teensy's serial monitor.

I thought it might be a defective TJA, so I tried the other. All with the same result.

I was hoping someone could direct me to the right FlexCan library for the 3.2

Which one should be used?
Techtop
Collin80
tonton
Pawelsky


Thanks
David
 
Last edited:
So I got my Teensy to read the message transmitted from the Uno ("hello" over can every second)
I had my Can Tx/Rx mixed up between the T3.2 and the TJA1050, and I added a 120ohm resistor between CANH and CANL.


I'm just concerned with one thing, the CanRx led (right) I hooked up flashes upon every receive from the Uno, but my Can Tx led (left) stays on.
I get 3,3v between Tx (pin3) and Gnd
IMG_0223.jpg

Is this something to worry about?

Here is the code running on the Teensy (Collin80 FlexCan library)
Code:
/*
 Authors:	Eric Desgranges
 Licensed under the GNU General Public License v3.0
*/

#include <FlexCAN.h>

// Teensy 2.0 has the LED on pin 11
// Teensy++ 2.0 has the LED on pin 6
// Teensy 3.x / Teensy LC have the LED on pin 13
const int ledPin = 13;

// -------------------------------------------------------------
static void hexDump(uint8_t dumpLen, uint8_t *bytePtr)
{
	uint8_t hex[17] = "0123456789abcdef";
	uint8_t working;
	while (dumpLen--) {
		working = *bytePtr++;
		Serial.write(hex[working >> 4]);
		Serial.write(hex[working & 15]);
	}
	Serial.write('\r');
	Serial.write('\n');
}

// -------------------------------------------------------------
void setup(void)
{
	pinMode(ledPin, OUTPUT); digitalWrite(ledPin, HIGH); delay(200); digitalWrite(ledPin, LOW);    // Blink once!
	Can0.begin();
	Serial.println(F("Hello Teensy E85!"));
}

// -------------------------------------------------------------
void loop(void)
{
	CAN_message_t rxMsg;
	while (Can0.available())
	{
		Can0.read(rxMsg);
		Serial.print("CAN BUS: "); hexDump(8, rxMsg.buf);
	}
}
 
Last edited:
No one? No insight all all?
Quite disappointing, I thought there would be a bit more support on this forum than others.
 
The TX normally sits high unless theres another node transmitting on the bus. Not everyone is familiar with the hardware, i myself am more into the software part of it
 
Hi David,

I'm still kind of going through the same issue of "which FlexCAN_Library do I use". I count over 100 forks of FlexCAN_Library. The up-side is that there are many versions suited for different purposes, and likely one that is perfect for you. The down-side is that you need to find it!

I'm new to Teensy, but am experienced with CAN firmware for marine applications.

It seems that anytime someone needs to tweak it for their own application, they make a new fork. I think this is especially the case if they want to control their own version, so that it works properly with another library that uses it. This is the case for Timo's NMEA2000 library; he has his own fork of the FlexCAN_Library with fixes needed for the NMEA2000 protocol which is layered over CAN protocol.

My advice to you is to use the FlexCAN_Library that is being used by the other libraries (if any) that you plan to use. If someone is doing project similar to yours, find out which library they are using. Teachop, pawelsky, and collin80 are definitely the most popular forks, but you mention tonton81, which seems obscure. His profile picture makes it obvious that he is working with automotive ECU's... I'll bet his FlexCAN_Library fork is the one you should try...

Andrew
 
It has nothing to do with my profile picture, no need to judge me based on a picture of the work i did on my car... Why is it obscure? Just because I modified my car makes me incapable of writing a library for general canbus development? I'll be sure not to post pictures of cats on my profile picture, wouldn't want people to think I am a crazy cat lady............ ;)
 
It has nothing to do with my profile picture, no need to judge me based on a picture of the work i did on my car... Why is it obscure? Just because I modified my car makes me incapable of writing a library for general canbus development? I'll be sure not to post pictures of cats on my profile picture, wouldn't want people to think I am a crazy cat lady............ ;)

@tonton81 - Your car work was fun watching before we worked together - all it takes is a good reason to work with something to make it work. In your case you have a good history of a few good projects for Teensy!

The latest RANDOM fork - starting in T4 Beta - was to make a working CAN library for T4's CAN FD and CAN 2. Didn't somebody note it was the ONLY CAN FD implementation for Arduino?

... @tonton81 - find a good image for your avatar … it makes it easier to spot your posts - even a cat would be cool - too many DOGS on here :) @KurtE and @mjs513 :)
 
It has nothing to do with my profile picture, no need to judge me based on a picture of the work i did on my car... Why is it obscure? Just because I modified my car makes me incapable of writing a library for general canbus development? I'll be sure not to post pictures of cats on my profile picture, wouldn't want people to think I am a crazy cat lady............ ;)

Rezo is asking for help with the same thing I am sorting through right now, so I've simply offered my speculations. Maybe obscure isn't the right word, but I use it because the other three forks he mentioned have spawned all the others... Obviously CAN is CAN. I'm suggesting he use yours because I'm presuming there are other libraries using it for similar applications (for instance maybe the default baud-rate is different). You should take it as a compliment.

I'm new here; please don't scare me away!
 
Rezo is asking for help with the same thing I am sorting through right now, so I've simply offered my speculations. Maybe obscure isn't the right word, but I use it because the other three forks he mentioned have spawned all the others... Obviously CAN is CAN. I'm suggesting he use yours because I'm presuming there are other libraries using it for similar applications (for instance maybe the default baud-rate is different). You should take it as a compliment.

I'm new here; please don't scare me away!

Nothing to be scared of here :) … Post your issue details … - if they overlap it might provide a missing detail.

Indeed starting with the @tonton81 library to see if it goes better seems right. With active development on that now - setting up a test might work - or resolving an issue if there is something.
 
I have successfully read the can bus on a VW engine using collin80's flex can example code. The only thing I am aware of is making sure you don't use the default flexcan library that comes with the teensduino software.
 
I have successfully read the can bus on a VW engine using collin80's flex can example code. The only thing I am aware of is making sure you don't use the default flexcan library that comes with the teensduino software.

can you post the example code pls
 
Finally - I have also had success with Collin80’s fork reading canbus data from my Golf GTI.
I built a sketch a while ago to pull standard and custom VW PID’s and I’m now adapting it to the FlexCan library.

Coupled with a 2.8” TFT display (ILI9341) I will be using this as a static can display in my car.
I can share code once I have a stable prototype working.
 
Here's what I used. Bear in mind that I had tapped into the can lines feeding the dash so did not need to send a request to the can gateway to start receiving data. I was also specifically looking for byte 1 in 0x288.

Code:
// -------------------------------------------------------------
// Development sketch to read VW marine can bus and filter relevant data
// using polling
//
// by Collin Kidder, Based on CANTest by Pawelsky (based on CANtest by teachop)
//
// This sketch uses interrupt driven Rx. Rx frames
// are internally saved to a software buffer by the interrupt handler.
//

#include <FlexCAN.h>

//#ifndef __MK66FX1M0__
//  #error "Teensy 3.6 with dual CAN bus is required to run this example"
//#endif

static CAN_message_t msg;
static uint8_t hex[17] = "0123456789abcdef";



/*might need int not uint8_t
uint8_t coolant; //unsigned integer coolant temp
uint16_t rpm; //unsigned integer rpm
uint8_t boost; //unsigned integer boost pressure
uint8_t iat; //unsigned integer intake air temp*/

// -------------------------------------------------------------
void setup(void)
{
  delay(1000);
  Serial.println(F("Hello Teensy 3.6 dual CAN Test."));
 
  Can0.begin(500000); //set baud. Change to Can1 for use on T3.6

  Can0.setListenOnly (true); //hopefully set listen only mode. Set after begin()
  
  //if using enable pins on a transceiver they need to be set on
  //pinMode(2, OUTPUT);
  //pinMode(35, OUTPUT);

  //digitalWrite(2, HIGH);
  //digitalWrite(35, HIGH);
}

// -------------------------------------------------------------
void loop(void)
{
  CAN_message_t inMsg;
  while (Can0.available()) 
  {
    Can0.read(inMsg); //read message into inMsg
    if (inMsg.id == 0x288)
    {
    Serial.print("CAN bus 0: "); 
    Serial.print(inMsg.id, HEX);
    Serial.print(", ");
    Serial.print (inMsg.buf[1], HEX);
    Serial.write('\r');
    Serial.write('\n');
    }
  }
 }
 
Status
Not open for further replies.
Back
Top