cypherkey / raspberrypi.net Goto Github PK
View Code? Open in Web Editor NEWRaspberry PI .NET library
License: GNU General Public License v2.0
Raspberry PI .NET library
License: GNU General Public License v2.0
I have trying to use MCP3008 to read analogue voltages from pi, but strangely its not working. The ADC value read from any channel gives either 0 or 6596.77 millivolts using the same code as used in the Mcp3008 example code.
Do I have the hardware circuit right? Its attached
Would be waiting for any help in this regard.
Is it possible to access the extra pins provided by the B+?
Thanks
Hi,
i have a problem:
System.Exeption: Cannot use pin with multiple instances. Unexport the previous instance with Dispose() first (pin 24)
I have only one instance of pin 24 in my Code and I get this Exeption where ever I delcare.
in_gpio24 = new GPIOMem(GPIOPins.V2_GPIO_24, GPIODirection.In);
Raspberry Pi 2
I'm quite new to programming so please help me to fix this problem
Hello guys,
I want to write code for the RaspberryPi in C# with Mono. That works pretty well.
But I need also to work with the GPIO-Pins.
When I want to build the RaspberryPiDotNet-Project, it throws me 31 errors, like this one:
CSC: error CS0518: The predefined type `System.RuntimeTypeHandle' is not defined or imported
Every error is the same, but instead of 'System.RuntimeTypeHandle' are everytime different things.
Thank you for writing this library. It's great.
Any thoughts on allowing the setting of the pull-up/down resistors when setting a pin to input? The default of off if usually fine, but there are times where it would be handy to use the internal resistors.
Thanks.
Hi,
thank you for your great work.
can you give me one raw example to communicate with other system using SPI using raspberry pi as master, raspberry should send two bytes and it will receive 10 bytes in return. the SPI clock is 1000000.
thanks,
Hey,
since the board Rev2 has changed some GPIO numbers, you should modify the GPIPins-enum.
Documentation: http://elinux.org/RPi_Low-level_peripherals#General_Purpose_Input.2FOutput_.28GPIO.29
Source changes:
public enum GPIOPins
{
GPIO_NONE = -1,
GPIO00 = 0,
GPIO01 = 1,
GPIO02 = 2, //REV2
GPIO03 = 3, //REV2
GPIO04 = 4,
GPIO07 = 7,
GPIO08 = 8,
GPIO09 = 9,
GPIO10 = 10,
GPIO11 = 11,
GPIO14 = 14,
GPIO15 = 15,
GPIO17 = 17,
GPIO18 = 18,
GPIO21 = 21,
GPIO22 = 22,
GPIO23 = 23,
GPIO24 = 24,
GPIO25 = 25,
GPIO27 = 27, //REV2
Pin03 = 2, //REV2
Pin05 = 3, //REV2
Pin07 = 4,
Pin08 = 14,
Pin10 = 15,
Pin11 = 17,
Pin12 = 18,
Pin13 = 27, //REV2
Pin15 = 22,
Pin16 = 23,
Pin18 = 24,
Pin19 = 10,
Pin21 = 9,
Pin22 = 25,
Pin23 = 11,
Pin24 = 8,
Pin26 = 7,
LED = 16
};
Greetings,
Sebastian
Hi guys...
I ran into a problem... I received my Pi 2 days ago and since that im trying to get my code working on that machine. The problem is even when I press one of the 4 buttons I need to have - the PinState still stays at low.
I already checked it with Python and its fully working there.
Codesnippet:
public static GPIOMem btn1 = new GPIOMem(GPIOPins.V2_Pin_P1_03, GPIODirection.In);
public static GPIOMem btn2 = new GPIOMem(GPIOPins.V2_Pin_P1_05, GPIODirection.In);
public static GPIOMem btn3 = new GPIOMem(GPIOPins.V2_Pin_P1_07, GPIODirection.In);
public static GPIOMem btn4 = new GPIOMem(GPIOPins.V2_Pin_P1_08, GPIODirection.In);
Console.WriteLine("State: " + btn1.Read() + " " + btn2.Read() + " " + btn3.Read() + " " + btn4.Read());
And the Output is:
State: Low Low Low Low
Hope you got an Idea to help me with that little problem...
I've tried using the wrapper on the Raspberry Pi 2B but i cant get it to to work. I tried bcm2835 1.3, 1.39 and 5.0 but none of them works.I am not getting any errors, it just doesn't change the pins state.
RPITest.zip
Should the file contain:
namespace RaspberryPiDotNet
{
public enum PinState
{
Low,
High
}
}
Hi!
There is a little problem with xbuild.
Compiling "xbuild RaspberryPiDotNet.csproj" isn't working with the Mono Version 3.2.8.0, XBuild Engine 12.0
Error message:
Project "/home/pi/dev/RaspberryPi.Net/RaspberryPiDotNet/RaspberryPiDotNet.csproj" (default target(s)):
Target PrepareForBuild:
Configuration: Debug Platform: AnyCPU
Target GenerateSatelliteAssemblies:
No input files were specified for target GenerateSatelliteAssemblies, skipping.
Target GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because its outputs are up-to-date.
Target CoreCompile:
Tool /usr/bin/dmcs execution started with arguments: /noconfig /debug:full /debug+ /optimize- /out:obj/Debug/RaspberryPiDotNet.dll DS1620.cs GPIO.cs GPIODebug.cs GPIODirection.cs GPIOFile.cs GPIOMem.cs GPIOPins.cs GPIOResistor.cs MCP3008.cs MicroLiquidCrystal/RaspPiGPIOFileLcdTransferProvider.cs MicroLiquidCrystal/RaspPiGPIOMemLcdTransferProvider.cs MicroLiquidCrystal/ILcdTransferProvider.cs MicroLiquidCrystal/Lcd.cs PinState.cs Properties/AssemblyInfo.cs TM16XX/TM1638.cs TM16XX/TM16XX.cs /target:library /define:"DEBUG;TRACE" /doc:bin/Debug/RaspberryPiDotNet.XML /reference:/usr/lib/mono/4.0/System.dll /reference:/usr/lib/mono/4.0/System.Core.dll /warn:4
DS1620.cs(92,42): error CS0589: Internal compiler error during parsingSystem.FormatException: Input string was not in the correct format
at System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider) [0x00000] in :0
at Mono.CSharp.Tokenizer.adjust_real (TypeCode t, Location loc) [0x00000] in :0
at Mono.CSharp.Tokenizer.is_number (Int32 c, Boolean dotLead) [0x00000] in :0
at Mono.CSharp.Tokenizer.xtoken () [0x00000] in :0
at Mono.CSharp.Tokenizer.token () [0x00000] in :0
at Mono.CSharp.CSharpParser.yyparse (yyInput yyLex) [0x00000] in :0
at Mono.CSharp.CSharpParser.parse () [0x00000] in :0
Task "Csc" execution -- FAILED
Done building target "CoreCompile" in project "/home/pi/dev/RaspberryPi.Net/RaspberryPiDotNet/RaspberryPiDotNet.csproj".-- FAILED
Done building project "/home/pi/dev/RaspberryPi.Net/RaspberryPiDotNet/RaspberryPiDotNet.csproj".-- FAILED
Build FAILED.
Errors:
/home/pi/dev/RaspberryPi.Net/RaspberryPiDotNet/RaspberryPiDotNet.csproj (default targets) ->
/usr/lib/mono/4.5/Microsoft.CSharp.targets (CoreCompile target) ->
DS1620.cs(92,42): error CS0589: Internal compiler error during parsingSystem.FormatException: Input string was not in the correct format
0 Warning(s)
1 Error(s)
Based on the following tutorial:
http://stackoverflow.com/questions/23639895/include-bcm2853-lib-on-raspberry-pi
after i run this script i got error below
any help please
the dll for RaspberyPiDotNet.dll and so file is already shared in gpio_csharp
using System;
using RaspberryPiDotNet;
namespace Test
{
class Program
{
static void Main(string[] args)
{
GPIOMem led = new GPIOMem(GPIOPins.V2_GPIO_12)
while(true)
{
led.Write(PinState.High);
System.Threading.Thread.Sleep(500);
led.Write(PinState.Low);
System.Threading.Thread.Sleep(500);
}
}
}
}
System.TypeInitializationException : An exception was thrown by the type initializer for RassberryPiDotNet.GPIOMem --->System.Exception:libbcm2835.so
at (wrapper managed-to-native)RaspberryPiDontNet.GPIOMem:bcm2835_init()
at RaspberryPiDotNet.GPIOMem..cctor()[0x00001]in
I could help by checking pull requests and issues. Also, I'm planning to find a solution for the problem we have to work with distance sensors in future.
public GPIOMem(GPIOPins pin, DirectionEnum direction)
: base(pin, direction, false)
{
// Isn't this next line redundant? the above base constructor call will make the same call.
ExportPin(pin, direction);
}
P.S. I would issue a pull request but haven't got git setup where I am right now.
Just a question, I wondered is there a reason why GPIO16 (i.e. the "OK" LED) was left out?
I tried adding it and was able to pulse the 'OK' LED on my RPi using this code
If there is a good reason then no problem, as I'm new to RPi, I'm not sure about this.
Btw, thanks for putting up this repo - it helped me out a great deal!
Hi there,
i have a Problem with reading a GPIO Value. I have written a litte source code in Visual Basic and C# too:
GPIOFile gpio17 = new GPIOFile(GPIOPins.V2_GPIO_17);
GPIOFile gpio24 = new GPIOFile(GPIOPins.V2_GPIO_24);
while(true)
{
gpio17.Write(gpio24.read());
}
My Compiler gives me the error, that the Method "Read" ist not presend in the .dll?
Does anyone have a solution for that?
edit: compiling the code direct on the pi2 is working, but on my pc with visual Basic not
Sorry for my bad english, it´s not my native language
Hello (Sorry my English for now)
I Compiled and installed bcm2835 library.
I tried the c++ code and i run c++ code perfectly.
After i run this command and this is run perfectly.
make libbcm2835.a
cc -shared bcm2835.o -o libbcm2835.so
i tried your simple blink led code but i've take some errors.
not find .so library.
Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for RaspberryPiDotNet.GPIOMem ---> System.DllNotFoundException: libbcm2835.so
at (wrapper managed-to-native) RaspberryPiDotNet.GPIOMem:bcm2835_init ()
at RaspberryPiDotNet.GPIOMem..cctor () [0x00000] in :0
--- End of inner exception stack trace ---
at Test.Program.Main (System.String[] args) [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for RaspberryPiDotNet.GPIOMem ---> System.DllNotFoundException: libbcm2835.so
at (wrapper managed-to-native) RaspberryPiDotNet.GPIOMem:bcm2835_init ()
at RaspberryPiDotNet.GPIOMem..cctor () [0x00000] in :0
--- End of inner exception stack trace ---
at Test.Program.Main (System.String[] args) [0x00000] in :0
Please help me.
Thanks
Does this library have PWM capability? Are you planning to introduce that in near future?.
Another important thing that I wanted to ask is if it is possible to access Raspberry Serial port(standard RS232 UART) to connect to a standard PC via its serial port.?
I have a raspberry pi and the setup to test if somebody wants to test,
Thanks,
Nouman
The example code using GPIOPins is obsolete and needs editing.
Hi,
under mono develop 2.8.6.3 I see a compilation error in TM1638.cs
line 112: Error CS0172: Type of conditional expression cannot be determined as byte' and
int' convert implicitly to each other (CS0172)
I don’t have a TM1638 to test with, but I suspect you can change the second expression to something like this: (byte)(data | (dot ? ((byte)1) : ((byte)0)))
;)
Thanks,
Stonie.
Taking into consideration this code
_ButtonGPIO = new GPIOFile((GPIOPins)GPIOPin, GPIODirection.In);
When this code runs, doing less /sys/class/gpio/gpio10/direction
(10 because it's the value of the GPIOPin variable) returns Out
.
The problem here is that the constructor referred above calls the public GPIOFile(GPIOPins pin, GPIODirection direction, bool initialValue)
with false on the initialValue
parameter. This one calls the base with: our pin, GPIODirection.In, false. The code for setting the PinDirection is the following
PinDirection = direction;
Write(initialValue);
and the Write
method is (partially) defined as this:
PinDirection = GPIODirection.Out;```
This setting will ALWAYS override the direction set.
My suggestion is that there should be another constructor on the `public abstract class GPIO : IDisposable`
I can try and contribute for that, but for that I would like you to DM me so that I can understand the process :)
hello all,
I am new with c# and I was trying to use the MCP3008.cs to read a potentiometer values but the value is always fixed to zero.
Reffering to the issues previously published:
Please does any body have an idea what could the problem be
PS: I have tried My mcp with PYTHON and it woks well.
I wrote an little Programm to set my GPIO-Pins but i'm only able switch Pin_P1_08, Pin_P1_10 and Pin_P1_13.
I use GPIOMem for example:
GPIOMem pin03 = new GPIOMem(GPIOPins.V2_Pin_P1_03, GPIODirection.Out,false);
To switch the status of the Pin i use:
if (pin03.Read())
pin03.Write(false);
else
pin03.Write(true);
The Programm compiles and runs without any Exceptions.
Hi,
Please could you help me with a (hopefully) small problem:
I have set up an input:
GPIOMem Inter = new GPIOMem(GPIOPins.Pin_P1_24, GPIODirection.In, false);
But I am trying to set the pull up/down resistor to off and cannot seem to do it. Is there something stupid I am missing?
Thanks
I would love to use .Net on my brand new Pi but I have no idea what your project needs to get me up and running.
I assume that there are lots of .Net devs out there who want to tinker with a Pi, but don't have the experience to get something like this going on their own. A "Get Started" guide would be immensely helpful.
Hello,
my knowledge about the SPI-Interface is nearly zero, but i need it for controlling a display. The raspberry has SPI-Pins. Will you support SPI with this library?
Greetings,
Sebastian
Hello
I'm quite new in this topic. But trying to acess the GPIO using the RaspberryPi.Net.
Compiling and adding the dll to the reference worked fine, as well no errors in the test code.
I prefer to use the GPIOFile method instead the GPIOMem
But when I run the applcation on the Pi I get some errors. Mono framework is working on the Pi for other applications.
Test code:
using System;
using Gtk;
using RaspberryPiDotNet;
public partial class MainWindow: Gtk.Window
{
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
protected void OnButton2Clicked (object sender, EventArgs e)
{
GPIOFile led = new GPIOFile(GPIOPins.Pin_P1_23);
led.Write (true);
}
protected void OnButton3Clicked (object sender, EventArgs e)
{
GPIOFile led = new GPIOFile(GPIOPins.Pin_P1_24);
led.Write (true);
}
}
Errors:
Marshaling clicked signal
Exception in Gtk# callback delegate
Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path "/sys/class/gpio/gpio8/direction".
at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x001c6] in /private/tmp/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.12/_build/mono-2.10.12.git/mcs/class/corlib/System.IO/FileStream.cs:282
at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
at System.IO.StreamWriter..ctor (System.String path, Boolean append, System.Text.Encoding encoding, Int32 bufferSize) [0x00039] in /private/tmp/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.12/_build/mono-2.10.12.git/mcs/class/corlib/System.IO/StreamWriter.cs:120
at System.IO.StreamWriter..ctor (System.String path, Boolean append, System.Text.Encoding encoding) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.IO.StreamWriter:.ctor (string,bool,System.Text.Encoding)
at System.IO.File.WriteAllText (System.String path, System.String contents, System.Text.Encoding encoding) [0x00000] in /private/tmp/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.12/_build/mono-2.10.12.git/mcs/class/corlib/System.IO/File.cs:576
at System.IO.File.WriteAllText (System.String path, System.String contents) [0x00000] in /private/tmp/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.12/_build/mono-2.10.12.git/mcs/class/corlib/System.IO/File.cs:571
at RaspberryPiDotNet.GPIOFile.set_PinDirection (GPIODirection value) [0x0004c] in /Users/reschmann/RaspberryPiDotNet/GPIOFile.cs:71
at RaspberryPiDotNet.GPIO..ctor (GPIOPins pin, GPIODirection direction, Boolean initialValue) [0x0006d] in /Users/reschmann/RaspberryPiDotNet/GPIO.cs:88
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000eb] in /private/tmp/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.12/_build/mono-2.10.12.git/mcs/class/corlib/System.Reflection/MonoMethod.cs:234
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /private/tmp/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.12/_build/mono-2.10.12.git/mcs/class/corlib/System.Reflection/MethodBase.cs:96
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000bf] in /private/tmp/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.12/_build/mono-2.10.12.git/mcs/class/corlib/System/Delegate.cs:413
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00018] in /private/tmp/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.12/_build/mono-2.10.12.git/mcs/class/corlib/System/MulticastDelegate.cs:70
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in /private/tmp/source/bockbuild/profiles/mono-2-10/build-root/mono-2.10.12/_build/mono-2.10.12.git/mcs/class/corlib/System/Delegate.cs:387
at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00000] in :0
at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] in :0
at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x00000] in :0
at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e, Boolean is_terminal)
at GLib.SignalClosure.MarshalCallback(IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data)
at Gtk.Application.gtk_main()
at Gtk.Application.Run()
Any idea where the problem could be?
Many thanks for your help for a rookie...
Hello,
I'd like to ask if the library provides support of I2C and UART.
Thanks.
Hi,
First off all thanks for the Great libary.
How i have to wire a HD44780 Display?
Greets
Johann
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.