GithubHelp home page GithubHelp logo

raspberry-sharp-io's Introduction

Raspberry# IO

See the Raspberry# IO Wiki for full documentation and samples.

Introduction

Raspberry# IO is a .NET/Mono IO Library for Raspberry Pi. This project is an initiative of the Raspberry# Community.

Current release is an early public release. Some features may not have been extensively tested. Raspberry# IO currently supports low- and high-level GPIO input/output, support for SPI and I2C peripherals.

Samples for SPI (for MCP3008 ADC or MCP4822 DAC), I2C (for MCP23017 I/O Expander), HD44780 LCD display and HC-SR04 distance sensor are provided.

Support for extended I/O (such as SDI, or PWM for motor control) is planned for future releases.

Programs using Raspberry# IO must be run with elevated privileges, for example the Test.Gpio.Chaser program included in solution:

sudo mono Test.Gpio.Chaser.exe -loop

Features

Raspberry.IO.GeneralPurpose

Raspberry.IO.GeneralPurpose provides a convenient way to use Raspberry Pi GPIO pins, while using .NET concepts, syntax and case. You can easily add a reference to it in your Visual Studio projects using the Raspberry.IO.GeneralPurpose Nuget.

It currently support the following features:

Low-level:

  • Access to GPIO pins through in 3 flavors: basic (using files), through memory, and full (memory with support for edge detection through "pseudo-interrupt"). By default, full driver is used.
  • Addressing through processor pin number or connector pin number
  • Pin assignment of various Raspberry Pi revisions (as of 2013-09, Raspberry Pi model B rev1 and rev2 as well as Raspberry Pi model A, including rev2 P5 connector)
  • Controlled use of resources using a IDisposable component and ability to use edge detection instead of polling
  • Support sub-millisecond polling of input pins

High-level:

  • Giving custom name to pins for more readable code
  • Easy-to-use, declarative configuration of pins. Ability to revert the polarity (1/0) of pins; ability to use an input pin as a switch button
  • Firing of events when pin status change (input as well as output), using polling
  • High-level behaviors for output pins, including blink, pattern and chaser

Raspberry.IO.SerialPeripheralInterface

  • Preliminary support for SPI through Raspberry.IO.SerialPeripheralInterface assembly
  • Includes SPI samples for MCP3008 ADC and MCP4822 DAC
  • Includes support for Linux's kernel SPI module driver spi-bcm2708 (/dev/spidev0.0)

Raspberry.IO.InterIntegratedCircuit

  • Preliminary support for I2C through Raspberry.IO.InterIntegratedCircuit assembly
  • Includes I2C sample for MCP23017 I/O expander

Raspberry.IO.Components

Parts of Raspberry# IO are inspired by BCM2835 C Library and Gordon Henderson's WiringPi.

raspberry-sharp-io's People

Contributors

chkr1011 avatar code1110 avatar danielcweber avatar danm-de avatar ebezine avatar gamondue avatar genemars avatar johnmwright avatar keneo avatar lkroliko avatar mihamarkic avatar neutmute avatar nickpbd avatar raspberry-sharp avatar shibayan avatar tanson avatar wildgenie avatar xlevel 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  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  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  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

raspberry-sharp-io's Issues

Can't build with mono/Mac

Hi,

Just tried compiling on my mac osx 10.10.1 (yosemite). Fails in Raspberry.IO.Interop.GenericIoControl
[DllImport("libc", EntryPoint = "ioctl", SetLastError = true)]

error is The DllImportattribute cannot be applied to a method that is generic or contained in a generic type.

From the microsoft docs:
https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute(v=vs.110).aspx:

"The DllImportAttribute does not support marshaling of generic types."

I guess the 'T' in public static extern int ioctl(int descriptor, UInt32 request, ref T data); wont work with the DllImport. I have not tried this on a pc yet. I tried it on monodevelop on the pi, and apparently I can't open the solution file there (I think that's because of the older version of monodevelop on the pi). I figured it would be fun to try it on the mac being that it's also a unix distro.

