Teensy 3.1 and CAN Bus

Code Problem

After looking around there didn't seem to be a good logging sketch out of the box, so I modified the example that comes with Flexcan and came up with this:

Source Code:
http://github.com/finderman2/Teensy-CAN-Logger/tree/master

By default, the file format it outputs is designed to work with Collin Kidder's excellent software, SavvyCAN available for Mac, Win, and Linux. If you want to change it to output different information or in a different order just change the lines in the if statement.

Can anyone tell me what I might be doing wrong here? I'm trying to use this code, but I keep getting a series of error messages. I am pretty new to programming, but from what I take from the error message, the problem is related to the SD library?
 

Attachments

  • Code Error.txt
    5.6 KB · Views: 205
Looks like your copy of the SD library, in C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD, has somehow become corrupted.

Please try the easiest thing first, quit Arduino and just reinstall Teensyduino. That should write a fresh copy of all those files. Hopefully it will make this error magically go away.

If not, use File > Preferences to turn on verbose info while compiling. Then try again and post the errors here. If this is something deeper than a corrupted file, hopefully the extra verbose info will allow us to figure out what's going wrong.
 
I first tried to reinstall Teensyduino, but to no avail. Attached is the verbose information. I noticed at the end of the error messages where it shows what libraries it is using it said...

Using library Metro in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Metro (legacy)
Using library FlexCAN in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\FlexCAN (legacy)
Using library SD at version 1.0.8 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD
Using library SdFat in folder: C:\Program Files (x86)\Arduino\libraries\SdFat (legacy)

There is no pre-processor directive for the SdFat library in the code. I removed SdFat from the arduino library (I had used it for a different CAN logger), and now it compiles.

Using library Metro in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Metro (legacy)
Using library FlexCAN in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\FlexCAN (legacy)
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI
Using library SD at version 1.0.8 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD

I am still curious as to why its not using the Adafruit SD library that the code comment next to the SD.h pre-processor directive says is to be used. I added it to the arduino library folder, but it still uses the SD library that came with Teensyduino instead. Can Arduino detect which library it needs if there are multiple SD.h files?
 

Attachments

  • Verbose Code Error.txt
    42.4 KB · Views: 168
Hi,

I am looking to build a CAN network for automation using the Teensy 3.2s. The plan is to have roughly 20 to 30 nodes of which one will be a windows PC. Some are sensors others are motors and pumps. To deal with the complexity of the system, I want to implementing a higher layer implementation of the CAN standard such as CANopen or DeviceNet. https://en.wikipedia.org/wiki/CAN_bus#Higher_layer_implementations

I'm wondering if one of these higher layer implementations are overkill. The standards look pretty daunting to code up myself. I'm hoping to use open source versions of the implementation such as https://github.com/CANopenNode/CANopenNode. Ideally I can find one that is written in c++.

I would appreciate any advice people with more experience can provide on building a network with one of these higher layer implementations.

So far thanks to teachop's FlexCan library I have been able to create a basic CAN Network with three Teensy 3.2s and a PEAK USB to CAN bus converter connected a Windows PC. I can send, receive in filter packets with the Teensy 3.2s and do the same using the PEAK API on the PC side. The network mostly turns on and off leds on pin13 on the respective nodes.

Sincerely,


Ken
 
Hi,
A while back ( https://forum.pjrc.com/threads/24720-Teensy-3-1-and-CAN-Bus?p=44082&viewfull=1#post44082 ) there was some discussion about adding some other CANbus speeds that seems to have been dropped.

I would like to com with the GM single wire can bus (SWCAN) on my Chevy SparkEV. I'm using a Freescale MC33897 single wire CAN transceiver with Collins Kidders due_can software on a Arduino due board with a custom shield and would like to use Teensy 3.2 instead. I tried to add in the function above but get a bunch of define errors. Looks like it's missing a header file. I have not contacted the author, uTasker yet.

My reason for posting here though, is that I haven't seen much discussion about SWCAN. SWCAN seems far more applicable to what people do with the Teensy than regular CAN. With SWCAN you can have a remote node sitting on a 5-26V bus that is 'sleeping @ 60uA'. When a 'WakeUp' message is sent on the bus the transceiver can wake up the teensy to check if it is interested in the ID and then the Teensy can go back to sleep or do whatever. This isn't possible with differential CAN, infact GM uses the SWCAN to wake up it's high speed network in many cases.

On the SparkEV the SWCAN is what all the human interface uses, i.e. door switch, seat sensors, shift position, radio and steering column switches ect. Lots of playing to be had.


Did you manage to find an answer? I too am looking for a solution to use single wire CAN (GMLAN) with Teensy 3.2 in a 2009 Saab 9-3 car, which comes with GMLAN. If you did manage to find a solution I would be interested in knowing.
 
Hi all and thsnks for help.i need help about this :i need to send two different can bus message with different id in 500kbps , i find some examples but i try without success can you help about this.thanks for help.
 
Hello LogicLow thanks for responce,i use mcp2551 .i able to send and receive can bus message in 500kbps i test it with can bus analyzer .my problem is i try to send two message but i doent know how (because all examples send only one and without diferrent id )for example i need to send two message .first with id 0x 222 and second with id 0x555 and the message for first is 0x12 0x13 0x14 0x15 0x16 0x17 0x16 0x18 and second message is 0x19 0x12 0x15 0x11 0x12 0x33 0x23 0x55.thanks for support.
 
Hello LogicLow thanks for responce,i use mcp2551 .i able to send and receive can bus message in 500kbps i test it with can bus analyzer .my problem is i try to send two message but i doent know how (because all examples send only one and without diferrent id )for example i need to send two message .first with id 0x 222 and second with id 0x555 and the message for first is 0x12 0x13 0x14 0x15 0x16 0x17 0x16 0x18 and second message is 0x19 0x12 0x15 0x11 0x12 0x33 0x23 0x55.thanks for support.

Good to hear you can receive and send!

Right, how about you first post in what you have so far in your coding so that I an help nudge you in the right direction :)
 
