Reading & logging inputs (EGT) over CAN from Arduino

For discussion of Phil Tobin's Tuner Studio software (Only about the tuning software itself, not about how to tune or firmware features)

Moderator: LT401Vette

Post Reply
motthomas
Helpful MS/Extra'er
Posts: 88
Joined: Wed Aug 24, 2011 2:06 am

Reading & logging inputs (EGT) over CAN from Arduino

Post by motthomas »

Hi all,
I have done a fair bit of searching on this but haven't been able to get anywhere so I am just hoping that there is something simple that I have missed.

Is there any documentation which covers adding logging parameters which are received via CAN bus?

I am running a Microsquirt V3 ECU with MS2E3.4.0 firmware and I want to be able to log EGT values from 4 thermocouples which will be sent to the ECU via CAN. I am using an Arduino to process the temperatures from the amplifiers and put the data on the bus but so far have not managed to get Tunerstudio to read and log the data. I have successfully used the Arduino hardware to read the ECU data via dash broadcasting to prove the hardware and code.

I have enabled Master in CAN Parameters and also enabled CAN ADC 0-3. I would have thought that this would get me what I want but there then does not seem to be any option to give CAN ADC 0-3 labels or to add them to the logging config. Is there another step that I am missing? I thought I might be able to use the Custom Channel Wizard to add the parameters and direct them to Remote ADC inputs in the same way as you can with Baro & other defined inputs but Remote ADC X is not an option within the Custom Channel Wizard.

Do I need a .ini file to tell Tunerstudio that there is a CAN module in the same way as the CAN-EGT does? If this is the case, is there any guide that will let me know what exactly this .ini file needs to contain? Bear in mind that I don’t need any configuration to be done via Tunerstudio. I am sending 4off Celsius temperature values across the bus and the only reason they are being provided is to add to the logged dataset. The ECU does not need to do anything with the values and I, the user, do not need to choose temperature units or configure this data as anything but EGT. What is the minimum that Tunerstudio requires in the .ini file to do the job?
Alfagta
Experienced MS/Extra'er
Posts: 239
Joined: Wed Aug 21, 2013 2:54 am

Re: Reading & logging inputs (EGT) over CAN from Arduino

Post by Alfagta »

Does your arduino already send the data to teh MSII via can bus?

You should have a gauge for the GPIO ADCx it is under the Sensor inputs 2 menue when you assigne a gauge.
They should also be logged normally..

BR
Alfa 156 GTA
Alfa 75 Race Car MS III -- alway latest FW
Alfa 164 V6 Turbo
Alfa 155 2,5TD RIP
Test MS II --always latest FW
Tunerstudio V2.6.11 Registered
MegaLog Viewer V3.4.04 Registered
motthomas
Helpful MS/Extra'er
Posts: 88
Joined: Wed Aug 24, 2011 2:06 am

Re: Reading & logging inputs (EGT) over CAN from Arduino

Post by motthomas »

Yes. Well, I am putting data on the bus from the Arduino and the Arduino is connected to the Microsquirt. Thank you for clarifying that the data should be coming in on GPIO ADC0-3. This though is telling me that the data isn't being read by the ECU.

Up until now I have been trying to send the data on an 11-bit message because I am using a later level firmware but paying a bit more attention to the labelling in Tunerstudio I am wondering if the MS2Extra requires CAN messages to be sent in 29-bit format in which case, my issues/misunderstandings run deeper than just Tunerstudio and this topic may be in the wrong forum…

I have also tried to send the data on a 29-bit message but still no success so now I am looking further into the format of the message as I had formatted the message in the same way as I would have expected having received data successfully. However, some things are confusing me.

First is the CANid. The way the notes and documentation read this could be interpreted as a number to identify the module which is sending the CAN data. But then what about the message ID because surely that is required to figure out where to look for the data? Also because the max value for “CAN id” is 14, this doesn’t match that 29-bit IDs can go as high as 536870911.

