Measure input voltage of Raspberry Pi B+ running Ubuntu - bash

I just learned that a red flashing LED indicates voltage below 4.63V on a Raspberry Pi Model B+.
Is there a command to determine the voltage programmatically?
I tried vcgencmd measure_volts. But it yields 1.2000V, independent of the input source and the LED status. And it doesn't seem to be related to the 4.63V mentioned above.
Update
Let me describe the situation in a bit more detail:
I'm powering the Raspberry Pi with a lead-acid battery built into a moving robot. After operating the robot for a while, the voltage seams to drop below a critical minimum, causing potential damage to the file system. Therefore, I'd like to detect low voltage automatically (and trigger the robot to return to the charging station).
I'm asking here in StackOverflow, since I assume the solution not to be robotic-specific, but generally applicable to other machines.

Yes you can, as it is said in this topic Under-voltage warnings you can know the low voltage reading the GPIO 35. For reading GPIO, you can refer to this topic:
Python Script to read one pin

Have a look at the adafruit ina219 sensor https://learn.adafruit.com/downloads/pdf/adafruit-ina219-current-sensor-breakout.pdf .
This sensor can be put between the battery and the raspberry and measures the current and the voltage along this connection (0-26V and max. 3.2A). It communicates via i2c bus. Together with an Arduino you can easyly build an battery watchdog for your raspberry. A sample program and the arduino driver can be found here: https://github.com/adafruit/Adafruit_INA219.

According to https://raspberrypi.stackexchange.com/questions/7414/is-it-possible-to-detect-input-voltage-using-only-software it's not possible to do it on software level without other hardware.

Related

Measure PWM Duty Cycle on RP2040 using micropython

I'm trying to use a Raspberry Pi Pico to measure an incoming PWM signal duty cycle and use the value to drive an I2C digital potentiometer. I'd like to use micropython as I know some of this already. The I2C output I have working with no problems. However I can't find where to start with the PWM measurement.
The RP2040 datasheet suggests it is possible to use the PWM slices to measure duty cycle, but the micropython PWM commands don't seem to utilise this (https://docs.micropython.org/en/latest/library/machine.PWM.html)
I can't see how to access the PWM slices directly in micropython
The "rp2" micropython — functionality specific to the RP2040 does not reference PWM as far as I can see. (https://docs.micropython.org/en/latest/library/rp2.html)
There are ways to measure PWM by using some coding but I would like to do it using the hardware as this frees up the processor for other tasks and it should also be more accurate I believe.
Perhaps I am just missing some documentation - any pointers much appreciated.
Chris
EDIT: I have found a useful module which covers a large part of this query:
https://github.com/phoreglad/pico-MP-modules/tree/main/PWMCounter

Powering Onboard Computer from DJI Matrice 100

I am trying to set up my Intel Nuc as the Onboard Computer for using DJI OSDK on my Matrice 100. I am looking for suggestions to find a way to power the Nuc from the Matrice.
In the beginning, I connected a DC-DC voltage regulator to one of the XT30 ports to get 19V and power the Nuc. It worked okay for a while and I was able to fly the Matrice outside using OSDK. But it has suddenly stopped working now. When the Nuc tries to boot into Ubuntu, it shuts down abruptly.
In short, use separate power source for Onboard PC and sensors.
Typically sensors and PC such as IR or LIDAR or NUC draws power heavily. If the current changes, the sensor value will change (which is bad). The PC will need a safe margin of voltage e.g 16 to 21. A sudden gust wind can cause the drone to output thrust power at a maximum which might lower the voltage for couple secs. In this case, PC might gets shut down or provide wrong calculation output ( e.g false odometry output)
So adding a stand-alone small size 5 cell battery should give you stable performance. Here I cant promote a specific commercial item. For my project, I bought the battery from Hobbyking to do the job for onboard PC and Kinects. You can search there for the battery that suits your need
PS. don't get DC to DC converter, typically it is very low efficiency and prone to power disturbance. I use typically raw battery and BEC(for 5V or 12V Sensor such as IR sensor and Hokuyo LIDAR)

How to do an edge counter/clock detector for a Raspberry PI(as linux kernel driver)?

Hej
I connected to one of my raspberry pi pins to a voltage controlled oscillator. A change of one of the oscillator capacity changes the output frequency. My question is how to realize the frequency detection?
There some constraints:
1st.) I like to keep the cpu consumption low.
2nd.) I like to have a file based interface, which my user space app can query for the actual frequency.
I was checking the Linux GPIO driver. But I see no possibility to configure a pin as an edge counter.
The raspberry pi soc data sheet describes at page 86 (chapter "6 General Purpose I/O (GPIO)")registers to configure a gpio to detect edges.
Any ideas how to configure these registers in a kernel character device driver?

