How to set the volume of a USB soundcard? - usb

I am a total newbie when it comes to programming or even talking directly to drivers. The thing I want to do is hooking up my Raspberry Pi with a 5.1 external USB-soundcard. I would really like to use the Creative Sound Blaster X-Fi Surround Pro for that but Creative only provides Windows drivers. Which basically means I will have to write my own driver. While I assume that it will be quite easy to do the audio playback (I have done a fair amount of audio processing in my life) I don't have a clue how to set the USB card volume. I am honestly mostly irritated that the Sound Blaster has its own external volume control (which is the main reason for me to use it). Just applying a simple gain factor on the bit stream would be really easy.
My question is: Could it be that I would have to just set the system volume and that the volume control on the sound card just transfers values to the USB host which I then would have to make sense of?
In case you do not know the Sound Blaster card, would that be the standard way of doing things?

I have the same soundcard and am doing the same thing with the Raspberry Pi. The command you're looking for is:
$ alsamixer
This will open up a terminal-friendly GUI for modifying the audio output volume. You should see the Raspberry Pi onboard audio driver BCM2835 and associated devices alongside your USB audio.
Alternatively, you can set the volume with a simple amixer command:
$ amixer -c 0 set Master 100%
which sets the volume of card 0 to 100%.
It's more than likely that the USB soundcard isn't being chosen as the default and is card 1, rather than card 0.
Check the following guides for further information on RasPi / USB Audio Setup:
http://drewlustro.com/hi-fi-audio-via-airplay-on-raspberry-pi
http://audioplastic.org/blog/2013/01/10/AP1/

Related

Armbian - how to turn off a hard drive connected on SATA

I have an Orange Pi + 2 single board computer with the ability to connect an external hard drive via SATA.
Armbian is installed on the hard disk, the bootloader is in the onboard memory of the board.
Any command to turn off the device leads to the same result: the indicators on the board go out, it is no longer available via SSH, but the hard disk, any devices connected via USB continue to work, and the image via HDMI is also displayed on the screen.
How to completely turn off the device so that the hard drive stops correctly?
I believe that if you are capable of powering the device off using the operating system's menu, then it should be safe to cut the power off from the device itself. I have a raspberry pi 4 and have a little USB-C adapter that has a simple power switch which makes this concept very convenient for me. Cutting power to a turned-on, working device is very dangerous as it can damage critical files that could be being written. For this reason, it is probably smart to back up the device and also make sure that you are powering the device off through the operating system so that it can finish editing core files in case it needs to.

Device driver for USB lamp and fans

I have a USB lamp,which just switches on when plugged into a USB port. I connected it to my computer and ran lsusb, but could not find the device. How does the OS handle these devices? Are the USB power pins always powered with 5V, or does it get powered when the OS detects a device? If the OS detects a device and then supplies power to the USB slot, how do I locate the drivers associated with the device?
The device is something similar to the device listed here:
https://www.amazon.in/Codered-Portable-Flexible-Light-Colors/dp/B078N9DQ8B
From the image and description below, the product in question looks like a "dumb" device to me. By dumb i mean it only uses the +5V and GND lines from the USB connector. The D+/D- used to communicate are not connected and therefore no drivers are required/applicable. Given USB is a fairly complex and comprehensive protocol, you could probably pick up a copy of USB Complete: the first few chapters should get you started in the right direction.
I have also found this helpful.
BTW, external links (esp amazon products) tend to die, so upload and include a picture (when you have the reputation points) otherwise the context of the question can be lost.

Obtaining a fast ADC sample rate in embedded linux with an external ADC

I've been given the task of getting ADC samples onto an embedded linux computer at the highest rate I can (up to about 300kSPS). I am playing with several different platforms (odroid, edison) but easrly on I realized the limitations of using the build in ADCs from within linux and timing (I am relativly new to this).
Right now I am reliably getting 150kSPS using a teensy 3.2 with a very basic swapping buffer, a PDB, and the USB connection. USB writes take 2.5usec no matter my buffer size so any faster and the ADC read interrupt collides with the USB and I get nothing.
My question is: Would using an external ADC chip enable faster speeds? I see chips on Digikey and Mouser advertising 600kSPS and higher with SPI and even parallel outputs... but I fell like the bottleneck is the teensy with USB writes. Even if it could (and I am sure it could) read values 600k times a second how do you get it onto the computer without falling behind?
also, it is for long term collection so I can't just store everything and write it once the collection is over. The edison has a built in microcontroller, but no SPI implemented yet.
Edit:
To clarify, my question is weather there is any way to get large amounts of data very fast into my embedded linux device programmatically or is there some layer between a fast SPI device and the comptuer that I don't know about. So far my mentors have suggested I 1) learn to write a device driver for the SPI device or 2) recompile an image with RT_PREEMPT.

Controlling simple relay switch via USB

