home..

Week 13 - Networking and Communications

group page // repo source files // objectives

Contents

…It’s the end of class (soon!)

hero shot >

objectives >

sequence >

flavor text >

This past week was a bit busy. I:

And of course, switched my final project with about a month left to go. Woohoo.

Needless to say, I wasn’t able to spend as much time on this weeks assignment. Fortunately, I think(?) it satisfies requirements.

actual project - urumbu peripheral >

In this project, I used my previous work from the machine week to demonstrate serial networking between devices via USB. I modified Neil’s Urumbot code to send additional single char commands to my previous muxed LED board, which is distinct from a stepper or servo.

I had 3 separate USB devices on a single bus (addressing).

background - USB and serial >

Universal Serial Bus (USB) protocol.

At its most basic implementation, power is delivered via a pair of power lines, +5V and Ground.

The USB protocol communicates via a pair of differential serial lines, Data+ and Data-, which can be shortened to D+ and D-. The wires carrying these signals are typically twisted to reduce noise and crosstalk.

Differential signaling: a method of electrical communication where two signals are sent, the original signal and complementary signal (opposite polarity but equal magnitude). The receiving end subtracts the two signals, which results in a signal double the magnitude of the original (eg A - (-A) = 2*A).

Differential signaling has a couple of advantages, but the main one is elimination of common-mode noise; eg noise that is affects the pair equally will be cancelled out when the two signals are subtracted from each other. Combined with the doubled signal voltage, this enables running longer cables.

USB serially communicates, synchronously. Although there isn’t a clock line, clock information can be recovered from the data pair itself by the receiver.

Serial communication is communication via sending data sequentially (one bit at a time), rather than in parallel (multiple bits at a time, each with their own lanes). Serial is typically superior in performance because crosstalk is less of an issue and various budgets (power, physical footprint, etc.) are less divided over multiple lanes.

background - USB continued >

Paraphrasing from the wikipedia article, USB is an “industry standard” that encompasses cables, connectors, and protocols to deliver power and data between computers and peripherals.

It’s a bit wordy, but that’s because the USB specification gets a lot more complicated than just the basic implementation. Just look at the pinout for a USB-C connector:

background - USB addressing >

The “Bus” portion of Universal Serial Bus enables up to 127 devices to be connected to a single host controller.

programming >

The Urumbu machine architecture uses single char commands to control peripheral devices, specifically the stepper motor. It accepts ‘f’ or ‘r’ for forward or reverse, respectively.

I added ‘y’ and ‘n’ for ramp up and ramp down led behaviors on my muxed led board, and modified my led board code to listen for serial commands, similar to how the stepper motor driver boards do.

In the Urumbot python code, I modified the code such that a motor event on either port0 or port1 would result in a write to the led board. The result isn’t very pretty (motor events occur waaaay faster than the led animations so the board is quickly saturated with commands), but it gets the point across.

baud rate >

The nano and the esp32 appear to have different acceptable baud rates. I haven’t dug into this too much yet (planning on swapping over to samd11c boards, so although interesting hasn’t been a priority), but I wasn’t able to talk to the nano at 921000 baud, while I could for the esp32.

The quick fix was to set all of the boards to 115200, a baudrate which all the boards can communicate at.

I should note that in order to make the nano’s work with the urumbu python program, I had to change from serialusb calls to serial, as is typical for your run of the mill Arduino board (Uno, Nano, etc.). This hackaday article notes the difference between serial vs serialusb. The article is worded a bit confusingly, but it notes that the serial library is used for devices that have a usb-to-uart chip, while serialusb is used for devices that have a built-in USB peripheral.

Not surprisingly, the devices w/ the USB peripheral are capable of much higher speeds.

© 2023 Alan Han   •  Powered by Soopr   •  Theme  Moonwalk