Saturday 22 June 2013

OLED Driver working!

The OLED driver code is almost done and is giving an output, although noise seems to be an issue. I'm going to buy some DuPont jumper wires to connect directly to the Raspberry Pi rather than breadboard. 20Mbps over breadboard is pushing it really :) Here's a picture of the OLED displaying time, all written in C#!

The resistor in the picture is just to hold the flappy display down. Under the display is a pcb which holds several capacitors for the dc to dc charge pump and a current limiting resistor. The current limits the OLED drive current for the pixels and the charge pump converts the 3.3v from the RPi to around 7 to 12v for the pixel drive voltage.

I also decided that rather than make one board, I'd make a few extra plus some other boards such as an AD7190 analogue to digital converter (a very, very low noise one for bridge sensors such as a load cell or gas sensor). An AD9834 DDS board with a 50MHz master clock source, I can use this to generate any frequency I want up to about 15MHz useable in sub hertz steps. The last board is a CAN BUS controller such as used in cars and industrial control. The can controller is based on the MCP2515 controller and MCP2551 can interface. Here's pictures of the rough, not yet cleaned up, pcb's:

I'll update the git hub repository with my latest updated wrapper class and test modules so anyone can have a play. For my next trick, DDS board with scope pictures and code updates!

Wednesday 8 May 2013

A great start...

Today was a great success to say the least. Some of my coding in recent months has surprised me when it's just worked right first time. It doesn't always happen but when it does, it's a great feeling.

I completed the library and paid particular attention to the pointers that Gordon Henderson uses in his WiringPi library. After learning of some different marshalling techniques I picked one that looked as though it did exactly what I wanted with the right performance, after all if it's worth coding, write it to be as simple and efficient as possible. Recompiling the WiringPi libraries as shared objects was something I'd seen somewhere in my Mono and Raspberry Pi searches so I decided to go with that. The commands to do so are: cc -shared wiringPi.o -o libwiringPi.so You'll need to do the same on all the libraries such as wiringPiSPI, wiringPiI2C etc.

The libraries just recompiled as shared objects are then imported by the WiringPi.WrapperClass in the visual studio solution. The console application in the solution has a reference to this wrapper and the LoopTest project is just a simple console application which writes 0xAA and 0x55 and tries to read the data back.

After copying the compiled code SPITest.exe, WiringPi.dll and pdb files I ran the code with the command sudo mono SPITest.exe and got this reply:

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

This is great as I'd expected this or to receive an all ones message. Now to short out the MOSI pin to the MISO pin. (Master Out Slave In, Master In Slave Out) This should mean what we write is what we get back because the interface is full duplex i.e. simultaneous write and read. Sure enough we get our Loopback is connected! message.

This is a great start but there's more to do, libraries for common devices and different scenario's is one area I think many would benefit from including myself. First I need to make a few pcb's for the devices I do have in stock. MRF24J40 radio modules, temperature sensor, OLED display, DDS chip, load cell interface, the list goes on and on....

See my github repo here: https://github.com/danriches/WiringPi.Net for the code, enjoy and feel free to comment...

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 ;)