DEF Sensor Simulator – CanBed ATmega 32U4
Assembling a DEF Sensor Simulator Using a CanBed ATmega 32U4
Only basic electrical and DIY skills are required for the hardware assembly, however some basic soldering is needed to install the 4 pin connector. There are many YouTube videos that can teach you to solder. For delicate electronics such as this use a low wattage grounded soldering iron (25 – 30 Watts) to help prevent pad damage, don’t use a soldering gun.
The software installation in this procedure can be done from Windows and is relatively straightforward.
Before you begin, please click here to read an important compatibility notice regarding the ECM (Electronic Control Module, aka Engine Computer) and info on compatible DEF head connectors.
If you run into difficulty post a comment at the bottom of this page.
Please read through all the instructions FIRST before beginning the project. There are web site links embedded in the instructions to help obtain parts.
NOTE: before mounting in the enclosure box, the CanBed needs to be programmed! Please see instructions in the Programming section.
• Drill & bits
• Wire cutters / Strippers
• Small screw driver
• Ohm meter (multi-meter)
• Silicone sealant (optional)
• Soldering iron & solder
1) The CanBed board can be obtained from several online sources. This board has the ATmega32U4 processor. The suggested source is Digikey.com p/n: 1597-102991321-ND
2) You will need a USB cable with a micro USB connector, as the board does not come with one. They are available at online retailers or in many stores. Here is one from Amazon.
3) Weather tight enclosure. The entire assembly of the CanBed is very small. The enclosures used on the UNO or DUE variants will work just fine, although they are larger than needed. Feel free to get a smaller one if desired. Here is one from Amazon that will work.
As an alternative to the “Gland nut” you can use a rubber grommet, which can be purchased from most hardware stores, such as ACE Hardware. Just get one that will fit your cable diameter. You could also just fill the hole in the box where the cable goes through with silicone sealant.
It is recommended that you program the CanBed board before doing the assembly. Please refer to the Programming section at the end of this post.
Take the 1 Meter DT Extension cable that you purchased and cut the off the flat end with the exposed orange silicone as shown in the picture below, approximately 4 inches from the connector. The short end with the Orange silicone connector will not be used electrically, but if desired can be used as a “dust cap” for the DEF head sensor connector when the DSS is not in use.
After cutting the cable, trim back the outer jacket about 4 inches and expose the 4 inner conductors. Be careful to not cut the inner conductors.
As noted at the beginning, the CanBed needs to have a connector soldered to the board. The connector comes with the board. You can get a very inexpensive soldering iron kit from Amazon (see tools list )
You can optionally directly solder the cable wires to the board if you wish. If you choose to solder the wires directly, you will need to feed the wires through the enclosure first.
The wiring connections on the 4 pin DT04 connector are: +12v, ground, CAN-H and CAN-L.
The wires associated with these pins (above picture) are connected to the CanBed via the screw terminals. You will need to use an ohm meter (multi meter etc) to determine which wire is connected to which pin, as the wire color codes are not standardized.
Drill a hole through the enclosure to accommodate the cable and gland nut (or grommet, whichever you are using). Feed cable into enclosure.
Strip about 3/16 inch of insulation off each wire end and connect to the screw terminals. Make sure the slot is fully open as shown in the picture below. If the wires are too large, you can trim off a few of the strands. Make sure there are no loose strands sticking out of the connector.
Insert the stripped wires into the slots shown in the picture below:
Tighten the screws to securely fasten the wires in the slots.
The finished board assembly can be secured in the box using Velcro.
A completed assembly:
NOTE: before mounting in the enclosure box, the CanBed needs to be programmed! Please see instructions in the Programming section if this has not been completed.
Programming the CanBed:
It is assumed that someone attempting to construct one will have a modest knowledge of a Windows based computer. The initial work was completed on a Windows 10 based machine, but it is expected that a Windows 7 or XP based machine will also work (USB drivers could be an issue). The computer will need to have at least 1 available USB 2/3 port.
The Arduino software install file can be downloaded by clicking here. The full github page can be viewed here.
When your browser opens to the page, click on the “download” button to download the file.
The download file (DEF Emulator Install Files v0.2 (x32).exe) is a self-extracting file that will include the compiled Arduino software appropriate for your hardware configuration and files for actually programming the Arduino. It is not necessary to install any additional software from Arduino or anywhere else. The browser will typically download the file into the “Downloads” section as shown in Windows File Manager.
After the file is downloaded, just double-click the file and it will automatically create the required directory structure on your C drive and copy all necessary files into their appropriate locations. It will prompt you to verify the destination directory, accept the suggested default, which is C:\AVRProg. You may see warnings from your anti-virus software on your Windows computer and you may have to deal with those to allow the installation to run. The downloaded installation package will create the following directory structure in the root of your C:\ drive:
1) Using a micro USB cable, connect the CanBed board to your computer’s USB port. You should see a LED light up next to the micro USB port on the CanBed board. This indicates power to the board.
2) Open Windows10 Device Manager (right click on windows “start” icon in lower left of screen and select Device Manager). Look under “Ports (COM & LPT)” and you should see the board listed. Note that it may be only listed as “USB Serial Device”. Here it’s shown as COM4. If there is more than one device shown, unplug the CanBed board and see which device is removed from the list. Be sure to plug the board back into the USB port.
3) Leave the Device Manager window open. Press and release the reset button on the CanBed board.
4) Watch for the Device Manger window to refresh. Under the Ports section you probably will see the COM# value change. Note this new value. Make sure the COM# does NOT overlap with another COM device.
5) Open a Windows10 CMD window by right clicking on Windows “start” icon at lower left of screen and then left click on Command Prompt.
6) Type: cd\avrprog and then hit Enter key
7) You should see the command prompt as C:\AVRProg
8) Type: program canbed x where x is the COM port number (1, 2, 3 etc) from step 4. DO NOT hit Enter key yet!!
9) Press and release the reset button on the CanBed board
10) Wait about 2 seconds and then press the Enter key in the CMD window
11) You should see something similar to this:
And when finished:
12) Programing is now finished.
After programming, it is expected to see a LED behind the reset button double flash about once per second. You can now disconnect the board from your computer.
Video after programming:
Connecting to your motorhome CAN network:
- Make sure that before you unplug your def head that the ignition is turned off, then unplug your def head. You may need to cut a zip tie to provide working slack in the wiring.
- Plug the simulator into the connection to your chassis wiring where the def head was plugged in.
- Turn on your ignition, some or all of the fault codes should go away and the Check Engine and MIL (Malfunction Indicator Lamp) lights should extinguish within a few minutes.
- If some codes remain, to clear your codes you will need to turn your ignition on (let all systems come up, about 20 seconds), then start your engine and fast idle for 5-6 minutes, shut down for 90 seconds, turn ignition on (wait for systems to boot 20 sec) start engine and fast idle for 5 min. You will do this a total of 3 times on the 4 cycle the codes should clear to the inactive status.
Note: on older engines or engines with older ECM software, some codes may not completely clear on their own. In this case code clearing intervention may be required. This is something that is still under study, see the Troubleshooting section for more info.