Jeff

tsop382 ir recieve

does anyone have any sample code for recieving ir signals? I don't need to decode, just detect activity.

thanks

Licence?

What's the licence model?

Is it ok to fork, extend, use and publish?

I2C ReadReg methods missing

I'm trying to use this library for reading Temp and Pressure from a MPL115A2. But this relies on reading the values from specific addresses on the device. I have not found the methods in the I2C part for doing this. Only for writing and reading streaming bytes. Am I missing something or are these not implemented?

Thanks,
Peter

Problem with HD44780

Are there any known issues with the HD44780 + MCP23017 kit sold by Adafruit? I had to make some minor adjustments to the pins based on the PCB's schematics, but it seems there's a problem writing to the LCD. Writing commands and text results in gibberish being written to the LCD, for example sending the "clear" command prints some Japanese character.

Updated pin layout:

  • Register = B7
  • Clock = B5
  • Data: B1, B2, B3, B4

Toggling the A6 pin turns the backlight on and off as expected.

Tested with a rev2 Raspberry Pi model B, using Test.Gpio.HD44780 5fb224b with the i2c option enabled. Adafruit's own Python example code works flawlessly.

MPU-6050 Gyro-Accel

Hi,
I try use I2cDriver to get measurement from mpu-6050, but I don't know how.
I try writeByte(registerNumber) and then readByte(), but I always get zero. How can I build own read or write sequence like in mpu6050 product specyfication document?

Please help me, Thanks!

Does not seem to support PI2

Hi,

I have tried this with the Raspberry PI2 and it does not seem to support that. That is, even if I manually set the board revision to (default it seems to select 2) I cannot get a pin to work. Is that correct?

Also - maybe I am missing something - but where can I find sample usages?

Watch multiple pins

Hi i'm using your library raspberry-sharp-io, working excellent. i got struck with watch multiple pins states, i tried to solve with Task parallel library but no use. you have already mentioned in the file Test.Gpio.watchpin\program.cs file "Todo" please complete this as early as possible, i'll be very thankful to u.

Questions about coding style

Hi,

I have two questions about the currently used coding style:

1.) #regions
Why do you use #regions? I know that I can quickly press Ctrl+M, Ctrl+O to collapse/expand all blocks. However I personally find them less helpful. They make it harder to refactor code and sometimes you separate closely connected methods.
(See also http://blog.codinghorror.com/the-problem-with-code-folding/)

2.) Omitting curly brackets
I have seen resolved merge conflicts that ended up like this:

from

if (test)
    action("foo");

to

if (test)
    action("bar");
    action("foobar");

Maybe not the expected result :-)

Greetings,
Daniel

PS: I have not forgotten about #14 I need to finish my other project first :-)

Possible support for T6963C-driven displays

Hello!
Firstly, thank you for this superb library! It already solves many of my problems I had to deal with like I/O expanders and I2C.
One point I still can't handle with is my T6963C-Display...
So I would like to ask if it would be much of an effort for you to implement the support for T6963C-driven graphic displays?
For example writing text with a choosable font and size or displaying monochrome pictures.

Thanks and keep up the great work!
Greets, Bjoern

Can't get I2C to work

I am trying to connect to the Adafruit Motor hat(that uses the Adafruit PWM code), but the code can't find a I2C device

Error

System.InvalidOperationException: No I2C device exist on the specified pins
  at Raspberry.IO.InterIntegratedCircuit.I2cDriver.GetBscBase (ProcessorPin sdaPin, ProcessorPin sclPin) [0x000a5] in <filename unknown>:0
  at Raspberry.IO.InterIntegratedCircuit.I2cDriver..ctor (ProcessorPin sdaPin, ProcessorPin sclPin) [0x00020] in <filename unknown>:0
  at motorTest.Motor_Hat..ctor (Int32 addr, Int32 freq) [0x00081] in /home/pi/motorTest/motorTest/adafruit_ports/Motor_Hat.cs:42
  at motorTest.MainClass.Main (System.String[] args) [0x00008] in /home/pi/motorTest/motorTest/Program.cs:9

