Site Information

 Loading... Please wait...

Blog

SAE J1939 GPS Application With Arduino Due Delivers PGN 65267 (Vehicle Position)

Posted by Wilfried Voss on

Arduino Due With Dual CAN Bus Interface Plus GPS Module

I am repeating myself over and over, but the Arduino Due is my preferred choice when it comes to quick prototyping of SAE J1939 and CAN Bus applications. It is the ease of programming and the great performance that makes it all possible. In fact, I created this application in only a few hours, mostly by copying and pasting existing code.

The Hardware

Quite obviously, I did use the Arduino Due but with some important additions. First of all, I added our Dual CAN Bus Interface for Arduino Due to support the SAE J1939 protocol stack, specifically its hardware layer. We also offer the same board which comes with an extended power supply range of 7 VDC to 36 VDC. Add to this combination a J1939 cable and you are ready to go and write your own J1939 application.

Secondly, in order to read GPS information, I added our UART GPS Module and connected it to the Arduino Due's RX1, TX1 (Serial1) port. The GPS sensor provides data according to NMEA 0183 (as does any standard GPS sensor), and decoding the data is fairly easy to accomplish with the appropriate information, the so-called NMEA output sentences, at hand. 

The Software

As I mentioned previously, this project was primarily created by copying and pasting code from several other applications I developed for the Arduino Due. It would take a lot more pages to explain the code for this GPS project in detail, but I deemed it more effective to provide references to the other applications. They are:

And yes, the project includes a full-blown SAE J1939 protocol stack, but please be aware that the actual protocol stack comes in a pre-compiled form. The protocol settings are documented in the above listed hyperlink.

Disclaimer

This Arduino program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

The protocol settings, such as the J1939 NAME, are designed to have a minimum impact on a J1939 vehicle network's operation, i.e. the application will yield its node address to any competing node. Nevertheless, the setting of NAME and node addresses in this project serve only as a demonstration.

Click here to download the entire Arduino Sketch (zip file).

PGN 65267 - Vehicle Position

The output of the application is PGN 65267 (0xFEF3) according to the SAE J1939-71 standard:

Transmission Rate: 5 s
Data Length: 8 bytes
Default Priority: 6

Start Position Length Parameter Name SPN
1 - 4 4 bytes Latitude 584
5 - 8 4 bytes Longitude 585

SPN 584

Resolution: 10^-7 deg/bit, -210 deg offset
Data Range: -210 to 211.1008122 deg
Operational Range: -210 deg (SOUTH) to 211.1008211 deg (NORTH)

SPN 585

Resolution: 10^-7 deg/bit, -210 deg offset
Data Range: -210 to 211.1008122 deg
Operational Range: -210 deg (WEST) to 211.1008211 deg (EAST)

Proof of Concept

The image below shows the data output of the application.

Line 1 documents the address claim. The application is set up for an address range between 128 (0x80) and 247 with a preferred address of 128. Since there is no other competing node, the application claims the address easily. The following lines are valid GPS data (pointing to my Windows 10 PC in my office; I moved the board as far as the cable allowed and changes are visible). 

Please note that the SAE J1939-71 Standard uses Small Endian for data transmission, meaning LSB comes first, MSB comes last. Also be aware, it might take several minutes after startup before the GPS module can provide a valid position (Once found, it takes only seconds with clear reception). The SAE J1939-71 Standard does not cover that situation, i.e. the data output for such a case is not defined. Rather than not sending anything at all, I chose to set all 8 data bytes to 0xFF.

Master The Arduino Due To Communicate through Ethernet, WiFi, USB, Firmata, and Xbee

Arduino Sketches is a practical guide to programming the increasingly popular microcontroller that brings gadgets to life. Accessible to tech-lovers at any level, this book provides expert instruction on Arduino programming and hands-on practice to test your skills. You will find coverage of the various Arduino boards, detailed explanations of each standard library, and guidance on [...]

Read More »


Electronic Logging Device (ELD) - GPS And Real-Time Clock (RTC) Breakout Board For The Arduino Due

Lately, I had looked into the topic of Electronic Logging Devices (ELD). An ELD is electronic hardware that is attached to a commercial motor vehicle engine to record driving hours. The driving hours of commercial drivers (truck and bus drivers) are regulated by a set of rules known as the hours of service (HOS). An ELD monitors a vehicle’s [...]

Read More »


Arduino J1939 Shield For Data Traffic Simulation And Vehicle Application Development

First of all, my apologies for a "misleading" title that included the term "J1939 Shield." I picked the topic after noticing increased search traffic for the term. In all consequence, there is no real J1939 Shield but an Arduino CAN Bus Shield with supporting J1939 protocol stack software.As a matter of fact, there a several [...]

Read More »


CAN Bus Bridge (CAN-to-CAN) Application With Arduino Due

Basically, there are two scenarios where a CAN Bridge application is of use:1. Connecting two separate CAN Bus networks.2. Network length extension.While the first scenario is more or less self-explanatory, let's look a little closer into the network length extension: The physical CAN network length depends primarily on the CAN baud rate, i.e. the higher [...]

Read More »


RS232 to USB Converter With Arduino Due Or Mega 2560

Just about everyone who is involved with serial communication will have his/her RS232 to USB converter. Today's PCs don't even bother to support RS232. Consequently, a USB converter is mandatory to monitor RS232 data traffic. All this appears to render the following project obsolete. However, when it comes to a protocol converter, i.e. the conversion [...]

Read More »


CAN Bus Data Traffic Simulation With Arduino Due

When working on a CAN bus or SAE J1939 project, it can be extremely helpful when the expected CAN Bus data traffic can be simulated rather than connecting your system to a running vehicle or automation control. The following project does exactly that with little effort for designing CAN data frames and their frequency. As [...]

Read More »


Interrupt-Controlled Timer Function For The Arduino Due

The Arduino Due is a microcontroller board based on the Atmel SAM3X8E ARM Cortex-M3 CPU. It is the first Arduino board based on a 32-bit ARM core microcontroller. It has 54 digital input/output pins (of which 12 can be used as PWM outputs), 12 analog inputs, 4 UARTs (hardware serial ports), a 84 MHz clock, [...]

Read More »


Monitoring SAE J1708/J1587 Data Traffic Using The Arduino Mega2560 Or Arduino Due

First of all, let me point out that this post is merely about monitoring SAE J1708/J1587 data traffic, i.e. the mere reading of data frames. SAE J1708, the hardware layer, is based on RS485, however, with a small hardware modification that allows message collision detection and prevention. In the following, I am using an RS485 [...]

Read More »


How To Use The Native USB Of The Arduino Due For High-Speed Communication

It seems to be an obvious statement, but there are many applications for the Arduino Due that require high-speed communication in a range that goes beyond regular UART baud rates, i.e. several Mbits/sec. Naturally, USB comes to mind, but surprisingly there are some obstacles when it comes to accessing the Arduino Due's USB ports. The [...]

Read More »