Then I am not sure I fully understand the “Table” parameter. Its not a term I am familiar with on CAN messages and doesn’t appear in any of the standard documentation I have read, only in the Megasquirt 29bit CAN protocol document which describes them as “Within the Megasquirt memory map various regions are referred to as tables” but this does not tell me a lot about how the CAN message needs to be structured or how to cross reference between the Arduino code and the Tunerstudio input.

The Arduino code to send a message is: CAN.sendMsgBuf(id, id_type, dlc, data buf). Tunerstudio requires CAN id, Table, Offset. How do the Tunerstudio parameters relate to what is being sent?

I can see that the MS3 firmware makes configuring additional CAN inputs easier and they are 11-bit so maybe I am just banging my head against the wall trying to get a Microsquirt to receive the data via CAN and Arduino? Are they even compatible?
jsmcortina
Site Admin
Posts: 39619
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: Reading & logging inputs (EGT) over CAN from Arduino

Post by jsmcortina »

Have you read the PDF document about Megasquirt CAN?

MS2/Extra has no capability to receive generic broadcasts, either 11bit or 29bit.

James
I can repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
grom_e30
Super MS/Extra'er
Posts: 4461
Joined: Thu Mar 08, 2012 12:44 pm
Location: UK

Re: Reading & logging inputs (EGT) over CAN from Arduino

Post by grom_e30 »

but you could use the can adc, then the ecu will send a request for the data using the 29bit identifier, this identifier and the message will say what data it wants from what device and will say where to send it to and where to save it, your arduino will then have to send a response back to the ecu again using the megasquirt 29bit format in order for the ecu to be able to read data from the arduino. it is possible to do i have a display using a uno32 (basically an arduino) that has a baro sensor, light sensor rtc and some switched inputs connected to it that works with my ms3 using the 29bit setup.

if you did use the can adc the easiest option would be to have a temp range of 0-1023c that way you could just send the temp in degree c and the adc number would not need converting.
1990 bmw 320i daily driver with m20b25 ms3 sequential fuel, 380cc injectors, d585 coil near plug, home made cam sync, launch control, fan control, vss, homebrew egt logging what's next????
jsmcortina
Site Admin
Posts: 39619
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: Reading & logging inputs (EGT) over CAN from Arduino

Post by jsmcortina »

Yes, but from what I read, the poster was just 'sending data' without regard to Megasquirt CAN ?

James
I can repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
motthomas
Helpful MS/Extra'er
Posts: 88
Joined: Wed Aug 24, 2011 2:06 am

Re: Reading & logging inputs (EGT) over CAN from Arduino

Post by motthomas »

Thanks guys, it’s a lot clearer to me now.

James, I had scanned through that document as part of my reading but hadn’t paid it a lot of attention as I had understood that the implementation of standard 11-bit headers from firmware 3.3.X applied to messages being received by the ECU as well as broadcast messages.

Understanding now that to get data to the ECU via CAN I need to use the proprietary 29-bit headers (I had not appreciated how different this is from other 29-bit headers), I’ve gone through the CAN protocol document in more detail and feel like I understand the majority of it. At least how the header IDs are built up.

It does open up more questions on the tables though. I made the assumption last night when I retested the setup that I could send the data to table 4 (Tuning Data). Clearly this was an incorrect assumption as it resulted in the number of cylinders being changed as soon as I initialised the CAN device. While it’s not the response I was looking for, at least it was a response indicating that I am getting closer to the goal. For additional input data to be directed to GPIO ADCX, is there a specific table that this should be written to so that it doesn’t unexpectedly clash with other functions? Is table 6 ok or maybe table 7 is better?

In the examples at the end of the CAN protocol pdf, the request & response messages have different table numbers. Is that specific to remote devices which also work on the Megasquirt memory structure? So in my example, when I specify Table X in the CAN Parameters window, the request message will reference Table X. Then the reply message containing the data should also reference Table X?

Grom, if you have this working already, would you be willing to share your Arduino code for processing the request and replying with the data? I’m 90% sure of my code but it would be a good sanity check. All the code I have found to date is for reading data from Megasquirt only.
Alfagta
Experienced MS/Extra'er
Posts: 239
Joined: Wed Aug 21, 2013 2:54 am

Re: Reading & logging inputs (EGT) over CAN from Arduino