Motor_Hat.cs(Relevant code)

public Motor_Hat(int addr, int freq = 1600){
    _i2caddr = addr;           
    _frequency = freq;          
    for(int i=1;i<5;i++){
        motors.Add (new DC_Motor (this, i));
    }
    steppers.Add (new Stepper_Motor (this, 1));
    steppers.Add (new Stepper_Motor (this, 2));
    var I2CDriver = new I2cDriver (ProcessorPin.Pin03, ProcessorPin.Pin05);
    _pwm = new Pca9685Connection (I2CDriver.Connect(addr));
    _pwm.SetPwmUpdateRate(_frequency);
    }

Am I doing anything wrong? The hat does work with the python code.

Share memoryFile between GeneralPurpose and I2cDriver

Well i have a I2C Screen and buttons, but when i initialize the GPIOConnection and then the i2c driver seens to override the connection to "/dev/mem" made by GPIOConnection and the buttons stop working, the solution maybe can be to create a new library only for the memory connection like "Raspberry.IO.MemoryConnection" so we can share the same connection??

TODO Completed : Watch multiple pins

using System;
using System.Linq;
using Raspberry.IO.GeneralPurpose;
using System.Threading;
using System.Threading.Tasks;

namespace Test.Gpio.WatchPin
{
class Program
{
static void Main()
{
Console.WriteLine("WatchPin Sample: log the state changes on input pin. \nTry to run it in parallel with i.e. Test.Gpio.HCSR501 or to test HCSR04 (IR motion detector) or SW-18020P (shake detector)");
Console.WriteLine();
Task monPin18 = Task.Factory.StartNew(() => Watcher("P1Pin18"));
Task monPin16 = Task.Factory.StartNew(() => Watcher("P1Pin16"));
Task monPin15 = Task.Factory.StartNew(() => Watcher("P1Pin15"));
Task monPin22 = Task.Factory.StartNew(() => Watcher("P1Pin22"));
Task.WaitAll(monPin15,monPin16,monPin18,monPin22);
Console.ReadKey();
//TODO: Allow watch multiple pins simultaneously
//TODO: Allow to specify pin in different ways, ie, by name, by wiringPi, etc.

    }
    private  static void Watcher(string pinName)
    {
        ConnectorPin userPin;
        if (!Enum.TryParse(pinName, true, out userPin))
        {
            Console.WriteLine("Could not find pin: " + pinName);
            PrintUsage();
            return;
        }

        Console.WriteLine("\tWatching Pin: {0}", userPin);

        Console.WriteLine("Press CTRL-C to stop");
        Console.WriteLine();
        var procPin = userPin.ToProcessor();

        var driver = GpioConnectionSettings.DefaultDriver;

        try
        {
            driver.Allocate(procPin, PinDirection.Input);

            var isHigh = driver.Read(procPin);

            while (true)
            {
                var now = DateTime.Now;
                Console.WriteLine(now + "." + now.Millisecond.ToString("000") + ": " +pinName +     (isHigh ? ": HIGH" : ": LOW"));
                driver.Wait(procPin, !isHigh, TimeSpan.FromDays(7)); //TODO: infinite
                isHigh = !isHigh;
                Thread.Sleep(500);
            }
            Task.Delay(500);
        }
        finally
        {
            // Leaves the pin unreleased so that other processes can keep reading
            //driver.Release(procPin);
        }
    }

