Page 1 of 1

Sharing/Outputting GPS or Wheel speed to megasquirt

Posted: Fri Jul 17, 2020 12:42 am
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)

Posted: Sat Jul 18, 2020 7:26 pm
by GTIspirit

Re: Sharing/Outputting GPS speed to megasquirt

Posted: Fri Sep 25, 2020 8:58 pm
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.

Re: Sharing/Outputting GPS or Wheel speed to megasquirt

Posted: Sat Oct 03, 2020 6:20 am
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%

Re: Sharing/Outputting GPS or Wheel speed to megasquirt

Posted: Mon Jan 25, 2021 7:09 pm
by brentp
Good writeup. Yes, the Lua scripting should be flexible for handling most any kind of CAN output.

-Brent