Page 1 of 3
Help with Mercedes w211 E55
Posted: Thu May 04, 2017 1:41 am
by Bewbzout
So I know nothing about CAN or LUA scripting. I was swayed by a buddy to buy the RCP for its ability to read CAN data. So here I am in a area I know nothing about.
So....
First off I will say that at this point I am only trying to read ecu data for tunning purposes. Mostly interested in getting RPM, MAP, IAT, and TPS.
I have turned CAN bus "on" and set baud rate for both channels at 500k. I also received a script from him that I pasted into the white area of the scripting section. After pasting it I assumed I needed to hit write after that.
So after all this I still do not get any info on the dashboard.
I will post the script I got below.
Posted: Thu May 04, 2017 1:42 am
by Bewbzout
--This example configured for E55 W211 CAN
--how frequently we poll for CAN messages
tickRate = 30
--the CAN baud rate
CAN_baud = 500000
--CAN channel to listen on. 0=first CAN channel, 1=second
CAN_chan = 0
--1 for Big Endian (MSB) mode; 0 for Little Endian mode (LSB)
be_mode = 1
--add your virtual channels here
tpsId = addChannel("TPS", 10, 0, 0, 100, "%")
--rpmId = addChannel("RPM", 10, 0, 0, 8000)
--customize here for CAN channel mapping
--format is: [CAN Id] = function(data) map_chan(<channel id>, data, <CAN offset>, <CAN length>, <multiplier>, <adder>)
--format is:eg [Decimal CAN Id] = function(data) map_chan("channel id", data, "CAN byte offset(0 for first byte, 1 for 2nd byte, etc)", "CAN length in byte count", "multiplier", "adder")
CAN_map = {
[528] = function(data) map_chan(tpsId, data, 2, 8, 0.4, 0) end,
--[776] = function(data) map_chan(rpmId, data, 3, 2, 0.15625, 0) end(not ready yet, gotta figure out bitmasking)
--setCANfilter(channel, filterId, extended, filter, mask )
}
function onTick()
processCAN(CAN_chan)
end
--===========do not edit below===========
function processCAN(chan)
repeat
local id, e, data = rxCAN(chan)
if id ~= nil then
local map = CAN_map[id]
if map ~= nil then
map(data)
end
end
until id == nil
end
--Map CAN channel, little endian format
function map_chan_le(cid, data, offset, len, mult, add)
offset = offset + 1
local value = 0
local shift = 1
while len > 0 do
value = value + (data[offset] * shift)
shift = shift * 256
offset = offset + 1
len = len - 1
end
setChannel(cid, (value * mult) + add)
end
--Map CAN channel, big endian format
function map_chan_be(cid, data, offset, len, mult, add)
offset = offset + 1
local value = 0
while len > 0 do
value = (value * 256) + data[offset]
offset = offset + 1
len = len - 1
end
setChannel(cid, (value * mult) + add)
end
map_chan = (be_mode == 1) and map_chan_be or map_chan_le
initCAN(CAN_chan, CAN_baud)
setTickRate(tickRate)
Posted: Thu May 04, 2017 3:14 am
by boggie1688
Sounds like someone baited you into being a guinea pig.
Don't worry, I convinced myself to be a guinea pig.
It looks like the W211 was produced between 2006 and 2012. You may or may not have CAN via OBDII. How are you currently connected to CAN? Are you certain the car has CAN? Are you on the right CAN network (cars can have multiple networks) ?
Delete the script your "buddy" sent you. Use this instead simple can bus logger instead:
-- Log messages from CAN bus
-- be sure to set the correct baud rate in the CAN settings
--------------------------------------------------
-- change this to 1 for CAN bus 1, 2 for CAN bus 2
canBus = 1
--------------------------------------------------
--this function drains all pending CAN messages
--and outputs messages to the log
function outputCAN()
repeat
id, ext, data = rxCAN(0, 1000)
if id ~= nil then
print('[' ..id ..']: ')
for i = 1,#data do
print(data ..', ')
end
println('')
end
until id == nil
println('Timeout: no CAN data')
end
function onTick()
outputCAN()
end
setTickRate(30)
Save the script, then check the "Poll Logfile" box. The black box below the script should fill up with a bunch of numbers. These are the CAN messages. This has to be done with the accessory power on. The car doesn't necessarily need to be running.
If you don't have message, there are some other things you can try changing: baud rate, can bus 1 or 2, reversed wires, correct wires, etc. You can find more info here: https://wiki.autosportlabs.com/CAN_Bus_logger
Start there before moving forward.
[/quote]
Posted: Thu May 04, 2017 3:31 am
by Bewbzout
Thank you for the reply. The car in question is a Mercedes 2006 e55. Is does have CAN and I am accessing it using a cable he sent me.
I will give it a try tomorrow. Thank you
Posted: Thu May 04, 2017 3:54 am
by boggie1688
E55!
Very nice!
Good luck and have fun!
Posted: Thu May 04, 2017 3:51 pm
by brentp
Thanks boggie1688 for help!
Bewbzout, thanks for working through decoding the mysteries of your car's CAN bus network!
To make the post more helpful for others finding similar information, I'd recommend renaming your first post to something like "Help with E55 W211 CAN bus"
Thanks!
Posted: Fri May 05, 2017 3:00 am
by Bewbzout
so I tried the script and I did get some stuff in the black box. Not letting me upload the pic but it said "GPS:" a bunch of times with things like configuring baud rate.
Posted: Fri May 05, 2017 3:04 am
by brentp
Hi - so this morning we just updated and improved the script a bit, and wrote this accompanying blog post:
https://www.autosportlabs.com/use-racec ... cars-data/
See the details in the post; if you see data you'll see some data flowing as shown in the screenshot. If not, you'll see 'timeout' errors. Please try the latest script; curious to see what you get!
Posted: Fri May 05, 2017 4:03 am
by Bewbzout
Well I can't seem to post a pic to save my life.
[LUA] gracefully stopping Lua task
[LUA] destroying Lua state
[LUA] initializing Lua state
[LUA]memory usage 16k
[LUA]loading script length 2130
[Can device] initializing can with baud rate 5000000
[Can device] can input success
[Lua] successfully loaded script
[Lua]script error [string "--this example configured for e55 w211 can..."]:62.0:
Attempt to perform arithmetic on field? (A nil value)
[Lua]script error [string "--this example configured for e55 w211 can..."]:62.0:
Attempt to perform arithmetic on field? (A nil value)
[Lua]script error [string "--this example configured for e55 w211 can..."]:62.0:
Attempt to perform arithmetic on field? (A nil value)
[Lua] failure: runtime error
Posted: Fri May 05, 2017 4:09 am
by brentp
It looks like there's a problem with your script, due to the error message. Try removing *everything* from the script window, then paste in the CAN logging script. That way, only the CAN logging script is in the window. Should work after that.
Posted: Fri May 05, 2017 12:40 pm
by Bewbzout
I'm pretty sure only this was in the white box
-- Log messages from CAN bus -- be sure to set the correct baud rate in the CAN settings -------------------------------------------------- -- change this to 0 for CAN bus 1, or 1 for CAN bus 2 canBus = 0 -------------------------------------------------- --this function drains all pending CAN messages --and outputs messages to the log function outputCAN() repeat id, ext, data = rxCAN(canBus, 1000) if id ~= nil then print('[' ..id ..']: ') for i = 1,#data do print(data ..', ') end println('') end until id == nil println('Timeout: no CAN data') end function onTick() outputCAN() end setTickRate(30)
Posted: Fri May 05, 2017 1:08 pm
by Bewbzout
Ok I think I missed writing the script to the rcp. So I retried the script and I got
GPS: successfully configured NMEA
GPS: configure message type: win
Stuff like that then a bunch of
[LUA] gracefully stopping Kia task
[LUA] Destroying Lua state
[LUA] Initializing Luna state
[LUA]Memory usage 16kb
[LUA] Starting Luna task
[LUA] Loading script. Length: 1212
[LUA] successfully loaded script
Then it just keeps repeating that
Posted: Fri May 05, 2017 1:33 pm
by boggie1688
I copied and pasted that script from the mk2 wiki.
Im assuming you have the can bus turned on in the app. If so it looks like it is not setting the correct can channel. Did you wire the can to the RCP via can 1 or 2?
Edit this line:
id, ext, data = rxCAN(0, 1000)
Change the 0 to 1 or 2 depending on which can you wired the car to.
Posted: Fri May 05, 2017 3:15 pm
by brentp
boggie1688, so yesterday we updated the script to provide more useful output - specifically to output a timeout message if no data has been received; the old script just did nothing if no CAN data was being received.
https://wiki.autosportlabs.com/CAN_Bus_logger
Screenshots of what it should look like here:
https://www.autosportlabs.com/use-racec ... cars-data/
Bewbzout, looks like your script isn't getting loaded correctly. Try this:
* read your RCP config (press 'Read' butto' in setup)
* erase everything in the script window
* write the config back to RCP (press 'Write' button)
* read it back, ensuring everything is empty in the script window
* Paste the new script in it's entirety from here:
https://wiki.autosportlabs.com/CAN_Bus_logger
* Write the config back to RCP
* press the 'poll logging' checkbox and check the output messages.
Like you see in yesterday's blog post screenshots, you should see some data flowing, or, you should see 'timeout' messages.
Side note, MK3 has an orange CAN indicator LED in the upper right of the front panel, labeled 'CAN'. Do you see that illuminating?
Posted: Fri May 05, 2017 7:24 pm
by Bewbzout
Brent, I will try that tonight. I have the mk2 so no orange light on mine.