    private static void PrintUsage()
    {
        Console.WriteLine("Usage: Test.Gpio.WatchPin [pin]");
        Console.WriteLine("Available pins:");
        Enum.GetNames(typeof(ConnectorPin)).ToList().ForEach(Console.WriteLine);

        Console.WriteLine("//todo allow watch multiple pins simultanously");
        Console.WriteLine("//todo allow to specify pin in diffrent ways, ie, by name, by wiringPi, etc");
        Console.WriteLine("I.e.: sudo mono Test.Gpio.WatchPin.exe P1Pin23");
        Console.WriteLine();
    }
}

}

Using Two SPI devices

Hi @ebezine ,

I'm experiencing conflicts using two spi devices (share violation on gpio...).
The first one is an MCP3008, while the second one is a Nokia3310 lcd display.

I managed to run both with a mutual access lock but when the program is reading MCP3008 values on the 3310 display do appear some dirty pixels.

So I thought it must been the SelectSlave that must be invoked before reading/writing from the spi, but there's no such method in the Mcp3008SpiConnection class.

Both spi devices are using same pins exception made for the CE0/CE1.

cam00030b

Cheers,
g.

Hd44780 - displaying random characters

I've got my 16x2 display setup as it's listed in the test program for it. It basically just displays your mac address and ip address for all your devices connected to the pi, then it repeats. However when I run it I usually get random characters that have nothing to do with what was actually sent to the display. sometimes it'll display the correct characters for part of a line but jibberish after that. I write a test program of my own and if I keep the write short to 3 characters it will usually display it properly. As example expected out put of "did" is usually "did", but sometimes it just displays a "d" on the second line. asking for a "123456789" to be displayed will result in something like "125Y8" or something like that . It's rarely the same jibberish that it displays for each expected output, multiple attempts at the same output give different results.

Raspberry.System.Board not up to date for latest revisions or hex values

The Board.Firmware property is not taking into account the revisions are in hex as well as the new revisions. The code below should handle this.

    /// <summary>
    /// Gets the board firmware version.
    /// </summary>
    public int Firmware
    {
        get
        {
            string revision;
            int firmware;
            if (settings.TryGetValue("Revision", out revision) && !string.IsNullOrEmpty(revision) && int.TryParse(revision, System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.CurrentCulture, out firmware))
                return firmware;

            return 0;
        }
    }

    /// <summary>
    /// Gets the board revision.
    /// </summary>
    public int Revision
    {
        get
        {
            var firmware = Firmware;
            switch (firmware)
            {
                case 2:
                case 3:
                    return 1;
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 13:
                case 14:
                case 15:
                    return 2;

                default:
                    return 0;
            }
        }
    }

Created support for MCP4261 DigiPot

Hi, I've added support for the MCP4261 digital potentiometre. However, not being a GitHub genie I cannot figure out to create a pull request for your consideration to include it.

Please advise.

i2c & sudo

I have some code using i2c which works fine in the console when elevated.

If I use it with winforms, then winforms doesn't work under sudo (get "check your display environment variable" error)

The winforms code not executed under sudo works fine but then I can't get to the i2c.
.
Any thoughts on how to work around this so that I can use i2c under winforms?

Support for UART serial communication

I'm not 100% sure this is not already somewhere in the codebase, but I couldn't find it. I need to start up a serial connection, write to it and read from it. I'd love to use common code syntax like:

Serial.Begin(speed [,rxPin, txPin])
Serial.Write
Serial.Read
Serial.OnData
Serial.Close

Or something similar.

Thoughts?

driver.Allocate defaults to low

When allocating an output pin like this

driver.Allocate(outputPin1, PinDirection.Output);

It seems the the pin is defaulted to low, it would be nice if you could pass in the default state like

driver.Allocate(outputPin1, PinDirection.Output, true);

I have a relay board where low means on so when the program allocates the output pin it defaults to low turning the relay on. Immediately after that i can do

    driver.Write(outputPin3, true);

But sometimes the relay still trips. I'm not sure if this is possible, if its not do you maybe have some work around where I can allocate the pin high instead of low?

Memory Gpio Bug ?

Hi,

