Connecting USBA pigtail cable to ESP32-S3

Hi there,

I have a ESP32 S3 ETH, details can be found here: https://www.waveshare.com/wiki/ESP32-S3-ETH

Futhermore, I have a USB-A pig tail cable with 4 wires (V+/red, GND/black, Data+/green, Data-/white).

The pinout of the board can be found here: https://www.waveshare.com/wiki/File:ESP32-S3-ETH-details-15.jpg

Can somebody tell me, how to connect these two things to be able to create a bridge to a rs232(J1939) device?

My suggestion is to put V+ (red) on VBUS-pin, GND (black) to a GND-pin. Do I have to use GPIO43/44 for Data+ (green) and Data- (white) or doesn’t it matter?

The second aim is to use then a USB-A-To-RS232 cable to connect to a RS232-device and receiving data based on SAE J1939. Does anyone have any experience with this kind of chain?

Pictures are preferably posted here.

Links to datasheets are prefered, not links to sales sites.

Please give it time and read: How to get the best out of this forum - Projects / General Guidance - Arduino Forum

Corrected. Hopefully I found better links, which describes technical details better …

The picture remains.

Please provide a link to this component also.

And a link to this component.

I suspect, based on the little information you have given, that for this idea to work, the ESP32 board would need to act as a USB Host. I didn't see anything on the links that says the board has that capability. So it can probably only act as a USB Peripheral Device, not a Host.

But this seems to be an unnecessarily complex way to achieve your bridge idea. You could simply use an RS232 to TTL-UART/serial adapter and connect that directly to the ESP32's pins. The ESP32 has at least a couple of unused UARTs that can be configured to use almost any pair of pins on the ESP32.


Make sure the RS232 to TTL adapter you get will work with 3.3V to match the ESP.

J1939 is CAN not RS232

You need a TTL to CAN converter that can work at 3.3V

Based on my lack of knowledge, I would like give some more information.

Given is actually a control cabinet, which should information of fuel rates and technical information. In this context, the following document was given to me ( I found the online version here): The interface document .

Based on page 3 the incoming data are based on CAN with protocol SAE J1939.

Furthermore I was able to get a picture of the “hardware” connection. It looks like a 9pin RS232.

My target is to receive data from this connection to a microcontroller (ESP32) - actually it doesn’t matter how. So, if there is an easy way to do it (without the USB-A cable), I would like to follow it …

It look like a 9 pin DB9 female connector. I see no mention of RS232 anywhere in the document. Since the document states CAN I would assume it is indeed CAN.

So as I said, you will need a TLL to CAN converter to connect it to an Arduino or a CAN to USB to connect to a PC/Laptop

Thanks for the explanations.

So, would this here the correct product I need (the same like PaulRB mentioned)? MAX3232 Converter Module 232 to TTL Serial Port Board Connector, RS232 to TTL Converter Module, for Serial Interface DB9 Connection 3.3 V to 5 V MAX3232 Root Module Pack of 4 : Amazon.de: Electronics & Photo ?

And then do I have to just connect

  • VCC → ESP32 board V3.3
  • GND to ESP32.GND
  • RXD to ESP32.UARTTX (GPIO43)
  • TXD to ESP32.UARTRX (GPIO44)

Would this be correct?

clarify if bridge is RS232 or J1939

if J1939 the ESP32-S3 has an onboard CAN interface - see Two-Wire Automotive Interface (TWAI)
if only requires an external CAN transceiver such as cjmcu-1051

Apparently you did not understand. CAN is NOT RS232
As I said you need something to convert CAN to TLL or USB.
RS232 is not involved

the ESP32-S3 ETH Development Board has an onboard USB type C connector
why do you need to connected the USB-A pig tail cable ?

I need the USB-C for power supply for the board itself.

USB-A was just an idea. The main target is to connect the DB9 (?) female connector to the board and consume the CAN/J1939 data.

See post #6 8 and 11

What don't you understand?

could you power the board directly via the 3.3V pin or even use POE

