ECUs and Tuning Discuss Engine Management, Tuning, & Programming

DIY CAN Gauge with Teensy 4.0

Thread Tools
 
Search this Thread
 
Old 06-17-2024, 04:17 PM
  #21  
Newb
Thread Starter
 
Eli_Swer's Avatar
 
Join Date: Oct 2021
Posts: 41
Total Cats: 25
Default

Well, that was quick. Zipped my entire file structure called "CANGauge - Copy.zip". You should be able to unzip that, navigate to ui>libraries then go ahead and copy those into your libraries folder under your arduino folder. You can open up the ui.ino file in the arduino IDE and take a look or change anything you may want to, but otherwise it should compile and be able to be uploaded to your teensy 4.0. Note it will warn you about needing to update your libraries but DO NOT UPDATE THEM. Earlier in the thread I mentioned lvgl library stopped supporting squareline studio so the newest lvgl library will not work to run the UI, the older version must be used.
Eli_Swer is offline  
Old 06-19-2024, 04:53 AM
  #22  
Junior Member
 
Stoffl's Avatar
 
Join Date: May 2022
Posts: 105
Total Cats: 8
Cool

Originally Posted by Eli_Swer
4. CANbus Coding
Admittedly I have actually had this done for a while now I was just waiting to be able to dive into tuner studio and look at the CAN functionality for myself with my MS3x connected. This part is relatively simple thanks to a fella named mikey. Found his thread on msextra and it is brilliant. He built a library to be used alongside the flexCAN_T4 library to handle CAN comms over megasquirt and turn them into usable data. I am waiting on my CAN shield from tindie but it is as easy as dropping it on a pinned teensy 4.0 and soldering the pads to the pins. You run your CAN lines to one channel's Hi and Lo and your done.

There's also not a ton of coding to be done and if youre following along you likely wont have to change anything. Under Mikey's examples in the Github he links on his thread he has a broadcast only example, which is all we are looking to do, have the MS3x broadcast CAN info and allow us to bite off of it. The canMShandler function below is the operation portion of the example and it is very simple. CAN info is broadcasted from the megasquirt cyclicly in "groups" each group has an id number and a name. Once all the data has been sent out it begins sending data again from group 0. Earlier in the example (not shown, line 5) the finalId variable is set to the base id, plus 17. To understand this we need to be looking at some MS documentation found here. Section 2.1 is the field list for the advanced real time data broadcasting ID's for the MS3x. Mikey here is asking the program to pull values from the CANbus ater the broadcasting hits group 17, meaning all values from groups 0-17 are available for use. Looking at the field list, most values past group 17 are not neccesasry unless you would like an ethanol content read out like my display shows. In this case I needed to change my offset value from 17 to 47 since ethanol value is so far down the list. This is the basis for the code in my particular program and the entire code can be downloaded from my github linked above. In my code the canMShandler function just fetches and stores the values into a variable using "bCastMsg.'variable name'". These names can be found in that section 2.1 field list. Mikey does the same here but also prints them out. I use my variables to drive arc changes and display values on the UI itself. He also makes all the variables floats but I wanted nice whole numbers for my temps so I made those integers.

Mikey's^^

Mine^^

Also you need to make sure you download the FlexCAN_T4 library and Mikey's library into your UI's libraries folder.
Updated and, fingers crossed, final revision of the code can be found on the github. Also I will be working on trying to upload the full file structure to the github so it can be as easy as buying the teensy, downloading the file structure, uploading the UI, and installing in the car. Right now the easiest way to probably get this done is to download the Gauge2.spj and Gauge2.sll files, open them in squareline studio, create a UI with them and copy and paste the relevant code from my UI into your UI.
Another small tidbit is that in my code on line 68, it specifies that the code is to read CAN port 2 on the teensy so be mindful of that and which pads you have your CAN lines soldered to on the CAN shield.
Last thing, the startup animation became too confusing so I removed it entirely, maybe on a rainy day I will try to incorporate it back in. Testing soon! My CAN shield has made it to the states so its only a matter of time before it is at my door.

Great stuff.
Stoffl is offline  
Old 06-19-2024, 01:01 PM
  #23  
Newb
Thread Starter
 
Eli_Swer's Avatar
 
Join Date: Oct 2021
Posts: 41
Total Cats: 25
Default

Note: I will be making a YouTube video that shows
1. The connections from the teensy to the display
2. How to solder the canbus shield to the teensy
3. Downloading my file structure from the GitHub and uploading the program to the Teensy.
4. Installing the teensy and necessary hardware to the dash for power, dimming, and screen switching.
5. Final result!

Until then feel free to check out my YouTube channel, there's an intro video for my car uploaded. An easy oil temp sensor install for the ms3x is going up this Saturday!
Eli_Swer is offline  
Old Yesterday, 12:04 PM
  #24  
Newb
Thread Starter
 
Eli_Swer's Avatar
 
Join Date: Oct 2021
Posts: 41
Total Cats: 25
Default

It's been a while, I'm sorry, life has gotten crazy! I'm moving out this weekend but will try to get this gauge tested in the car next week. I've got high hopes. I only need to branch off the Bus and tie the leads to the teensy to get it tested. After I confirm its functionality I can pull the gauge cluster and hard wire it to the car.
Eli_Swer is offline  
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
shlammed
Fabulous Fabrication
170
09-26-2018 02:55 PM
Leveq
Media
0
11-17-2017 02:31 PM



Quick Reply: DIY CAN Gauge with Teensy 4.0



All times are GMT -4. The time now is 01:25 AM.