In MemoryGpioConnectionDriver.cs

line 205
var pinGroupAddress = gpioAddress + (int)((value ? Interop.BCM2835_GPSET0 : Interop.BCM2835_GPCLR0) + offset);
should be 4_offset
BCM2835_GPSET0 is at 0x 7E20 001C
BCM2835_GPSET1 is at 0x 7E20 0020
or var offset = 4_Math.DivRem((int) pin, 32, out shift); in line 203

line 221
same missing : offset*4

by now not raspberry GPIO up to 31, so no way to detect the problem.

Bye

Future pull request

Hello

I'm working on adding support for the Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface - PCA9685 and hope to send you a pull request. It is already working to control a servo but I want to clean it up and improve a few things first.

I just want to check on a few things standard wise:

  1. I'm locating this PWM i2c component under expanders - is that correct?
  2. Should folders/classes be all caps (PCA9685) or camel case (Pca9685)?
  3. In order to support command line arguments, I added a Test.Util project so as to include Ndesk.Options. It helps keep the main program cleaner - see options example here, with usage here. Is that ok?
  4. I'd really like to have logging available in the Component class. Nlog is my preferred choice but that won't suit all consumers so I was thinking of implementing it via Common.Logging. This way each consumer can choose their own preferred logging implementation. Will this be accepted?

thanks for your efforts on this library. It was unexpectedly easy to add support for the PCA9585 when porting from Adafruit's Python library by standing on the shoulders of your i2c code.

Application fails with "Can't find custom attr constructor image"

I'm trying to run a mono app on Rasbian Jessie Lite and receive the following error. I think I'm missing a dependency but am not sure what to install.

pi@raspberrypi:~/myapp $ mono MyApp.exe
Can't find custom attr constructor image: /home/pi/MyApp/Raspberry.IO.GeneralPurpose.dll mtoken: 0x0a000014
Unhandled loader error: 8, (null) System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 (null)
* Assertion: should not be reached at loader.c:298

Stacktrace:


Native stacktrace:


Debug info from gdb:

