-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't Require Gem on RPi 4 #22
Comments
Same error, Pi Model 2B v1.1, Ruby 2.5 -- 2.5 being what I got with apt-get install ruby-full, and even that's in "security maintenance phase (will EOL soon!)" |
Same on on Pi Model 3B+ with ruby 2.6.6
|
I am seeing the same issue, and have a janky workaround. I'm going to try to improve on it but I'm putting it out there in case it might help someone immediately, and to move the conversation along. Essentially, c_gpio.c, setup() sets up the memory map between the GPIO device and a block of memory. The function tries to set this up in two ways, the first if it has permissions to read from /dev/gpiomem, and the second if it does not. I haven't been able to get get the first mapping working yet, because I don't have permission as a user to read from this device. I think I need to give ruby setuid root permissions to do this, and I haven't taken that step yet. Instead, I've gotten the second code path to work, which does require ruby to be run as root. In this case, the IO memory base address, or peri_base, isn't getting determined properly by setup.c - the code is evaluating it to be zero and the code is bailing with this call:
peri_base on the raspberry pi 4 needs to be 0xFE000000. So in the #define's I set this based on the CPU type:
Later on, there are two attempts to set peri_base, again, based on permissions. In the first attempt, it attempts to read from /proc/device-tree/soc/ranges and computes the value based on the contents of that device file. I don't yet understand the computation, so for now I've simply replaced the line that computes peri_base with one that sets peri_base to this value:
In the second attempt, which tries to determine peri_base based on the cpu type by reading /proc/cpuinfo, I've added an elseif based on the CPU type BCM2711:
Now, if I build this code and copy the resulting shared library into place, and run my test code as root, I'm able to read and write to the GPIO pins. With this code deployed on my Paspberry Pi 4, I'm able to toggle an LED connected to board pin 11 with this bit of ruby:
Anyway, I've attached my modified c_gpio.c (as a txt file) for anyone interested to copy into their source tree. I doubt it'll work on anything but a pi 4 right now, but it's a start. |
Any update? |
Same issue on a Pi 3B, with Ruby 3.0.0 and 2.5.1. Before finding this thread I'd tried rbenv, RVM and a clean install of Raspbian. |
These may not be comprehensive instructions, but they may be enough to muddle through:
I updated it in two places: /usr/local/lib/ruby/gems/2.7.0/gems/rpi_gpio-0.5.0/lib/rpi_gpio Now, check to see if your system works and you're able to talk to the GPIO! Anyway, this is the steps I followed a couple months ago, based on memory. I hope it's clear (and accurate) enough - let me know if you have any issues or need clarifications. Obviously, this should only be done on an as-needed basis, and should be considered a particularly ugly bandaid. I hope it can help someone out until a proper fix can be rolled out. |
Sorry if this is a dumb suggestion, but your user is a member of the gpio group, right? |
Not a dumb suggestion, because the user wasn't a member of the group. I just added it, and I still get an error unless I'm running as root. :-/ I'm probably doing something dumb. EDIT - Still not working, but when I su to the user pi (which is also in the gpio group, I'm able to read from /dev/gpiomem, but when I try that from my user account even after I added it to the gpio group it still fails. So there's probably something I need to figure out with regards to group membership & permissions, once I have a moment this evening. |
The problem itself is that the library Ruby expects should be in This file is created at gem installation time (or when manual compilation happens), for some reason, your compilation process either has an error or the file is just not being created, that's why Ruby then complains that it can't find it. I'm not sure the solution is indeed updating the start values for any given BCM, but the fact that your current BCM (i.e: Pi4) is not supported could be the issue. I highly doubt this is the main reason, but since I haven't really tested it I'm leaving it as an option. I did checkout to the only open PR right now (#20). Recompiled the lib and replaced the whole gem folder where it was installed. If all of this sounds weird to you, the tl;dr is:
The compile process should output a fiile: If you solve that or manage by any other means to get that library there, this problem should be gone. Note: You may also just To know where any given gem is installed use |
I get a load error on a Raspberry Pi 4B for version
0.5.0
. Version0.4.0
loads without issue, here's the stack traceI see the Readme mentions Ruby 2.0.0 as the highest version tested, but on the Pi4, 2.4 is the lowest version I could easily install with
rbenv
.lib/rpi_gpio/rpi_gpio.so
does exist on my machine. I also tried using the code from #20, but get theRuntimeError: this gem can only be run on a Raspberry Pi
.Happy to perform any debugging steps on my machine
The text was updated successfully, but these errors were encountered: