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...

No comments:

Post a Comment