2

I want to run weewx on a raspi zero 2 w. I want an RTL-SDR radio dongle and an arduino uno to communicate with the raspi02w over two usb connections. If I replaced the raspi zero 2 w with a raspi 4 I think I could do this simply by using the raspi 4 host usb ports (not the usb-c). On a computer for the arduino connection I use ttyUSB0. Before I resort to using a raspi4, to keep the heat in the case lower, is it feasible with the zero 2 w?

  • The micro usb connector on the zero 2 w is a host for devices like keyboards and mice. I found out I can attach the arduino to it and use it as ttyUSB0. Will try to see if it works for RTL-SDR also.
  • The console cable is supposed to be attached to 5V,GND,TX,RX so can I attach the arduino to it (use it like ttyUSB0)?
  • How do I set up the console cable as a serial port (use it like ttyUSB0)?
  • what device is it? ttyGS0, ttyGS1?
  • Can the console cable provide power downstream?

So far I think how you set up the serial ports is: in /boot/config.txt include at end

enable_uart=1
dtoverlay=dwc2,dr_mode=host
dtoverlay=disable-bt

note the dr_mode=host. In cmdline.txt it looks like I need something like: after rootwait, add space, then modules-load=dwc2,g_serial.

I planned to have the other physical usb power plug (the one on the corner of the zero2w for power ONLY not the two usb data connections) connected at the same time to power the arduino, the RTL-SDR AND the zero2w. Before I try this, adafruit said in their writeup for the "usb gadget" (usb serial console) raspi setup, you should never hook up the 5V to the console cable at the same time as using the dedicated usb power plug in the corner of the board. If you tell me this is safe I will try it then I can report back. I expect that since the two data usb ports supply power downstream (instead of receiving power from upstream as in the adafruit console example), I should be okay. Is this correct?

UPDATE: amazing information goldilocks, THANKS :-). So far: I plugged the built-in usb port on the raspi02w (the data plug as opposed to the power plug) into the arduino without an OTG cable or anything and it was immediately recognized as ttyUSB0. Just to be clear the raspi02w is the usb host and the arduino is the peripheral. To test my raspi code I type "stty -F /dev/ttyUSB0 raw; cat /dev/ttyUSB0" and the serial output from the arduino appears ... that's what my weewx driver on the raspi requires so THE FIRST USB CONNNECTION WORKS with ZERO configuration.

As for the RTL-SDR what I need is to plug it in to a second raspi USB port. The RTL-SDR driver is called rtl_433. In the meantime I will try to figure out what this driver needs other than just a "USB port". What I have is an adafruit "CONSOLE CABLE" with TX/RX/GND/5V jumpers on one end and USB-A-male on the other like the one pictured below. I am not sure what this exactly is but you can connect from a computer to the raspi when the console cable is connected to TX/RX/GND. The 5V connection would provide power downstream from computer to raspi and is meant to be used if the usb power plug on the raspi is disconnected. I am certainly confused.

What it looks like is that I stupidly assumed that since the "CONSOLE CABLE" has a USB-A-MALE plug it is the same thing as a usb port. I expect that it is not.

The raspi USB data plug (not the power plug) REALLY IS a usb port with a usb controller, so I should try putting the RTL-SDR on that instead and put the arduino on the console cable connected to (TX/RX/5V/GND). At this point, will this console cable enable me to do this and how?

6
  • "so can I use it like ttyUSB0?" As per my answer I think this hinges on a misunderstanding of what ttyUSB0 is, which in turn makes this part of your question confusing. You need to explain in explicit detail what you mean by that. It's implicit you mean you want to plug in a USB device. Which one? And if so, how would you intend to connect that to 5V/GND/tx/rx instead?
    – goldilocks
    Commented Aug 7, 2022 at 14:36
  • "assumed that since the "CONSOLE CABLE" has a USB-A-MALE plug it is the same thing as a usb port. I expect that it is not." -> Nope, that's the crux of my answer (added a bit to make it plain). This is why there are male and female USB A jacks, so you do not try and plug a master into a master. It isn't a symmetric protocol (like UART, where neither side is a "master" or "host") and why you should never, ever, regardless of what kind of cable you find or create, plug one computer into another via their host ports. Hosts provide power downstream, both sides doing this can be bad.
    – goldilocks
    Commented Aug 7, 2022 at 15:42
  • Yes I understood that part about host-to-host usb connections and power. The way I have it now the power source is on the usb power connector on the raspi and the usb data and console cable are both downstream ... so I guessed right and you answered that question !! Commented Aug 7, 2022 at 15:58
  • I expect this means that I can't use the arduino as a peripheral since the console cable expects the raspi to be a peripheral connected to a computer host. So how else could I do it, connect the TX/RX from arduino to raspi directly? Commented Aug 7, 2022 at 16:09
  • yeah "shimmy" is the word here. just getting the cable into the case was hard enough. more gender changers and 90 degree plugs than you can imagine. what you said makes sense now. Commented Aug 7, 2022 at 16:14

