RP2040-based VPW adapter

endjuser

Original poster
Member
Jul 7, 2020
11
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.
 

mrrsm

Lifetime VIP Donor
Supporting Donor
Member
Oct 22, 2015
8,390
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:

Forum Statistics

Threads
23,799
Posts
643,534
Members
19,495
Latest member
DanFlesch

Members Online