some CANbus interfaces use 9 pin D-type connecters like RS232

they are totally different interfaces

First you need to understand CAN
Start here
https://docs.arduino.cc/learn/communication/can/

I still dont get the clue, how to bridge the DB9 to the board. It seems that products on amazon uses RS232 and DB9 as a synonym.

Could you give/show me links to products, that are useful to make this bridge?

using the ESP32 TWAI library to connect a ESP32S3 ETH module to canbus via a CJMCU-1051 CAN transceiver

code

// ESP32S3 ETH TWAI-CAN library using a cjmcu-1051 CAN transceiver
//  adapted from  File>Examples>ESP32S3-TWAI-CAN>OBD2-querry

// to enable serial monitor - USB CDC on boot: enabled

// ESP32S3-TWAI-CAN library
//     

// cjmcu-1051 CAN transceiver wiring
//     https://www.circuitstate.com/tutorials/what-is-can-bus-how-to-use-can-interface-with-ESP32S3-and-arduino/

// ESP32S3 GND    cjmcu-1051 GND
// ESP32S3 5V     cjmcu-1051 VCC powers transceiver
// ESP32S3 3.3V   cjmcu-1051 VIO powers logic
// ESP32S3 GPIO16  cjmcu-1051 CTX
// ESP32S3 GPIO17  cjmcu-1051 CRX
// ESP32S3 GND    cjmcu-1051 S   HIGH = TRX off, LOW = TRX on


#include <ESP32-TWAI-CAN.hpp>

// Simple sketch that transmits and receives CAN frames
// Showcasing simple use of ESP32-TWAI-CAN library driver.

#define CAN_TX 16
#define CAN_RX 17

CanFrame rxFrame;

// transmit a test frame
void sendObdFrame(uint8_t obdId) {
  static byte data = 2;  // test value - increment every frame
  CanFrame obdFrame = { 0 };
  obdFrame.identifier = 0x7DF;  // Default OBD2 address;
  obdFrame.extd = 0;
  obdFrame.data_length_code = 8;
  obdFrame.data[0] = data;
  obdFrame.data[1] = 'T';
  obdFrame.data[2] = 'W';
  obdFrame.data[3] = 'A';  // Best to use 0xAA (0b10101010) instead of 0
  obdFrame.data[4] = 'I';  // CAN works better this way as it needs
  obdFrame.data[5] = 0;  // to avoid bit-stuffing
  obdFrame.data[6] = 0xAA;
  obdFrame.data[7] = 0xAA;
  // Accepts both pointers and references
  ESP32Can.writeFrame(obdFrame);  // timeout defaults to 1 ms
  data++;                         // increment for testing
  Serial.printf("Transmit frame: %03X: ", obdFrame.identifier);
  for (byte i = 0; i < 8; i++)
    Serial.printf(" 0x%.2X", obdFrame.data[i]);
  Serial.printf("\n");
}

void setup() {
  // Setup serial for debbuging.
  Serial.begin(115200);
  delay(3000);
  Serial.println("\n\nESP32S3-TWAI-CAN Send/Receive test -  Initialize");
  // Set pins
  ESP32Can.setPins(CAN_TX, CAN_RX);
  // You can set custom size for the queues - those are default
  ESP32Can.setRxQueueSize(5);
  ESP32Can.setTxQueueSize(5);
  // .setSpeed() and .begin() functions require to use TwaiSpeed enum,
  // but you can easily convert it from numerical value using .convertSpeed()
  /*ESP32Can.setSpeed(ESP32Can.convertSpeed(250));  //500));
  // You can also just use .begin()..
  if (ESP32Can.begin()) {
    Serial.println("CAN bus started!");
  } else {
    Serial.println("CAN bus failed!");
  }*/
  // or override everything in one command;
  // It is also safe to use .begin() without .end() as it calls it internally
  if (ESP32Can.begin(ESP32Can.convertSpeed(125), CAN_TX, CAN_RX, 10, 10)) {
    Serial.println("CAN bus started!");
  } else {
    Serial.println("CAN bus failed!");
  }
}

