Sharing/Outputting GPS or Wheel speed to megasquirt

Discussions on CAN mapping for ECUs, sensors, PDMs, and more.
Post Reply
Canyonfive
Posts: 57
Joined: Mon Jan 29, 2018 11:20 pm

Sharing/Outputting GPS or Wheel speed to megasquirt

Post by Canyonfive »

Sharing/Outputting GPS or Wheel speed to megasquirt

Anyone done anything like this? I'm currently broadcasting from the Megasquirt to the Racecapture Pro, but I would like to send the GPS speed or wheel speed from sensors to the Megasquirt. (edit: The reason why I want to do this is because there aren't many inputs on the MegaSquirt itself. )

Outputting a square wave form from the GPIO would work too it's capable. (Edit: Spoiler its not possible)
Last edited by Canyonfive on Sat Oct 03, 2020 5:50 am, edited 2 times in total.

GTIspirit
Posts: 233
Joined: Wed Jan 09, 2013 11:20 am
Location: SE Michigan

Post by GTIspirit »


Canyonfive
Posts: 57
Joined: Mon Jan 29, 2018 11:20 pm

Re: Sharing/Outputting GPS speed to megasquirt

Post by Canyonfive »

Well... Yeah... As far as sending messages that the Megasquirt understands, I can now do that. The next challenge is to get the Megasquirt to allow me to write to Canvvs2 which I'll take up on the MSextra forum.

For those reading I did what was done in the other thread, but for testing I used fuel pressure.
Lua Script below

t1 = getChannel("FuelPress")
local msg = {t1}
txCAN(0 1918, 0, msg)

On the MegaSquirt
Image

and to make it something I could read I set CanAdc01 to a sensor input.

Image

Now I can see what is being sent. In this case 1 Byte, which consists of my fuel pressure. I then added "Fuel Pressure" to my SD logging so I'll have it in both as needed.

Canyonfive
Posts: 57
Joined: Mon Jan 29, 2018 11:20 pm

Re: Sharing/Outputting GPS or Wheel speed to megasquirt

Post by Canyonfive »

OK. I have edited the title and the first post to reflect the reality and the changes. After logging my wheelspeed (vss1) from the Megasquirt vs the GPS speed at 25Hz its clear there is a lag and its not good enough for Launch control / traction control.

However the MK3 Pro has 4 wheelspeed inputs. So, Ill be connecting my ABS sensors (VR) to a conditioner (JRperf) to output as a 0-5v square wave. Something the RPM inputs would be happy to receive. While I wait on parts, I thought I would work out the settings needed to make this possible. Also I chose text since pictures need updating.

Race Capture Settings are done in lua. (Modified code from GTI Spirit and this code can really be shortened but that is a thread for another time.)

setTickRate(50)--TickRate is in Hz
function onTick()
local speed = getChannel("RPM1") --raw pulses from the sensor... also a number that will end up being larger than 255 so it can be just one byte like the fuel pressure example
speedL = bit.band(speed, 0xFF) --maskout high byte
speedH = bit.rshift(speed, 8) --shift high byte to the right --The point of doing this is to send a number greater than 255
--format local speed into a CAN message. Speed is in the first two bytes also mind the brackets they are important, I think this is called an array.
local msg = {speedL,speedH}
txCAN(0, 1917, 0, msg) --(Bus, ID in Decimal format , 0 for 11 bit header, msg for your variable that contains what you want sent)
--color for easier reading on the forums
--Delete everything with --before it when using the code
end

The goal of this code is to send the pulses from your RPM inputs to the MegaSquirt. It works, you can test it by making local speed = 444 instead of fetching your RPM channel which will be 0 since you probably aren't programming lua and driving at the same time. :D

MegaSquirt Settings. (I have an Ms-Pro3-PNP and these instructions assume you have the canbus already connected, like with can mapping.)

I also recommend making a custom gauge on the megasquirt dash with vvs2_ms_1 as a confirmation you are receiving data.

1) CAN Parameters
Enable ADC Polling, but leave all the ADC selections to OFF

2) Can Receiving
Shown above, this is where you will tell the megasquirt where to listen. Im using can vvs2 but you'll want to use whatever you want to import it to CanVVS1-4
Local Variable Std/Ext Identifier Offset Size
CanVVS2 std 1917 0 L2U

The ID can be whatever you set it to, just dont use anything 1500-1700 or 1-10. The size is now L2U since we are sending 2 unsigned bits.

3) CAN VVS Gear
Mode = Listen
Data Size = 16 bit

4) Advanced Engine > Speed and Gear Sensors
VSS1-4 your choice, but it must match the local Variable you choose. IE Can Receiving.
Input type = Digital
Digital Input = CanVss1-4 (and your local variable selection for that wheel)
Wheel Dia = whatever it is for your tire
VVS position type = Wheel
Scaler = Still working on it, but I have it 45.6 as of this writing for testing
Smoothing Lag Factor = 100%

Post Reply