GithubHelp home page GithubHelp logo

wiringpi.net's Introduction

WiringPi.Net

A simple C# wrapper for Gordon's WiringPi library, also on GitHub. Please note this was only tested with the hardfloat version of Raspbian using CrashOverrides mono build which can be found here: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=34&t=37174&hilit=c%23+experimental

Simply install Gordon's WiringPi library on your Raspberry Pi and create the shared libraries as follows:

cc -shared wiringPi.o -o libwiringPi.so

cc -shared wiringPiI2C.o -o libwiringPiI2C.so

cc -shared wiringPiSPI.o -o libwiringPiSPI.so

Compile the project in Visual Studio 2010 and copy to your RasPi via FileZilla or some other SFTP client. Then run with: sudo mono SPITest.exe With nothing connected to the GPIO header you should see:

SPI init completed, using channel 0 at 32MHz for loopback testing All zeros read back

If you short the MISO and MOSI pins together you should see:

SPI init completed, using channel 0 at 32MHz for loopback testing Loopback is connected!

This is a different project to another .Net io library in that the SPI is hardware based and not software driven, the same with the I2C interface.

All praise should really go to Gordon@drogon for his great library which exposes all the required interfaces making my life and others that much easier. Cheers Gordon!!

wiringpi.net's People

Contributors

danriches avatar dxball avatar gerhman avatar marcus-l avatar seaeagle1 avatar teetrizzz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wiringpi.net's Issues

Shutting down interrupt threads

When using the wiringPiISR method a new thread is created which handles the interrupt (as I understand it). The problem I have is that when I try to exit my application I need to trigger the interrupt again (in my case a button push) before the application can exit.

Is there any way to 'shut down' the interrupt thread(s)?

I am now using Process.GetCurrentProcess().Kill(); to stop/kill my application... But that just seems wrong...

I2C 16 bit operations no sign or endian accomodation

Not really the wrapper's fault I don't think as I couldn't really find 16 bit reads and writes except as purpose written methods in specific devices. Could be wrong, might be a universal one I just can't find (not a C or C++ expert by any means).

So for two or more byte reads I use the ReadReg8() methods and assemble the bytes appropriately.

I haven't had any issues with the WriteReg16 but then I haven't actually used it. Didn't see anything dealing with sign/endian in the intellisense information though.

Use of Interrupts

Nice work, I added the two interrupt methods, maybe you want to add them as well.
Use the following to compile the base so:
cc -shared wiringPi.o -o libwiringPi.so -lwiringPi

PiThreadInterrups Class:
public enum Edge { INT_EDGE_SETUP = 0, INT_EDGE_FALLING = 1, INT_EDGE_RISING = 2, INT_EDGE_BOTH = 3}

PiThreadInterrupts Class:
[DllImport("libwiringPi.so", EntryPoint = "waitForInterrupt")]
///Obsolete, use wiringPilSR
public static extern int waitForInterrupt(int p_pin, int p_timeout);

[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void InterruptCallback();
[DllImport("libwiringPi.so", EntryPoint = "wiringPiISR")]
public static extern int wiringPiISR(int p_pin, int p_edgeType, [MarshalAs(UnmanagedType.FunctionPtr)] InterruptCallback p_callback);

Call:
if(WiringPi.PiThreadInterrupts.waitForInterrupt(8, -1) > 0) //only works in Sys mode! (WiringPi.Init.WiringPiSetupSys();)
{
Console.WriteLine("interrupt");
}

WiringPi.PiThreadInterrupts.wiringPiISR(8, (int)WiringPi.PiThreadInterrupts.Edge.INT_EDGE_RISING, new WiringPi.PiThreadInterrupts.InterruptCallback(Callback));

symbol lookup error for libwiringPi.so

Hi there,
thank you for the work on this library, I hope you can help me with this issue..

I'm trying to let a simple blink example run, but when executing with mono on my raspi I just get
the following error:
"mono: symbol lookup error: /home/pi/Programs/GPIO-WrapperClass-Test/libwiringPi.so: undefined symbol: softPwmStop"
I installed the latest version of wiringPi, it shows: "gpio version: 2.44"
All the three ".so"-files are in my program directory.
My program "LoopTest.cs" just looks like:

`using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WiringPi;

namespace SPITest
{
class LoopTest
{
//Main entry point
public static int Main(string[] args)
{
//Init WiringPi library
Init.WiringPiSetup();

        //Set Pin 7 as Output
        GPIO.pinMode(7, (int)GPIO.GPIOpinmode.Output);

        for (int i = 0; i < 10; i++)
        {
            GPIO.digitalWrite(7, 1);
            System.Threading.Thread.Sleep(1000);
            Console.WriteLine("High");
            GPIO.digitalWrite(7, 0);
            System.Threading.Thread.Sleep(1000);
            Console.WriteLine("Low");
        }
        return 0;
    }

}

}`

I just don't get what I did wrong..
Thank you in advance for any help!!

Contact

Hey Dan, could you please get in touch with me?
Unfortunately I can't find your e-mail address.
It's about this repo and the WiringPi organization that we continue to maintain.

Thanks, Christof
[email protected]

WiringPi.net examples needed.

Hi i appreciate your efforts, i need to use wiring pi library in my .net console application. could you please send me any links which will show how to use this library. Thank you.

Setup help?

Please Help?

I have got to this point but do not know where to set this up? I got the Gordon's WiringPi working on my PI so my next question would be what next?

Simply install Gordon's WiringPi library on your Raspberry Pi and create the shared libraries as follows:

cc -shared wiringPi.o -o libwiringPi.so
cc -shared wiringPiI2C.o -o libwiringPiI2C.so
cc -shared wiringPiSPI.o -o libwiringPiSPI.so

Soft PWM Support

Hello,

I am building a quadcopter using a Raspberry PI and C#. At the moment for I2C communication between my Raspberry PI and MPU9150 (works great).

I would like to add motor control so I would need 4 PWM outputs. Does the wrapper support the Software PWM library (https://projects.drogon.net/raspberry-pi/wiringpi/software-pwm-library)?

If not, will adding this to the wrapper work:

    [DllImport("libwiringPi.so", EntryPoint = "softPwmCreate")]
    public static extern int softPwmCreate(int pin, int initialValue, int pwmRange);

    [DllImport("libwiringPi.so", EntryPoint = "softPwmWrite")]
    public static extern void softPwmWrite(int pin, int value);

It may also be a good idea to add an example of PWM usage to the test console program.

Thanks in advance and with best regards!

EntryPointNotFoundException

Hi Dan,

I'm new in C# so if my question is trivial, sorry :)

I follow your instruction and compile shared libraries.
But when I want to try the GPIO on this way:

using System;

namespace WiringPiTest
{
class MainClass
{
public static void Main (string[] args)
{
WiringPi.Init.WiringPiSetup ();
WiringPi.Init.WiringPiSetupSys ();
WiringPi.GPIO.digitalWrite (0, 1);
}
}
}

I got the following error

Unhandled Exception:
System.EntryPointNotFoundException: digitalWriteGpio
at (wrapper managed-to-native) WiringPi.GPIO:digitalWrite (int,int)
at WiringPiTest.MainClass.Main (System.String[] args) [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.EntryPointNotFoundException: digitalWriteGpio
at (wrapper managed-to-native) WiringPi.GPIO:digitalWrite (int,int)
at WiringPiTest.MainClass.Main (System.String[] args) [0x00000] in :0

what should I do?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.