Linux Driver real time constraints

I need to build a platform for logging some sensor data. And possibly later doing some calculations on this logged data.
The Raspberry Pi seem like an interesting (and cheap!) device for this.
I have a gyroscope that can sample at 800 Hz which is equivalent to one sample every 1.25 ms.
The gyroscope has a built-in FIFO that can store 32 samples.
This means that the FIFO has to be emptied at least every 32 * 1.25 = 40 ms, otherwise samples will be dropped.
So my question is: Can I be 100% certain that my kernel driver will be able to extract the data from this FIFO within the specified time?
The gyroscope communicates with the host via i2c, and it can also trigger an interrupt pin on a "almost full"-event if that would make things simpler.
But it would be easiest if I could just have a loop in the driver that retrieves the data at regular intervals.
I can live with storing the data in kernel space, and move it to user space more infrequently (no constraint on time).
I can also live with sampling the gyroscope at lower sample rates (400 or 200 Hz is acceptable).
This is with regards to the stock kernel, and not the special real-time kernel as it seems like this is currently not supported for the Raspberry Pi.
You will need a real-time linux environment for tight timing:
You could try Xenomai on Raspberry Pi:
http://diy.powet.eu/2012/07/25/raspberry-pi-xenomai/
However, following along this blog:
http://linuxcnc.mah.priv.at/rpi/rpi-rtperf.html (dead, and I could not find it in wayback or google cache)
It seems he is getting repeatable +/- 20µS timing out of the stock kernel. As your timing resolution is 1250µS you may be fine with the stock kernel if you willing to lose a sample once in a blue moon YMMV.
I have not tested this yet myself but I have been reading up in an attempt to try to drive a ws2811 LED controller with the Raspberry Pi and this was looking the most promising to me.
There is also the RT linux patch: https://rt.wiki.kernel.org/index.php/Main_Page
Which has at lest one pi version: https://github.com/licaon-kter/raspi-rt
However I have run into a bunch of nay-sayers when looking deeper into this patch.
Your best bet it to read the MS timer and log or light an LED if you miss an interval and then try some of the solutions. Happy Hacking..

Accessing audio out in Windows

I am looking to write an Arduino script that uses whatever audio signal is going to the speakers to create a physical visualization.
The Arduino is connected to the windows machine only through USB, so I need to use USB to find out what is being sent to the speakers. How would I access this information?
As of right now, the Arduino can only communicate with the computer via serial over USB. Things have changed with the new Arduino Uno, but the examples have not yet been released to show how to have the new Arduino act as other USB devices.
You would have to write something for the Windows box that monitor's the system audio and sends the info about it over serial to the Arduino, as long as you want it to only connect via USB.
There isn't a very good way to interface an audio signal to an Arduino without some external hardware.
One way to do it though would be to connect the audio line to a biased pin with a capacitor, then you could use the ADC directly. There will be pretty terrible dynamic range, but it only takes 3 passive parts. Running that through an opamp before going to the ADC pin could significantly improve dynamic range and provide a filtering opportunity (see below). Alternatively, you could switch on an on-chip voltage reference to use (typically 1-1.5 V) instead of the main supply.
It doesn't matter that much for a straight visualization, but the sample rate will not be good enough to capture the full spectral content of the audio (in addition to the poor dynamic range resolution). The default Arduino sample rate is 10 kHz(-ish...possibly asynchronous), so you will only get valid data if your signal is below 5 kHz, otherwise aliasing will muck it up. (If you write your own analog driver for the ATmega32P you could get up to 76 kHz sample rate with 8-bit samples)
Then to actually communicate that data to a computer, you can fairly easily throw all those ADC values onto the UART for the computer to pick up and process as it sees fit. An ATmega will not have the power to compute FFTs on the fly (what you'd do almost always do for a viz anyways).
Or to skip all that, connect the audio signal to your computer's sound card (or USB sound card...they're pretty nice) and use some audio driver.
There is a Java library for processing called ESS that lets you access audio out.

Resources