void loop() {
  // transmit data when space entered on keyboard
  if (Serial.available()) {
    if (Serial.read() != ' ') return;
    sendObdFrame(5);  // For coolant temperature
  }

  // frame received?  You can set custom timeout, default is 1000
  if (ESP32Can.readFrame(rxFrame, 100)) {
    // print frame contents
    Serial.printf("Received frame: %03X: ", rxFrame.identifier);
    for (byte i = 0; i < 8; i++)
      Serial.printf(" 0x%.2X", rxFrame.data[i]);
    Serial.printf(" %s\n", (char *) &rxFrame.data+1);
  }
}

test run with ESP32S3 ETC connected to a UNO and ESP32 via canbus
ESP32S3 ETH serial output

ESP32S3-TWAI-CAN Send/Receive test -  Initialize
CAN bus started!
Transmit frame: 7DF:  0x02 0x54 0x57 0x41 0x49 0x00 0xAA 0xAA
Transmit frame: 7DF:  0x03 0x54 0x57 0x41 0x49 0x00 0xAA 0xAA
Received frame: 100:  0x55 0x4E 0x4F 0x20 0x20 0x30 0x00 0x00 NO  0
Received frame: 100:  0x55 0x4E 0x4F 0x20 0x20 0x31 0x00 0x01 NO  1
Received frame: 100:  0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
Received frame: 100:  0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
Transmit frame: 7DF:  0x04 0x54 0x57 0x41 0x49 0x00 0xAA 0xAA

UNO with Canbus shield serial output


CAN MCP2515 shield Send/Receive test - MCP2515 Initialize
Entering Configuration Mode Successful!
Setting Baudrate Successful!
CAN Receive - MCP2515 Initialized Successfully!
MCP2515 Library CAN Send/Receive Example
 enter space to send a frame
Standard ID: 0x7DF       DLC: 8  Data: 0x02 0x54 0x57 0x41 0x49 0x00 0xAA 0xAA TWAI
Standard ID: 0x7DF       DLC: 8  Data: 0x03 0x54 0x57 0x41 0x49 0x00 0xAA 0xAA TWAI
0x55 0x4E 0x4F 0x20 0x20 0x30 0x00 0x00 UNO  0 Message Sent Successfully!
0x55 0x4E 0x4F 0x20 0x20 0x31 0x00 0x01 UNO  1 Message Sent Successfully!
Standard ID: 0x100       DLC: 8  Data: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Standard ID: 0x100       DLC: 8  Data: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Standard ID: 0x7DF       DLC: 8  Data: 0x04 0x54 0x57 0x41 0x49 0x00 0xAA 0xAA TWAI

ESP32 TWAI

ESP32-TWAI-CAN Send/Receive test -  Initialize
CAN bus started!
Received frame: 7DF:  0x02 0x54 0x57 0x41 0x49 0x00 0xAA 0xAA TWAI
Received frame: 7DF:  0x03 0x54 0x57 0x41 0x49 0x00 0xAA 0xAA TWAI
Received frame: 100:  0x55 0x4E 0x4F 0x20 0x20 0x30 0x00 0x00 UNO  0
Received frame: 100:  0x55 0x4E 0x4F 0x20 0x20 0x31 0x00 0x01 UNO  1
Transmit frame: 100:  0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Transmit frame: 100:  0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Received frame: 7DF:  0x04 0x54 0x57 0x41 0x49 0x00 0xAA 0xAA TWAI
Received frame: 100:  0x55 0x4E 0x4F 0x20 0x20 0x32 0x00 0x02 UNO  2

photo of setup

the CANH (orange wire) and CANL (grey wire) going out of the top of photu would go to your 9 pin D-type connecto

Read the information in the link I provided.

This is true about almost the whole world. RS-232 only, ever, defined 25 pins for a connection and NEVER defined a physical connector, either 9 pin or 25 pin. That was always left to the manufacture of the device.