I'm looking to control a mains powered light from a simple relay switch connected via USB to the computer.
The relay switch isn't even a USB device, it's just a simple switch that requires the USB voltage to turn it on. When the voltage drops below a threshold, the switch will turn the light off.
My problem is that I can't control the power output of a USB port. I'm happy to do it using any language on Windows or Linux (but preferably Java because I'm used to it).
Unfortunately, in most cases you cannot control the power supply to the USB port. The power supply is usually hardwired through, and not switchable in software. You can send a reset to a USB device, but that won't work in your case.
There are a number of projects on instructables that do similar to what you describe, but unfortunately they seem to either be quite complicated or require expensive parts.
EDIT: There is actually a product currently in the news which would do want you want, but it doesn't appear to be shipping yet: http://www.pwrusb.com/
EDIT (again): Apparently you can do this with some usb hubs. This post sugggests the Linksys USB2HUB4 is one that works.
EDIT (and again): Apparently there are a number of similar questions, but there don't seem to be any more useful answers:
https://stackoverflow.com/questions/405269/custom-usb-device-that-disables-power-to-usb-devices-plugged-into-it
Power off an USB device in software on Windows
Is there software or code to alter USB power output
Can I write a program that swiches USB on/off
Most of the USB to Serial or USB to RS232 $10 converters support hardware handshaking. Use one of those as a single channel digital io.
Connect your transistor that will drive the relay to DTR on the converter board and command DTR ON/OFF with the converters driver.
A 2N7002 is a good transistor to use (FET actually) since it will work from 3V and doesnt need any resistors anywhere.
Here is a complete solution.
It uses an Arduino board, with a USB connection, (and Uno for example) to control the relay and combines this with pfod (Protocol for Operation Discovery) www.pfod.com.au which will let you control the board/relay from either the Arduino IDE SerialMonitor, or a terminal window (TeraTerm) or a Java program. The message protocol encloses commands in { }, think simplified html for micros, and provides numerous screens, menus, sliders, text and numeric inputs, etc. A detailed protocol spec is available
See Garage Door Remote for a detailed example, with full Arduino code and an example of controlling the relay from TeraTerm as well as the Arduino IDE SerialMonitor.
There is also an Android app, pfodApp, which will do general purpose control via bluetooth, or wifi/internet with 128 bit security. The pfodApp does all the Android stuff, you only need to code some simple strings in your Arduino code to get any menu system you want. See www.pfod.com.au for numerous examples.
You need a USB-GPIO microcontroller:
Adafruit FT232H (about $15)
Arduino Nano ATmega328 (about $7)
See this answer
I would suggest placing a separate Raspberry Pi unit with a wake-on-lan feature activated so you can ping it off and on.
You could do it by combining these two products from Pololu, for about $25:
Micro Maestro (assembled)
Basic SPDT Relay Carrier with 5VDC Relay (Assembled)
The Maestro is mainly a servo controller but you can set any of its channels to be simple digital outputs instead. The output can be controlled from the Maestro Control Center software or you can write your own software. A digital output from a Maestro is suitable to turn on the relay on the relay carrier. The relay could be powered from USB through the Maestro; I think it draws about 100 mA of current so that probably will not be a problem for most USB ports, though it would not be USB-compliant because the total current drawn by the Maestro and the relay would be over 100 mA. You could supply your own power source for the relay if you are worried about that.

Is USB power always enabled ? And if not, how to write a driver

I have a device that came with an AC power adapter where the connector is a mini USB plug. The device however doesn't seem to power itself from a computer's USB port (using a standard USB-mini USB cable) unless a specific driver is installed. The driver is only available for Windows. I would like to charge the device from USB plugs on different platforms.
My question is: why isn't power getting to the device without the driver? Is a driver always required for a USB port to start giving power? Or is it this device that's specifically made not to take a charge unless some software routine triggers it to do so?
I guess my question can be summarized as: Is power not present on the USB cable or is it present but the device ignoring it. If the answer is the former, I'll be trying to figure out how to write software that will enable the voltage to always be present.
Thanks
Why isn't power getting to the device without the driver?
USB ports are always powered when the computer is on and the USB control software hasn't detected current overdraw.
Is a driver always required for a USB port to start giving power?
No, the USB port is always required to start off providing power to the device, otherwise the device could never initiate a connection.
Or is it this device that's specifically made not to take a charge unless some software routine triggers it to do so?
This can be complex. To meet the USB spec a device cannot pull more than a few mA until it's registered with the computer.
However, nearly every computer allows the USB port to pull the full 500mA (and more) before it'll shut the power off.
The device you're charging is being nice by not pulling any significant power until the computer gives permission.
Writing software won't help, the device has to register with the USB bus, which will best be done with the driver.
However, the plug in charger doesn't do that. It likely has shorted the two data lines of the USB plug together, which signals the USB device that it's not connected to a computer and can pull the full 500mA without waiting.
Take a USB extension cable, cut off the jacket, and short the data lines (green and yellow, sometimes) together on the end going to the USB device, and leave them cut without touching anything on the end going to the PC, and leave the read and black power wires connected through.
It might work. If not, take the wall charger apart and find out what it's doing with each of the four USB wires, and see if you can duplicate that.
This might be helpful if you are targeting a linux system.
This seems to be platform-specific. In Linux, USB ports are always energized, while on Windows they don't. Thumbdrives with LEDs turn off when unmounted in windows, but in Linux they stay lit. My cellphone's manual says that it can't be charged by a PC, but I regularly do on my linux machine, I guess that's because they don't have a driver and windows won't power up without one.
Have you tried plugging it into a 'dumb' USB port - like the one on a car charger? Those ports are pure power and don't create a USB network. I think.
Unless you have the hardware specs from the manufacturer, I think you are out of luck. You could try reverse engineering the driver to see what it does, but I'd expect it would be cheaper and easier just to buy one with cross platform drivers or charges without the driver.