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.
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.
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!
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.
Hey ! I just want to say I made an account just to reply to your thread. Your work is amazing !
Would you happen to know if it works with other ECUs that have CANbus ? I'm referring in my case to ME221 ( motorsport electronics )
CANChecked is available for this ECU , but I feel like tinkering with it rather than buying such a solution.
Thanks and I hope u managed to move in and eveyrhting's good on your end
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.
Hey ! I just want to say I made an account just to reply to your thread. Your work is amazing !
Would you happen to know if it works with other ECUs that have CANbus ? I'm referring in my case to ME221 ( motorsport electronics )
CANChecked is available for this ECU , but I feel like tinkering with it rather than buying such a solution.
Thanks and I hope u managed to move in and eveyrhting's good on your end
sorry, really struggling at the moment life wise. The poor weather doesn't help lol. Yes this will work with any ecu that can give you Canbus outputs, however each company/ecu has its own sort of canbus language so you would need to find a library that can decipher that language similar to the one I found that can decipher the ms3 canbus language for me.
I promise I will get to testing this! My health dictates that I fly to and from a nearby city almost every weekend at the moment so spare time is at a minimum. On top of that it's winter here and I do not have a heated garage. Need me a Mr. Buddy heater!
heat pump for my garage and it was one of the best purchases I made. As long as you have access to outside air it'll heat AND cool your garage, and it's about $140 cheaper now than when I bought it
I just wrapped up my CAN project, I put it on GitHub here. There's probably not a ton of overlap, but feel free to steal whatever helps!
Woa! Sweet thanks! A heat pump sounds fantastic. I'll take a look at your project, CAN stuff is awesome, especially when we can build the bus from the ground up as opposed to diving into a messy can system on newer vehicles.
I have been testing the gauge in car all week. Something has gone awry in my setup somewhere. Doesnt look like I'm picking up any can data from the bus. I know my spartan3 wideband controller and MS3x are successfully talking over the bus so we have good setup there. Going to try some super basic codes chat GPT suggested to see if I can pick up ANYTHING on the bus using the teensy.
Testing successful!!!! I will post up my full tuner studio settings list as well as update my github with a zip you can simply download, unzip, flash to the teensy and go!
Fixed the small display gremlins and uploaded CANGauge1.2.zip to the github. If you would like to make this gauge yourself you can download and unzip the file, drop it into your "Arduino" folder from your arduino IDE, open the ui.ino file in arduino ide, compile it and upload it to your teensy and youll be ready to rock. Now the question is how soon do I get around to installing it. It's the middle of autocross/track season here in Ohio so the car is seeing heavy usage. I was able to squeeze in this testing period with the car because of a lul in the race schedule. I plan on making a complete youtube video, showing the hardware, software download and installation, and install to the car. That way literally anyone can have their own can gauge for a fraction of the price. If anyone wants to jump ahead of me, I linked an instructables earlier in this thread for digital gauges, I am going to be connecting the power, grounds and illumination of the teensy in the same way they did with a 5v buck converter that is listed in the bill of materials for this build. The switch screen wire will be simply sent to the momentary button I have in the materials and then sent to ground. Optionally, like the instructables, you can add a usb extender to outside the cluster. That will allow you to still plug into the teensy while it is in the car, just note once the teensy is wired into the car it will be receiving 5V from a 12V source through a buck converter. Plugging in the teensy to a laptop while the car is on and the 12v source is active, WILL FRY YOUR TEENSY. To safegaurd against this I think I am going to strip open the microusb extenders I listed in the materials and snip the power cable out, that way when you plug in your laptop to the extender the 12v from your laptops usb is stopped in its tracks and will never reach the teensy.
****Edit, already on version 1.3, if you're seeing this at a later date make sure to download latest version. I made the AFRs and Boost pressure refresh much faster in 1.3.
video. The dimmer works, I need to work out some kinks with the screen switching button but other than that it's fully operational.
I did end up cutting the RED wire in the microusb extension and it works flawlessly to keep my laptop from accidentally powering the teensy the same time the cars 12v system is. To flash new code to the controller I'll have to have the teensy plugged into the laptop for comms and the ignition on for power to the controller. Bulletproof. Gonna button her up later this week when it's not so blistering hot.
Forgot to update here! Everything's in. I could not be more elated. I can't believe I got it all to work haha. Really thought this project was a lost cause initially and that I'd just end up buying a canchecked gauge for $283849438. Here are some pics and a TikTok I made to summarize the build.
https://www.tiktok.com/t/ZTMFX91XV/