You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Always getting an exception GpioConnection: Object reference not set to an instance of an object #86
I have a Raspberry Pi 3 B. I did some GPIO development using Python, but I would love to use C#.
I set up a small project (Raspberry.IO references are OK):
using System;
using Raspberry.IO.GeneralPurpose;
namespace Lichtje1
{
class Program
{
public static void Main( string[] args )
{
var led1 = ConnectorPin.P1Pin15.Output();
var connection = new GpioConnection( led1 );
for( var i = 0; i < 100; i++ )
{
connection.Toggle( led1 );
System.Threading.Thread.Sleep( 250 );
}
connection.Close();
}
}
}
I keep getting the following error no matter if I compile on Visual Studio (on Windows) or MonoDevelop (on Raspberry Pi):
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
at Raspberry.IO.GeneralPurpose.GpioConnection.Allocate (Raspberry.IO.GeneralPurpose.PinConfiguration configuration) [0x00073] in <39616ab275014559a5b975fe859e9ad9>:0
at Raspberry.IO.GeneralPurpose.GpioConnection.Open () [0x00036] in <39616ab275014559a5b975fe859e9ad9>:0
at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.GpioConnectionSettings settings, System.Collections.Generic.IEnumerable`1[T] pins) [0x000f8] in <39616ab275014559a5b975fe859e9ad9>:0
at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.PinConfiguration[] pins) [0x00000] in <39616ab275014559a5b975fe859e9ad9>:0
at Lichtje1.Program.Main (System.String[] args) [0x00011] in <fb46ca8bbdcc45f0952b44480e70cfba>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
at Raspberry.IO.GeneralPurpose.GpioConnection.Allocate (Raspberry.IO.GeneralPurpose.PinConfiguration configuration) [0x00073] in <39616ab275014559a5b975fe859e9ad9>:0
at Raspberry.IO.GeneralPurpose.GpioConnection.Open () [0x00036] in <39616ab275014559a5b975fe859e9ad9>:0
at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.GpioConnectionSettings settings, System.Collections.Generic.IEnumerable`1[T] pins) [0x000f8] in <39616ab275014559a5b975fe859e9ad9>:0
at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.PinConfiguration[] pins) [0x00000] in <39616ab275014559a5b975fe859e9ad9>:0
at Lichtje1.Program.Main (System.String[] args) [0x00011] in <fb46ca8bbdcc45f0952b44480e70cfba>:0
Hi, can anyone please repeat the steps (as simple as possible ^^) to solve this problem? There is a dead link. I found the function above but there are so many build errors... Is there a simpler solution, or can I maybe update to a fixed version with nuget?
Also, I wonder if even older Pi's report Bcm2835 as the Hardware value in /proc/cpuinfonow. (The change, after all, was in the OS kernel, not the actual hardware). If that's the case, the both old and new Pi's may be reporting the same value, in which case the fix suggested by @Bulinlinbu above will not be safe on older Pi's. I have no way of testing this tho, since I only have a new one.
However, if you know you're only running on a RPi 3, then @Bulinlinbu's change looks safe enough.
Finally, test on my RPi3 indicates that this quick and dirty workaround also works, if you know you are running on a RPi 3:
I wouldn't advocate using that for any long-term purpose, but as a quick workaround until R#.IO, for users who know they are on RPi3, it seems to work. It amounts to forcing in the value that the library expects to see on an RPi 2 - which results in the correct GPIO memory addresses being selected because the addresses are the same on the Pi 3.
Activity
arakis commentedon May 7, 2017
i have a similar problem:
Its since the upgrade from kernel ARCH Linux 4.4 to 4.9
Bulinlinbu commentedon May 30, 2017
So do I
It seems that "Driver" is null GeneralPurpose > GpioConnection.cs line 488 :
Driver.Allocate(configuration.Pin, configuration.Direction);Bulinlinbu commentedon May 30, 2017
OK, il think the problem is from Raspberry.System API, it doesn't reconize the CPU of this version of PI.
If I do this :
Raspberry.Board.Current.IsRaspberryPi; // FalseSee this request :
raspberry-sharp/raspberry-sharp-system#6
Bulinlinbu commentedon May 30, 2017
Right, it works for me.
First : in Raspberry.System librairy, add the BCM2835 CPU
see this post : raspberry-sharp/raspberry-sharp-system#6
Next : In Raspberry.IO.GeneralPurpose, edit the function :
In GpioConnectionDriver.cs line 291
and in MemoryGpioConnectionDriver line 246
IT is magic !
NeededAnUnusedName commentedon Jul 2, 2017
Hi, can anyone please repeat the steps (as simple as possible ^^) to solve this problem? There is a dead link. I found the function above but there are so many build errors... Is there a simpler solution, or can I maybe update to a fixed version with nuget?
Bulinlinbu commentedon Jul 2, 2017
Link not dead anymore
NeededAnUnusedName commentedon Jul 2, 2017
Thanks, maybe fix the other link too, I still cant reach it.
But it helped a lot, thank you very much! =)
JohnRusk commentedon Oct 22, 2017
A note for others who find this page: it's recommended to use the revision number now, for identifying the processor. See raspberrypi/linux#2008 and raspberrypi/firmware#705
Also, I wonder if even older Pi's report Bcm2835 as the Hardware value in
/proc/cpuinfonow. (The change, after all, was in the OS kernel, not the actual hardware). If that's the case, the both old and new Pi's may be reporting the same value, in which case the fix suggested by @Bulinlinbu above will not be safe on older Pi's. I have no way of testing this tho, since I only have a new one.However, if you know you're only running on a RPi 3, then @Bulinlinbu's change looks safe enough.
Finally, test on my RPi3 indicates that this quick and dirty workaround also works, if you know you are running on a RPi 3:
I wouldn't advocate using that for any long-term purpose, but as a quick workaround until R#.IO, for users who know they are on RPi3, it seems to work. It amounts to forcing in the value that the library expects to see on an RPi 2 - which results in the correct GPIO memory addresses being selected because the addresses are the same on the Pi 3.
Dip11 commentedon Aug 7, 2018
install Raspberry.IO.GeneralPurpose3 -Version 3.1.1 instead of Raspberry.IO.GeneralPurpose as nuget package. Hope ur problem will be solved.
JTrotta commentedon Aug 7, 2018
Raspberry.IO.GeneralPurpose3 has been disocontinued.
Try https://github.com/JTrotta/RaspberrySharp
piibet commentedon Dec 16, 2018
Please make sure you have enabled all Interfaces in Rasperry Pi Configuration.
I forgot to do that, and it gave me same error.