RP2040-based VPW adapter

endjuser

Original poster
Member
Jul 7, 2020
12
PA
I've seen a few folks on this forum experimenting with Arduino-based VPW adapters for interacting with Class 2 messages. I thought I would share one of my own projects, using a $5 Waveshare RP2040 Zero board to implement the VPW protocol using PIO for precise timing:

https://github.com/endjuser/rp2040-vpw

The main advantage of the RP2040 is that it's fast enough to handle 4X VPW (using PIO) and has plenty of available compute to implement your own logic. I'm using it primarily as an in-vehicle data logger to an SD card, but have another one on my workbench for testing/experimentation.

This code was designed for using a MC33390 VPW transceiver IC (level-shifted to 3.3V for the RP2040) to interface with the VPW bus, but for a DIY workbench scenario (e.g. not in-vehicle) you may be able to get away with just level-shifting 3.3V to 7V without using a transceiver chip.
 
  • Like
Reactions: AmpOverload

mrrsm

Lifetime VIP Donor
Supporting Donor
Member
Oct 22, 2015
8,412
Tampa Bay Area
This comes from a *CHAT* with GPT4ALL (Off Line) in response the Question of Arduino Programming Software Options... using your First Post as the conversation starter:

4XRPWPIOA.jpg4XRPWPIOB.jpg4XRPWPIOC.jpg4XRPWPIOD.jpg

Prompt:

Is there any "Free Off The Shelf" Software available for the Arduino category for this OP’s Project?


"I've seen a few folks on this forum experimenting with Arduino-based VPW adapters for interacting with Class 2 messages. I thought I would share one of my own projects, using a $5 Waveshare RP2040 Zero board to implement the VPW protocol using PIO for precise timing:


The main advantage of the RP2040 is that it's fast enough to handle 4X VPW (using PIO) and has plenty of available compute to implement your own logic. I'm using it primarily as an in-vehicle data logger to an SD card, but have another one on my workbench for testing/experimentation.

This code was designed for using a MC33390 VPW transceiver IC (level-shifted to 3.3V for the RP2040) to interface with the VPW bus, but for a DIY workbench scenario (e.g. not in-vehicle) you may be able to get away with just level-shifting 3.3V to 7V without using a transceiver chip."


GPT4ALL Response:

Yes, there are several "Free Off The Shelf" (FOTS) software options available for the Arduino category that can be used with your project. Here are a few examples:

1. **Arduino IDE**: This is the official integrated development environment (IDE) provided by Arduino. It's free and open-source, allowing you to write code in C/C++ and upload it to various micro-controllers, including the RP2040.

2. **PlatformIO**: A popular alternative to the Arduino IDE, PlatformIO supports a wide range of micro-controllers, including the RP2040. It offers features like project management, library management, and debugging tools.

3. **Visual Studio Code (VSCode)**: While not specifically designed for Arduino, VSCode can be used with various extensions, such as the "Arduino" or "PlatformIO" extension, to create and upload code to micro-controllers.

For your specific use case of implementing VPW protocol using PIO on a RP2040 board:

1. **PIO (Programmable I/O)**: As you've already discovered, PIO is a powerful feature in the RP2040 that allows for precise timing control. You can write custom code to implement the VPW protocol.

2. **RP2040 libraries**: The official Raspberry Pi Foundation provides various libraries and examples for the RP2040 board, including ones related to serial communication (e.g., `rp2040-serial`).

Some other FOTS software options that might be useful in your project:

1. **SD card library**: For logging data to an SD card on the RP2040.
2. **GPIO libraries**: To interact with the GPIO pins of the board.

When choosing a software solution, consider factors like ease of use, community support, and compatibility with your specific hardware setup.

As for using just level-shifting 3.3V to 7V without a transceiver chip on your workbench scenario:

1. **Voltage shifting libraries**: You can find various FOTS libraries that provide voltage shifting functionality (e.g., `levelshifter` or `voltage_shifter`) which might be useful for this specific use case.

Keep in mind that using just level-shifting without a transceiver chip may not be the most reliable solution, especially if you're working with high-speed signals like VPW. However, it can work well for low-to-medium speed applications on your workbench setup.

Prompt:

Can YOU write a program in Python3 that would work with this Arduino System?

GPT4ALL Response:


Here's a basic example of how you could write a Python program to interact with the RP2040 board and implement VPW protocol using PIO. This code assumes you're running on a Raspberry Pi or other Linux-based system.

**Note:** This is just an example, and you'll need to modify it according to your specific requirements and hardware setup.

```python

import time

# Define constants for VPW parameters (adjust as needed)

VPW_BAUD_RATE = 9600 # bits per second

VPW_BIT_PERIOD_US = int(1e6 / VPW_BAUD_RATE) # microseconds

VPW_DATA_BITS = [0, 1] # assume binary data

# Define a function to generate the VPW signal using PIO (simplified example)

def generate_vpw_signal(pio):

for bit in VPW_DATA_BITS:

pio.set_high()

time.sleep(VPW_BIT_PERIOD_US / 2) # high pulse

if bit == 1: # only send a low pulse if the data is '1'

pio.set_low()

time.sleep(VPW_BIT_PERIOD_US / 2)

return

# Define a function to read VPW signal using PIO (simplified example)

def read_vpw_signal(pio):

received_data = []

for _ in range(len(VPW_DATA_BITS)):

while not pio.get():

pass

time.sleep(VPW_BIT_PERIOD_US / 2) # wait for high pulse

if pio.get(): # check if the data is '1'

received_data.append(1)

else:

received_data.append(0)

return received_data

# Initialize PIO (simplified example, adjust according to your setup)

import rp2040pio as pio

pio.init()

pio.set_mode(pio.MODE_OUTPUT)

try:

while True:

# Generate VPW signal for transmission

generate_vpw_signal(pio)

# Read VPW signal from the bus (assuming a simple receiver is connected)

received_data = read_vpw_signal(pio)

print("Received data:", ''.join(map(str, received_data)))

except KeyboardInterrupt:

pio.deinit()

```
This code uses the `rp2040pio` library to interact with the RP2040 board's PIO. It defines two functions: one for generating a VPW signal and another for reading it.

