Setting Linux serial baud rate higher than 4 megabaud - linux

Super long story short: is it possible to read from a UART at something close to 12 megabaud?
I have a high speed connection that I am trying to read from on a Raspberry Pi. At present, the Raspberry Pi (and as far as I can tell, the world of serial programming) has a maximum baud rate of 4 Mbaud, which I achieved by setting the Raspberry Pi's UART clock to 160 MHz.
However, I need a UART running at 12+ Mbaud to capture the data streaming in from my external source. The Raspberry Pi's terminos.h file specifies 4 Mbaud as the max baud rate for serial communication. Is there a way to get higher baud rates? Is the key ioctl from How can I set the baud rate to 307,200 on Linux??
Raspbian 3.6.11, Raspberry Pi rev2

Each UART has a hardware limit... If your hardware supports this rate, it's allowed... Verify it before.

Related

Delays in serial communication with pyserial

I'm seeing ~15ms of overhead when communicating with a microcontroller over RS-485 with a USB-to-serial converter, is there any way to minimize this overhead?
I have some debug and data collection python3.10 scripts that connect to a microcontroller via either USB or half-duplex RS-485 serial. I'm using PySerial in both cases and I am either passing it the address for the USB-to-serial converter to the controller directly (running on MacOS). Today I logged how long a command and response takes to execute at different RS485 baud rates (median of 1000 command/response cycles, min time is similar):
9600 baud - 32 ms
38400 baud - 16 ms
115200 baud - 16 ms
230400 baud - 16 ms
500000 baud - 16 ms
USB - 1 ms
I have scoped the signal # 115200 baud and the command + response takes 3ms max, so I while I would like this micro to burn in a pit I don’t think I can blame this particular problem on it. Since all my code is shared between the serial and usb tests, I'm left to believe that the majority of the overhead is coming from pyserial or my d-tech usb-to-serial converter.
From what I’ve seen a large number of the usb-to-serial adapters use the same FTDI chipset, so I’m not sure if I would actually get any improved performance by blindly choosing another converter. If someone knows better here please chime in.

How to get a UART communication at 12 Mbps in linux (Raspbian)?

I am currently working on a Raspberry pi (Jessie Stretch), the issue is that I want to connect two FTDI FT2232H serially at 12 Mbps, but because 12Mbps is not a standard speed Raspbian does not allow me to add that baud rate. I would like to know if someone has transmitted at that speed or if someone knows how to achieve the Bit rate of 12 Mbps with the maximum baud rate in Raspbian (4,000,000) .
PS: I changed the UART clock to 64,000,000, modified the "termbits.h" library and created termios structures, but nothing worked.
Thanks.
The data sheet for the FT2232H does advertise it supports 12 Mbaud (not 12Mbps). But it looks like it comes in different modules with support for RS232, RS422, and RS485. The most typical being RS232.
I've never heard of anyone operating a RS232 connection at 120000000 baud. The typical maximum that almost everything supports is 115200. The highest I've seen is 921600. Typical RS232 cables started running into interference issues at the higher baud rates.
I suspect the 12Mbaud spec is for RS422/RS485 operation which requires different cabling and is designed for higher speeds.
If you're using an FT2232H with RS232, the speeds you're looking for are likely unrealistic. If you're using it with RS422/RS485 you can probably get there, but it will be a much more specialized endeavor. It does look like Linux does support RS485. But there's not nearly as much documentation out there as for RS232.
Can you provide any more information about the USB adapters you're using?

I2C and Serial communication between devices

I am using python sockets to connect to a bluetooth HC-05 module with my PC. I want to send music to the HC-05 by converting a wav file to a string array which will later by converted to integers ranging from 0-65535 on an arduino. The arduino and HC-05 communicate via serial at 9600 baud. Then those ints will be passed into a DAC via I2C. I am wondering if there could be a memory issue sending an enormous number of strings from my PC. Is it possible the original quality of the sound will be distorted as a result of the different rates of sending/receiving data across the devices? Or will the sound signal just be delayed on the DAC?
The arduino and HC-05 communicate via serial at 9600 baud.
This is going to be too low to be usable for audio.
9600 baud gives you 7680 bits of data per second. At 16 bits per sample, you're looking at a sample rate of 481 Hz, which is too low for intelligible audio. It's barely even high enough to reproduce sound at all.
You need to:
Increase the baud rate. Ideally you'll want at least 57600 baud, for 46 kbit/sec of data. If higher baud rates are available, use them.
Use fewer bits for each sample. Using 4 bits for each sample at 56 kbaud will give you a respectable sample rate of 11.5 kHz. The audio will sound a little tinny at 4 bits, but it'll be intelligible.

How to use a MCP23017 with MCP3008 for I2C voltage sensor with Raspberry Pi?

