Monday, 29 April 2013

Here we go...

I've never done a blog before or anything like this really, so bear with me.

I bought two Raspberry Pi's of late and have been messing about with them for a while, learning or rather relearning linux shell commands and the file system. It takes a while to get to grips with especially when you've limited time being busy and all. One of the Pi's has given me loads of problems which I've narrowed down to it being a really early model that has the polyswitch fuses on the USB ports. Sadly I only found out after it trashed, and I mean totally killed, one of my SD cards.

Normally I wouldn't have documented all my Pi dealings but a few people have asked for any pointers and now I can point them here.

I'm not going to draw attention to setting up a Pi, everyones already done it. Rather I want to share getting electronic gadgets or interfaces connected and running. Initially I'll support this all through the use of C#, my favourite programming language for many reasons. I'll later go on to using C / C++ as I learn it and try to explain everything as best I can. Of course I welcome comments, keep them clean please, constructive or otherwise. I'm always open to new suggestions and ways of doing things so fire away.

First up see this post on the Raspberry Pi forums for getting Mono up and running. I'm only going to support this method on the hard float version of Raspbian, you're on your own with the soft float release (sorry). Currently, at the time of writing, the hard float version doesn't work with the usual distro release of mono, the linux version of the Windows .Net Framework and CLI as there are bugs with DateTime.Now for one.

You can use the Raspberry Pi.Net solution from cypherkey on github if you only want gpio. However I want SPI and I2C working as most of my projects use ADC's (Analog to Digital Converters) and OLED displays which communicate over SPI. Although this library does support SPI and I2C, it uses the bit bang method rather than using the dedicated hardware. This means it's slow, uses more cpu time than necessary and my devices need high speed. One of these is a 10/100 ethernet chip that'll need 20MHz clock cycles if not more and using a library which pulses bits rather than hardware doing it for you, which is why it's there, seems a cop out to me but hey it works.

I'm going to wrap up Gordon's Wiring Pi library which is written in C and can be found on his site here, take a look and you'll see it uses the hardware and we can ramp the speed up to 32MHz which is impressive. First we have to grab the library and compile it, then create a shared library so we can wrap the function up in a C# class so everyone out there can connect all sorts of stuff from SparkFun and AdaFruit etc. We can even get some of those Arduino shields connected, I've not got any myself or an Arduino but I can enlist a friend who does if I need to.

So, on to writing the wrapper. I'll update this blog as I go, here goes nothing ;)

No comments:

Post a comment