[New LWP 887]
[New LWP 886]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
0x76e30ee8 in __libc_waitpid (pid=888, stat_loc=0x7ef2b14c, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40
40      ../sysdeps/unix/sysv/linux/waitpid.c: No such file or directory.
  Id   Target Id         Frame
  3    Thread 0x763ff430 (LWP 886) "mono" 0x76e2c7a4 in __pthread_cond_wait (cond=0x235420, mutex=0x235408) at pthread_cond_wait.c:187
  2    Thread 0x76a4b430 (LWP 887) "Finalizer" 0x76e2ea40 in do_futex_wait (isem=isem@entry=0x22a58c) at ../nptl/sysdeps/unix/sysv/linux/sem_wait.c:48
* 1    Thread 0x76f27000 (LWP 882) "mono" 0x76e30ee8 in __libc_waitpid (pid=888, stat_loc=0x7ef2b14c, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40

Thread 3 (Thread 0x763ff430 (LWP 886)):
#0  0x76e2c7a4 in __pthread_cond_wait (cond=0x235420, mutex=0x235408) at pthread_cond_wait.c:187
#1  0x001468a8 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 2 (Thread 0x76a4b430 (LWP 887)):
#0  0x76e2ea40 in do_futex_wait (isem=isem@entry=0x22a58c) at ../nptl/sysdeps/unix/sysv/linux/sem_wait.c:48
#1  0x76e2eaf4 in __new_sem_wait (sem=0x22a58c) at ../nptl/sysdeps/unix/sysv/linux/sem_wait.c:69
#2  0x0015f164 in mono_sem_wait ()
#3  0x0010d90c in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 1 (Thread 0x76f27000 (LWP 882)):
#0  0x76e30ee8 in __libc_waitpid (pid=888, stat_loc=0x7ef2b14c, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40
#1  0x0007a328 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

Aborted

spi sample

hi
could you please give me a simple simple of spi in software mod and hardware mod
i know there is in sample
but it is not just a simple spi and i cant't understand how the spi working

thanks

Interrupts

Forgive my ignorance, but are there any examples for configuring interrupts?

I am attempting to have an event fire on the falling edge of a given pin but so far I've been unsuccessful. I'm attempting to mimic the behavior I get using NETMF with "new InterruptPort(irqPin, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow)".

Build scripts

Hi there - I have some powershell buildscripts that I use in a few projects to make building a solution and building nuget packages a one step process.
Happy to contribute them in a PR - but I wasn't sure if you build the nuget packages using mono or .NET?

Personally I build everything in Windows / .NET and SCP the files over to the pi but wasn't sure if that was the official way. If not then powershell scripts wouldn't be of much use.

With the powershell scripts you could automate the publish and deployment of nuget packages via myget with very little effort.
Let me know if you would like the PR
cheers

dnxcore50 support

Any plan to support the new dnxcore50 framework?
otherwise is it impossible to use it on projects for Windows IoT

So thanks.

Button not working as expected on Raspberry Pi B V2

Hello,

I wired a simple push button as specified here http://razzpisampler.oreilly.com/ch07.html Whereas the ground is on Pin 39, and the GPIO being used is at Pin 37 (GPIO 26).

The code is as follows:

var switchButton = ConnectorPin.P1Pin37.Input().Revert().Switch().Enable().OnStatusChanged(x => {
Console.WriteLine("Button Switched {0}", b ? "on" : "off");
});

using(var connection = new GpioConnection(switchButton)){
Console.WriteLine("Init Completed");
Console.ReadKey();
}

When pressing the button the text is not getting stated, when manually shorting the wires the text is not getting stated, when using my finger and touching one of the wires the text gets randomly fired.

Under python the above wired setup works as expected.

Please advise on how to fix this problem.

Thanks,
Dan

I2C

Is I2C working, in the lib?
I am trying to connect an I2C Real Time Clock, but I don't understand how to read registrer # 2 on device of address 0x51. Tried by guessing, but no way.
Can you access single registers inside the controlled device with your library?

I2C: Repeated start conditions are not supported

These conditions are used to read registers from port expanders like PCA9555. The library does not allow to write and read within the same transaction. This issue also prevents reading from EEPROMs etc.

ANyone have a work copy

Ive trying to get this to compile on mono for two days now and between the third party libs and being new to mono it's just not happening. Does anyone have the dll's for this and any other files required. Id be will to PP someone a twenty just to get back to working on my actual project rather than spending more time beating my head against this particular wall

I2C not working on Pi 3

This code works on my Pi 2 but not the new Pi 3
The code and the libs for the project is on my github account

pi@Natsukipi:~/monodevelop/BattleBotServer/BattleBotServer/bin/Debug $ sudo mono BattleBotServer.exe

Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for BattleBotServer.Helpers ---> System.NotSupportedException: Connector pintout Unknown is not supported
  at Raspberry.IO.InterIntegratedCircuit.I2cDriver.GetBscBase (ProcessorPin sdaPin, ProcessorPin sclPin) [0x00000] in <filename unknown>:0
  at Raspberry.IO.InterIntegratedCircuit.I2cDriver..ctor (ProcessorPin sdaPin, ProcessorPin sclPin) [0x00000] in <filename unknown>:0
  at BattleBotServer.Helpers..cctor () [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at BattleBotServer.LogWriter.get_Instance () [0x00000] in <filename unknown>:0
  at BattleBotServer.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for BattleBotServer.Helpers ---> System.NotSupportedException: Connector pintout Unknown is not supported
  at Raspberry.IO.InterIntegratedCircuit.I2cDriver.GetBscBase (ProcessorPin sdaPin, ProcessorPin sclPin) [0x00000] in <filename unknown>:0
  at Raspberry.IO.InterIntegratedCircuit.I2cDriver..ctor (ProcessorPin sdaPin, ProcessorPin sclPin) [0x00000] in <filename unknown>:0
  at BattleBotServer.Helpers..cctor () [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at BattleBotServer.LogWriter.get_Instance () [0x00000] in <filename unknown>:0
  at BattleBotServer.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0

Don't found mscorlib.dll 2.0 version

Please,
I installed only mono-runtime and I found error using Raspberry-sharp:
"The assembly mscorlib.dll was not found or could not be loaded. It should have been installed in the `/usr/lib/mono/2.0/mscorlib.dll' directory."

Don't found nothing in the project using this version.

Utilizing internal pull up/down resistors

The Raspberry Pi supports internal pull up and down resistors. Have you considered adding an option so that when using the MemoryGpioConnectionDriver (BCM2835 library) class, this can be set for an input pin? I see comments in your code for the different options that bcm2835_gpio_set_pud takes to support this.

I don't think the File IO supports the internal pull up/down resistors at this time.

And thanks for creating and releasing RaspberrySharp.IO. I love .NET and am really enjoying your library.

Chris

can't build on mono

I could not build the solution on mono/Raspberry.
Is that supported?

(I can build on VS and run binaries on Pi without problems)

pi@raspberrypi ~/sandbox/raspberry-sharp-io $ xbuild
XBuild Engine Version 2.10.8.1
Mono, Version 2.10.8.1
Copyright (C) Marek Sieradzki 2005-2008, Novell 2008-2011.

Build started 735138/00/0001 16:43:56.
__________________________________________________
/home/pi/sandbox/raspberry-sharp-io/Test.Gpio.HCSR04/Test.Gpio.HCSR04.csproj:  warning : Could not find project file /home/pi/sandbox/raspberry-sharp-io//.nuget/nuget.targets, to import. Ignoring.
Project "/home/pi/sandbox/raspberry-sharp-io/RaspberrySharp.IO.sln" (default target(s)):
        Target ValidateSolutionConfiguration:
                Building solution configuration "Debug|Mixed Platforms".
        Target Build:
                Project "/home/pi/sandbox/raspberry-sharp-io/Raspberry.IO.GeneralPurpose/Raspberry.IO.GeneralPurpose.csproj" (default target(s)):
                        Target RestorePackages:
                                Executing: mono --runtime=v4.0.30319 /home/pi/sandbox/raspberry-sharp-io/.nuget/NuGet.exe install "packages.config" -source ""   -RequireConsent -solutionDir "/home/pi/sandbox/raspberry-sharp-io/"
                                Unhandled Exception: System.TypeLoadException: A type load exception has occurred.
                                [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: A type load exception has occurred.
/home/pi/sandbox/raspberry-sharp-io/.nuget/NuGet.targets: error : Command 'mono --runtime=v4.0.30319 /home/pi/sandbox/raspberry-sharp-io/.nuget/NuGet.exe install "packages.config" -source ""   -RequireConsent -solutionDir "/home/pi/sandbox/raspberry-sharp-io/"' exited with code: 1.
                        Task "Exec" execution -- FAILED
                        Done building target "RestorePackages" in project "/home/pi/sandbox/raspberry-sharp-io/Raspberry.IO.GeneralPurpose/Raspberry.IO.GeneralPurpose.csproj".-- FAILED
                Done building project "/home/pi/sandbox/raspberry-sharp-io/Raspberry.IO.GeneralPurpose/Raspberry.IO.GeneralPurpose.csproj".-- FAILED
        Task "MSBuild" execution -- FAILED
        Done building target "Build" in project "/home/pi/sandbox/raspberry-sharp-io/RaspberrySharp.IO.sln".-- FAILED
Done building project "/home/pi/sandbox/raspberry-sharp-io/RaspberrySharp.IO.sln".-- FAILED

Build FAILED.

Warnings:

/home/pi/sandbox/raspberry-sharp-io/Test.Gpio.HCSR04/Test.Gpio.HCSR04.csproj:  warning : Could not find project file /home/pi/sandbox/raspberry-sharp-io//.nuget/nuget.targets, to import. Ignoring.

Errors:

/home/pi/sandbox/raspberry-sharp-io/RaspberrySharp.IO.sln (default targets) ->
(Build target) ->
/home/pi/sandbox/raspberry-sharp-io/Raspberry.IO.GeneralPurpose/Raspberry.IO.GeneralPurpose.csproj (default targets) ->
/home/pi/sandbox/raspberry-sharp-io/.nuget/NuGet.targets (RestorePackages target) ->

        /home/pi/sandbox/raspberry-sharp-io/.nuget/NuGet.targets: error : Command 'mono --runtime=v4.0.30319 /home/pi/sandbox/raspberry-sharp-io/.nuget/NuGet.exe install "packages.config" -source ""   -RequireConsent -solutionDir "/home/pi/sandbox/raspberry-sharp-io/"' exited with code: 1.

         1 Warning(s)
         1 Error(s)

Time Elapsed 00:00:17.7723980

Compiling with the latest build of mono on Raspberry Pi 2

Hi, been successfully using the raspberry-sharp-io on Raspberry Pi 2. I did an update-distribution today which took me to the latest build of Mono Develop and mono complete. The Raspberry.IO.Interop project no longer compiles - get error message "The Dllimport attribute cannot be applied to a method that is a generic or constrained in a generic type".

Is this an issue with the latest compiler or have I damaged my pi setup. Cheers Dave

Always getting an exception GpioConnection: Object reference not set to an instance of an object

Hey.

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

Thank you for any help.
Kind regards.
Kris.

Benchmark

Hi there,
I'm just making my first steps with Raspberry and the Raspberry Sharp IO project, and it feels straightforward and good to use.
I'm wondering, if it is the Raspberry, the Mono-FW or the IO Library or my Setup, which makes some things a little bit slow: In my benchmark I write blind to a pin < 1ms, read < 1 ms, but if I connect the write-pin to the read-pin, I have to wait 0,1 sec before I can be shure to read the value written.
This is not a complaint, just wondering if you have similar timing values!
thx
Harry

    static void Benchmark ()
    {
        DateTime start = DateTime.Now;

        OutputPinConfiguration output = ConnectorPin.P1Pin11.Output ();
        InputPinConfiguration input = ConnectorPin.P1Pin12.Input ();

        using (GpioConnection connection = new GpioConnection (new PinConfiguration[]{ output, input })) {

            Console.WriteLine ("ConnectTime = " + new TimeSpan (DateTime.Now.Ticks - start.Ticks)); //3sec, long time

            const int testCount = 100;

            start = DateTime.Now;
            for (int i = 0; i < testCount; i++) {
                bool buttonPressed = connection [input];
            }

            Console.WriteLine ("ReadTime = " + new TimeSpan ((DateTime.Now.Ticks - start.Ticks) / testCount));  // < 1ms, quick

            start = DateTime.Now;
            for (int i = 0; i < testCount; i++) {
                connection [output] = (i & 1) > 0;
            }

            Console.WriteLine ("WriteTime = " + new TimeSpan ((DateTime.Now.Ticks - start.Ticks) / testCount)); // < 1ms, quick

            //ReadWrite: Connect output to input on breadboard
            bool status;
            start = DateTime.Now;
            for (int i = 0; i < testCount; i++) 
            {
                status = (i & 1) > 0;
                connection [output] = status;
                Thread.Sleep (100); //Write seems to be async, Errors if < 100ms! slow
                if (connection [input] != status)
                    Console.WriteLine ("Bullshit");
            }

            Console.WriteLine ("WriteReadTime = " + new TimeSpan ((DateTime.Now.Ticks - start.Ticks) / testCount));

            connection.Close ();
        }
        Console.ReadKey ();

    }

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.