I would like to know if is possible to use an MCP23017 16 bit I/O expander with a MCP3008 ADC and read the voltage with a Raspberry Pi 2. I want to use the ADC as an I2C device. I would like to do this so I don't have to run the program a 'root', so I'm thinking that running the ADC as an I2C device will fix this problem. I'm looking for help with how to wire the system as well as programming it. I'm using the Python 3 editor. The existing program I have will be used to plot a sine wave generated by a AD9850 DDS module who's signal is amplified and fed into a device. I want to measure this voltage. I know how to use a voltage divider, but am having trouble coming up with a way to read it. The measured voltage value needs to be stored as global variable that can be passed around the program. Right now I'm mainly concerned with not running the program as a root, turning the ADC into an i2c device, and storing the voltage as a global variable to be passed around in an existing program.
I have not worked with any kind of I2C TO SPI converter. Still, you can use some I2C to SPI bridges if they work, I just googled it, but that can cause wiring problems.
I can suggest you the same ADC MCP series with I2C interface.Thus, the further I2C connections with MCP23017 expander and then the Raspberry pi would be easy.You can go through various analog to digital converters that can be I2C interfaced with their codes in python or java for pi like MCP3425, MCP3426, MCP3427, MCP3428. You can easily find them or also check control everything as that would be easy to interface using I2C cables and adapters preventing connection or wiring problems.For codes: https://github.com/ControlEverythingCommunity?utf8=%E2%9C%93&query=MCP34
The following codes for MCP_23017 can also help you code the way you want easily with expander being connected to pi:https://github.com/ControlEverythingCommunity/MCP23017_16-Channel.
I think this would solve your problem!!
Thanks.

How would I control the output of the power in USB ports in Linux?

I built a robot from a thin client pc (can run Windows CE or Linux) and two servo motors. I put USB ends on the servo motors, so when they are plugged in to the thin client they continuously run. In Linux, how could I set the amount of current or voltage going from the USB ports to the servo motors? Would I be able to run a shell script to set the power of a certain USB port to slow down a motor or stop one? If this cannot be done through software, what is the easiest way to do this through hardware without having to buy too much?
The USB voltage is fixed at a nominal 5 volts and cannot be controlled.
The behavior of USB devices regarding their current draw is well defined in the USB specifications. USB devices are supposed to draw up to 1 unit load (100mA) unless they have negotiated a higher load from the USB host. It's quite likely that the servo motors that you have are going to need to draw higher currents than that, and wouldn't be able to request it without being a USB device and negotiating with the host.
It's also likely, depending on the servo motor that you are trying to control, that you'll need to either provide a PWM signal or an analogue voltage to control motor position. USB hosts are not intended to provide either of these.
Your best options to drive your motor from your PC are:
Get a dedicated USB controller for your servo motor (if one exists)
Make your own, based on a small microprocessor (eg. using an arduino)
Choose a different port on the PC. If available, PC parallel ports can be controlled to provide control for motor drivers.
The answers here seem to say it is a hardware issue, but I think this is a software issue. ASUS has Ai Charge which more then doubles the volts to charging Apple products from a standard 2.0 usb port.
USB 1.0, 2.0 and 3.0 Specs (All at 5 volts) 4 Wires (2 Data and 2
dedicated power)
Voltage Breakdown: USB 1.0 and USB 2.0 = 0.5A or 500 mA = 2.5 watt
USB 3.0 = 0.9A or 900mA = 4.5 watt Wall wart = 1.5A or 1500 mA = 7.5
watt Ai Charge = 1.2A or 1200mA = 6 watt
Ai Charge works on ASUS and non-ASUS motherboards and is a program you can install in Windows.
Personally I HATE Apple so I want to figure out a way to do this 1.2A usb 2.0 output trick for my netbook while running Linux.
I don't believe it is possible to directly manipulate the USB voltages. They are designed to provide a +5V output at all times unless power is diminised with other hubs.
You might be better served posting this question on http://electronics.stackexchange.com
you need to use PWM to control motors speed, to do that you need a micro controller, PIC18F series supports USB communication, there are plenty of code samples available internet how to use USB in PIC18F series, also you need a transistor array or H-Bridge to control mortors from PIC.
The simplest way to communicate is, program a USB serial in PIC18F micro controller, and when you plug that 18F to your computer, it will detect USB serial port, so you can send the commands to serial port to control speeds.
I dont think its possible, and even if it was, consider this: The USB port is not suposed to power motors because you can burn the USB port. USB is limited to 500mA (or there abouts) and any power device like a motor can potentially require more than that.
Another thing is that servos should be driven with constant voltage, and the speed is controlled by timing impulses on the control wire.
http://en.wikipedia.org/wiki/Pulse-width_modulation
You should use a driver (hardware) to power the motor with an external power source.
This is transistor's purpose, or try with a potentiometer

Resources