Post by Alfagta »

Hello,

i have all this working and have played so much time with the MS can bus.
I have developet 2 boards (1x Extender Board, 1x Display Board) which are working with the MS and the 29 Bit protocol.

For my development i have made a excel sheet which can encode and decode the canbus id.
I have attached the sheet.

I think it will help you to understand the ms protocol better.
Decode MS Can ID (2).zip
BR
Alfa 156 GTA
Alfa 75 Race Car MS III -- alway latest FW
Alfa 164 V6 Turbo
Alfa 155 2,5TD RIP
Test MS II --always latest FW
Tunerstudio V2.6.11 Registered
MegaLog Viewer V3.4.04 Registered
motthomas
Helpful MS/Extra'er
Posts: 88
Joined: Wed Aug 24, 2011 2:06 am

Re: Reading & logging inputs (EGT) over CAN from Arduino

Post by motthomas »

Thanks BR. That is pretty much where I got to last night with my understanding and the hex IDs generated from my spreadsheet match those generated by yours so that is a plus. In that case it must be the table that I am using that is the problem. What table do you send your additional inputs to?
Alfagta
Experienced MS/Extra'er
Posts: 239
Joined: Wed Aug 21, 2013 2:54 am

Re: Reading & logging inputs (EGT) over CAN from Arduino

Post by Alfagta »

The MS tells you everything with the id what you need to build the answear id.
In the id from the MS there is the table number inculded to which you send data.

An MS request the data from the table you have defined in the can bus parmeter page for the GPIO Adc...

Best Regards
Alfa 156 GTA
Alfa 75 Race Car MS III -- alway latest FW
Alfa 164 V6 Turbo
Alfa 155 2,5TD RIP
Test MS II --always latest FW
Tunerstudio V2.6.11 Registered
MegaLog Viewer V3.4.04 Registered
motthomas
Helpful MS/Extra'er
Posts: 88
Joined: Wed Aug 24, 2011 2:06 am

Re: Reading & logging inputs (EGT) over CAN from Arduino

Post by motthomas »

I understand that the request message from MS contains the table numbers & offsets, etc but is that not what needs to be defined in the CAN Parameters dialogue box in TS (below)? If I understand this correctly then I need to tell MS where to tell the remote CAN module to send the data? Or is this not the case and I am still misunderstanding what the TS settings are doing?
Alfagta
Experienced MS/Extra'er
Posts: 239
Joined: Wed Aug 21, 2013 2:54 am

Re: Reading & logging inputs (EGT) over CAN from Arduino

Post by Alfagta »

No this tells the Ms where to request the data from.

The table and offset for the answear are in the 3 data bytes.

So the ms tells you the table and offset for the msg you send back.

You can also build a message Id with my excel sheet.
Go to the second tap.

In your attached picture the ms request 8 bytes from Id 2, table 7 offset 0.
Alfa 156 GTA
Alfa 75 Race Car MS III -- alway latest FW
Alfa 164 V6 Turbo
Alfa 155 2,5TD RIP
Test MS II --always latest FW
Tunerstudio V2.6.11 Registered
MegaLog Viewer V3.4.04 Registered
jsmcortina
Site Admin
Posts: 39619
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: Reading & logging inputs (EGT) over CAN from Arduino

Post by jsmcortina »

motthomas wrote:I understand that the request message from MS contains the table numbers & offsets, etc but is that not what needs to be defined in the CAN Parameters dialogue box in TS (below)? If I understand this correctly then I need to tell MS where to tell the remote CAN module to send the data? Or is this not the case and I am still misunderstanding what the TS settings are doing?
The CAN settings tell the MS where to request data from. The MS then tells your device where to send the data, don't guess and don't send them somewhere else - send them where it asked.

James
I can repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
motthomas
Helpful MS/Extra'er
Posts: 88
Joined: Wed Aug 24, 2011 2:06 am

Re: Reading & logging inputs (EGT) over CAN from Arduino

Post by motthomas »

Ah ok. Got it. That makes a lot more sense. I'll revisit over the weekend and hopefully I'll get it working this time.

Thanks for your help and patience lads!
Post Reply