Please note that this is a simplified example and might not work as-is in your specific setup. You'll need to adjust the constants, modify the code according to your hardware configuration (e.g., adding transceiver logic), and ensure proper error handling.

Also, keep in mind that using just level-shifting without a transceiver chip may introduce errors or noise into the signal, which can affect the reliability of data transmission.
 
Last edited:

AmpOverload

Member
Jul 10, 2023
175
USA
I've seen a few folks on this forum experimenting with Arduino-based VPW adapters for interacting with Class 2 messages. I thought I would share one of my own projects, using a $5 Waveshare RP2040 Zero board to implement the VPW protocol using PIO for precise timing:

https://github.com/endjuser/rp2040-vpw
A cool project, indeed!

The main advantage of the RP2040 is that it's fast enough to handle 4X VPW (using PIO) and has plenty of available compute to implement your own logic.
I've given almost no thought to VPW 4X mode since I only hear talk about it being used for dumping/programming an ECU. I may experiment more with it at some point in the distant future though.

This code was designed for using a MC33390 VPW transceiver IC (level-shifted to 3.3V for the RP2040) to interface with the VPW bus, but for a DIY workbench scenario (e.g. not in-vehicle) you may be able to get away with just level-shifting 3.3V to 7V without using a transceiver chip.
I wish the MC33390 had been available when I started thinking about implementing a VPW circuit, but I think it's been obsolete/unobtainable now for a long time. I managed to hack Bruce Lightner's circuit (from a cool MPG-gauge project that does VPW comm without a dedicated transceiver) to great effect in my own little project.

I'm using it primarily as an in-vehicle data logger to an SD card, but have another one on my workbench for testing/experimentation.
I've been using my circuit mostly for a VPW-protocol vehicle simulator (frequently coupled with Tech2Win and a VXDIAG VCX Nano), but I'd also started using a 2nd circuit (same exact hardware but with different ATMega328 firmware) as a scantool, with the idea of doing exactly what you've done -- a data-recording scantool. That project was going well, working fine as a scantool but without having yet implemented the actual SD-card recording. But I had to shelve it several months ago for more pressing activities, hopefully to be resumed within a few months.

I've considered abandoning the Atmel/Microchip MCUs for something better, but I've got a lot of "investigative homework" to do first and no time to do it! But RP2040/RP2350 will probably be one of the contenders, so I appreciate you sharing your project and wish you luck with it!
 
  • Like
Reactions: TJBaker57

endjuser

Original poster
Member
Jul 7, 2020
12
PA
I wish the MC33390 had been available when I started thinking about implementing a VPW circuit, but I think it's been obsolete/unobtainable now for a long time. I managed to hack Bruce Lightner's circuit (from a cool MPG-gauge project that does VPW comm without a dedicated transceiver) to great effect in my own little project.

That's a great idea to have a hardware simulator!

I imagine you could use similar circuitry to interface the RP2040 with the VPW bus. Essentially the only thing the MC33390 is doing is overvoltage/short protection and wave shaping (rounding the edges) of the output from the microcontroller to reduce ringing on the bus. The PIO input/output is standard J1850 VPW (but at 3.3V)

I've got a software-based simulator that's part of a web-based VPW analysis tool I've been working on for bench testing. I wrote it before I made the RP2040 adapter, so at the moment it uses two cheap ELM-compatible adapters and an OBD2 Y-splitter (one for read and one for write) for comms. Essentially it starts by reading all the blocks/PIDs/DPIDs/memory from a module and saves that to a JSON file for later use. Then I can monitor the VPW bus and simulate the saved device(s). I have a (very ugly) screen full of text boxes that highlights which PIDs/blocks are being requested (e.g. when I have a Tech2 plugged in on a data screen) and I can change the values in real time.

Once I finish my research into functional messages, I'm planning to re-write the useful parts of that tool, along with its VPW decoder, into a public webpage so anyone can use it.
 

Attachments

  • simulator.png
    simulator.png
    88.4 KB · Views: 5

AmpOverload

Member
Jul 10, 2023
175
USA
I've got a software-based simulator that's part of a web-based VPW analysis tool I've been working on for bench testing. [...]
Very nice! :thumbsup:

I too have a software simulator, but it's considerably different than yours. (I don't typically mention it here because it's far less relevant on this site than my hardware sim.) To any communicating app, it basically looks like a serial port that it can open and talk to a (fake) scantool. I can simulate any of several vehicles and any of several scantools, all in the software. I've used that software sim far longer than my hardware sim and it's been invaluable over the years in learning OBD2 stuff. But there's no GUI -- it runs in a console window, with user-typed commands to control it, so it's not very user-friendly. I've thought about "GUI-fying" it, but that day will probably never come.

When I started using a VXDIAG VCX Nano and the Tech2Win & GDS2 software that came with it, my hardware sim opened up a whole new world to me, for the GM vehicles.

But lately I've been spending more of my free time on Ford/Lincoln/Mercury, so I may have to work on a J1850-PWM sim next! And I just bought a 3D printer, so I'm learning all I can, with a plan to print some custom cases for my various circuits. So many projects & ideas, so little time! :smile:

I will definitely have to take a closer look at the RP2040 (etc). Thanks for your input -- very interesting stuff!
 

Forum Statistics

Threads
23,814
Posts
643,704
Members
19,550
Latest member
reikahrob

Members Online