Is it possible to run two transceivers on ONE single teensy?

I want to filter out certain messages between a device and the "core CAN bus", so I need one transceiver to connect to the device and the other one to connect to the "core bus". Any ideas?
 
Has anyone found a source for a compatible Micro SD Socket that Pawelsky's Teensy 3.1 CAN + MicroSD shield is using?
( Suntech ST-TF-003A or Adam Tech MCSP-08-C-SG)

If I leave the SD Socket off the shield, can I still run everything (obviously without logging to file)?

(I've searched Mouser pretty extensively and could not find anything with the same footprint)
 
Last edited:
In general I didn't have problems with the 230 chip, except one particular batch, which I've received twice from different sellers. It was labeled 42M and refused to work correctly.
I've got problems with SN65HVD230 batch 61M.
Looking with a oscilloscope at the VREF pin I can see that the output on VREF partially follows what comes from microcontroller on the D (TX) pin.
That is, instead of being steady VCC/2 like specified in datasheet, it jumps up and down in sync with the input data!

I've connected VREF to the VCC pin (directly! yes I know it sounds crazy), and suddenly it started working!
Possibly, it will work if you manage to feed a low-impendance VCC/2 to this pin (like using a external voltage regulator), but I haven't tried that.

Perhaps these are failed batches sold by garbage sellers, I've got mine from aliexpress.
 
Hi,

sorry for stupid questions. I have no experience with arduino but I would like to start with one OBD project. For a start I would like to control windows and switch parking sensors. My questions are:
Is it OK to use Teeny 3.2 with FlexCAN Library and do I need any CAN shield, for example (https://oshpark.com/shared_projects/VeJFD9qA)?
Or do you recommend Leonardo CAN bus (http://www.hobbytronics.co.uk/leonardo-canbus)?

In additional, I would also like to monitor some parameters on display (ride time, distance, speed, temperature) and open/close windows via Bluetooth.
Thanks for your answer.
 
Last edited:
I will have these shields coming in in a couple days.

TAipimP.jpg


OVDrZpi.jpg
 
Looks like we're going to need CAN.setTX(pin) and CAN.setRX(pin) in the FlexCAN library....
That could cause people trying to use any pin for CAN. I would rather think of some kind of CAN.setAlternativePins(alt) that would only allow to chose between alternative pin sets.


Regarding the CAN shields itself I would suggest to add a hole to the CAN pads so one could also use through hole connectors (pads are not mechanically strong).
 
I didn't do TH because the will be mounted with low profile headers and will sit directly on the (metal) SD slot, adding minimum height to the setup. I've never had pads tear off on me, although they probably won't take as much stress as the TH.
 
I didn't do TH because the will be mounted with low profile headers and will sit directly on the (metal) SD slot, adding minimum height to the setup. I've never had pads tear off on me, although they probably won't take as much stress as the TH.
I fully understand why you went for the pads and I do like the design, I was only suggesting adding TH (next to the pads) to make it more universal if you decide to share the design at some point (for those who would like to install the shield underneath on leave a bit more clearance when installed on top.

Regarding the alternative pin selection in the FlexCAN library I think I'll add extra parameters to the constructor (as it is actually the place where the pins are configured) rather than providing separate function for it. I guess it makes more sense that give the ability to change it on-the-fly with set methods.
 
We've got similar setNAME(pin) functions for hardware serial, I2C, SPI, and they're planned for audio. I'd really like to see FlexCAN use consistent functions.

Also on my todo list is looking into the possibility of a unified CAN base class API. Currently we have similar functionality but different APIs for Teensy, Arduino Due, MCP2551, and ChipKit. My hope is we can make all of the API compatible, so people can share Arduino sketches between them, and also to allow libraries for higher level protocols built on to of CAN to work without being coded to specific hardware.
 
Back
Top