3 Answers 3

0

equivalent on a computer is ttyUSB0

ttyUSB0 is just a name used by the kernel (or udev) when a USB serial converter is attached, and it works like a normal serial port (which USB is just a beefy, complexified version of).

By analogy, if you plug a USB mouse in, you will get a /dev/mouse0 (or /dev/input/mouse0 or some such). Instead, this could be called the more informational /dev/mouseUSB0, orthogonal to /dev/ttyUSB0, but it is not a USB port, nor is it used like a USB port. It's a mouse. The same thing is true of ttyUSB0: It isn't a USB port, and it isn't used like one. It's a device plugged into a USB port.

If you are used to the world of Arduino and other things that can be connected from a mini-USB to a USB-A host, this may be a bit confusing because it seems that this is just USB connection. It isn't. The Arduino implements a USB-serial device, meaning that's the user protocol in play: normal UART (serial bus). It is exactly the same as if you had just connected 5V/GND/rx/tx from the Arduino to the same on the Pi: No USB involved, exact same style port.

The console cable is supposed to be attached to 5V,GND,TX,RX so can I use it like ttyUSB0?

Not, I think, in the sense you are thinking. To reiterate the last point: ttyUSB0 is not a USB port. It represents the other end of the serial cable. For a normal converter (see below), this is the set of four wires which constitutes a normal serial port (5V, GND, tx, rx).

It's not clear what you have in mind here, vis. connecting to something to this and using it "like ttyUSB0". What are these four wires you want to plug in from?

How do I set up each usb port as a serial port?

You need a USB to serial cable. There are actually different forms of these as "serial bus" broadly can refer to various not directly compatible things, eg. USB to RS232 is "USB to serial" but it is not a normal UART port.

This is a USB to serial UART cable:

enter image description here

You would also need a logic level converter, since the Pi's UART logic level is 3.3V, not 5V.

But...

IMPORTANT! Do not take this to mean you could attach the four wires to the Pi's UART pins and use the other end as a USB port somehow -- you can't (not least because it is a male connector, by "somehow" I mean, don't try and shimmy something on there to make it female).

1
  • There are USB serial cables which work with 3v3.
    – NomadMaker
    Commented Aug 8, 2022 at 0:57
0

Your question is far from clear.
You CAN setup the Pi Zero in gadget mode using dwc2 to emulate a serial or Ethernet device (I have never used this as I don't have a Pi Zero or any of its family and frankly don't see the point as real Pi are not much dearer and better).

dtoverlay -h dwc2
Name:   dwc2

Info:   Selects the dwc2 USB controller driver

Usage:  dtoverlay=dwc2,<param>=<val>

Params: dr_mode                 Dual role mode: "host", "peripheral" or "otg"

        g-rx-fifo-size          Size of rx fifo size in gadget mode

        g-np-tx-fifo-size       Size of non-periodic tx fifo size in gadget
                                mode

You can use the inbuilt serial port on pins 8,10 (provided you enable serial in raspi-config) and connect a compatible serial device to these pins.

You can connect a USB serial adapter to the USB port.

Whatever you do on the USB port and pins 8,10 are totally independent.

Your question mentions Pi Zero2 W & Pi4 - these are different animals with different characteristics.

1
  • "Your question is far from clear." -> True enough, so to be clear about something that might otherwise be a subtlety: By my reading the OP isn't interested in gadget mode/using the Pi Zero as a USB slave, they want to plug a USB serial converter into the USB-C connector -- I don't have a Zero 2, but I presume this plays the same role as the micro USB on the original, ie., normally used as a mster, which is what is needed for a USB serial converter.
    – goldilocks
    Commented Aug 7, 2022 at 13:55
0
  • the RTL-SDR expects to be on a USB plug with a USB controller. we already have one usb data port on the raspi so it has to use that.

  • the console cable expects the jumper to be on the peripheral and the USB-A plug to be on the usb host. since the raspi is the host, and we can not use the console cable with jumpers on the arduino, the console cable is of no use.

  • solution 1: connect raspi and arduino directly using TX/RX pins on each.

  • solution 2: connect raspi to a hub and plug arduino and RTL-SDR into hub.

  • solution 3: get a raspi4b with two usb ports and plug in arduino and RTL-SDR.

I hope cross-listing is not discouraged. Please see: [https://forums.raspberrypi.com/viewtopic.php?t=338520]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.