How to know input voltage to RShake?

Hi All,
I am running a 3D shake powered by solar panels and battery. I would like to know input voltage to the shake so that I can trigger a soft shutdown when input voltage is below a certain threshold.
Is there any way I can read input voltage?
Thanks in advance
Diego

As far as I knw, there is no way to read the voltage in the R-Pi itself, but it does detect low voltage and deliver a warning. That is probably good enough for your needs.

This may give you what you need (NOTE: I have not tested this myself!):

1 Like

Hello Diego,

As Philip said, there is no way of precisely reading the input voltage of the Pi board. It may be possible with the vcgencmd python package (vcgencmd) as one user has done something similar in the last post of this thread: Using under voltage warning for pi shutdown - Raspberry Pi Forums but you will have to experiment.

As an alternative, executing this from the command line

sudo zgrep -a -i voltage /var/log/syslog*

will provide all the lines in the log files where voltage issues have occurred, such as undervoltage events too. You can monitor the logs with this, inside a script, and trigger a soft shutdown when a voltage line appears.

Hello Stormchaser,
thanks for your hint.
When I run your command, I obtain several lines like the following couple

/var/log/syslog.4.gz:May  6 02:15:24 raspberryshake kernel: [61808.093628] Under-voltage detected! (0x00050005)
/var/log/syslog.4.gz:May  6 02:15:30 raspberryshake kernel: [61814.336769] Voltage normalised (0x00000000)

As far as I understand, voltage is normalized (stabilized?) typically a few seconds after an under-voltage is detected. What does this mean? Are under-voltage events like that pasted above real power supply shortage? I do not want to shutdown the unit when it is not necessary to.
Thank you
Diego

Hello Diego,

As the undervoltage “events” highlighted by those lines are solved in a matter of seconds, I can say that, apparently, the voltage level only dips very briefly below the notification threshold before going up (normal) again.

As you have their precise timing, you can check on the Shake helicorder (first icon low on the left in rs.local/) to see if these “events” are causing you to lose data. If there are many lines like that, then I would also recommend verifying your power supply and seeing if you can reduce their number.

You could approach a soft shutdown by monitoring the logs, and if an “undervoltage” line appears not to be solved in, let’s say, a minute (or 30 seconds) or so, then trigger the function to power down the Shake. You can then refine and optimize this approach in relation to how often this happens and how effective this new implementation is.

Hello Stormchaser,

Thanks for your hint. I have another question. I would like to search for undervoltage events just in the most recent syslog file. I tried to understand which file was last modified as follows

myshake@raspberryshake:/var/log $ ls -lt
total 8168
-rw-r----- 1 myshake myshake  717246 May  9 17:50 auth.log
-rw-r----- 1 myshake myshake  586934 May  9 17:50 syslog
-rw-r----- 1 myshake myshake  634771 May  9 17:45 daemon.log
-rw-rw-r-- 1 myshake myshake  292584 May  9 17:43 lastlog
-rw-rw-r-- 1 myshake myshake   23040 May  9 17:43 wtmp
-rw-r--r-- 1 myshake myshake   33964 May  9 17:13 nmbd.log
-rw-r----- 1 myshake myshake  373794 May  9 17:07 kern.log
-rw-r----- 1 myshake myshake  353747 May  9 17:07 messages
-rw-r----- 1 myshake myshake    8686 May  9 17:04 debug
-rw------- 1 myshake myshake   15650 May  9 17:03 xrdp-sesman.log
-rw-r--r-- 1 myshake myshake    9731 May  9 17:03 boot.log
drwxr-xr-x 2 myshake myshake   12288 May  9 11:07 ntpstats
-rw-r----- 1 myshake myshake  258266 May  9 06:37 syslog.1
-rw-r----- 1 myshake myshake    2867 May  8 16:03 debug.1
-rw-r----- 1 myshake myshake   20809 May  8 11:07 syslog.2.gz
-rw-r----- 1 myshake myshake   28677 May  7 06:25 messages.1
-rw-r----- 1 myshake myshake   13112 May  7 06:25 syslog.3.gz
-rw-r----- 1 myshake myshake  202763 May  7 06:25 auth.log.1
-rw-r----- 1 myshake myshake  109601 May  7 06:21 daemon.log.1
-rw-r----- 1 myshake myshake   30938 May  6 21:19 kern.log.1
-rw------- 1 myshake myshake       0 May  6 06:25 btmp
-rw-r----- 1 myshake myshake       0 May  6 06:25 user.log
-rw-r----- 1 myshake myshake  117126 May  6 06:25 messages.2.gz
-rw-r----- 1 myshake myshake  296597 May  6 06:25 syslog.4.gz
-rw-r----- 1 myshake myshake   40547 May  6 06:25 auth.log.2.gz
-rw-r----- 1 myshake myshake  131951 May  6 06:24 daemon.log.2.gz
-rw-r----- 1 myshake myshake  146306 May  6 02:15 kern.log.2.gz
-rw-rw-r-- 1 myshake myshake   46080 May  5 10:43 wtmp.1
-rw-r----- 1 myshake myshake    2029 May  5 10:43 debug.2.gz
-rw-r--r-- 1 myshake myshake 1024281 Feb 15 16:06 nmbd.log.old
-rw-r----- 1 myshake myshake  115795 Jan 17 12:02 user.log.1
-rw------- 1 myshake myshake     384 Jan 17 10:29 btmp.1
-rw-r----- 1 myshake myshake   44679 Jan 17 06:30 syslog.5.gz
-rw-r----- 1 myshake myshake    1169 Jan 16 06:28 syslog.6.gz
-rw-r----- 1 myshake myshake   28481 Jan 15 06:25 messages.3.gz
-rw-r----- 1 myshake myshake    1029 Jan 15 06:25 syslog.7.gz
-rw-r----- 1 myshake myshake   14076 Jan 15 06:25 auth.log.3.gz
-rw-r----- 1 myshake myshake    8339 Jan 14 11:07 daemon.log.3.gztype or paste code here

I am not sure I got this output right. Is the syslog file the most recent one I should look into for undervoltages? How and when are the syslog.*.gz files generated? Why is the syslog.1 file still not compressed?

Thank you for your help
Diego

Hello Diego,

I would advise you to push your last question to a Linux forum to get a more detailed answer and reasoning behind the possible why the syslog file was not compressed, as this is related to how the base Debian OS we have based our OS upon is configured and works.

A colleague has also suggested the following, that is, instead of reading the input voltage of the Shake by looking through the software, you can set up a way to read the output voltage of the battery (so moving from the end to the start of the pipeline) and then execute a soft shutdown when the battery output voltage drops below a certain threshold. It’s worth a thought.

Hi Stormchaser,

Thanks for your reply. I thought you were more into the syslog file generation because, as far as I understand, there you can monitor what is happening to the system that controls the sensor.
I am afraid that the second option you propose is not a solution, for my case at least. First because I would need to somehow input the external reading of the voltage to the unit (maybe with GPIO? GPS antenna is connected to the USB port) and this would compromise the IP67 enclosure. Second, there is a solar charge controller that controls the solar panel, the battery and the unit and one of its tasks is to disconnect the unit when battery voltage is low.
I think I will dig further in the vcgencmd solution that you suggested a couple of posts ago.
Thanks
D

2 Likes