Main Site Documentation

Creating new SPI module


#1

Hi everyone, I’m new here so first of all I want to say hello.
Second, I want to ask you some questions about the SPI protocol.
I’m buying a digital Potentiometer that supports SPI protocol but I’m wandering how to begin writing the code to control the module.

The Potentiometer is this one:

I’d appreciate any help or useful examples.
Thanks ahead!


#2

Do I need to create a new module first?


#3

Hi there Bioengproject, welcome to the forum.

You should check out https://www.ghielectronics.com/community/codeshare/entry/344

If you really want to convert the “driver” like the attached into a “module” then you need to know a bit about things documented in the module builders guide - not impossible but possibly also overkill as an early project. You can still use the device without it being a module that you can drag and drop in the designer - so it’s far from “mandatory” to do this.


#4

Thank you all for the replies.
By module I meant to create new object like these in the toolbox of GHIElectronics which you drag to the Program.gadgeteer and connect it to the mainboard.

To summarize, my mission is to connect digital SPI potentiometer (0 to 10K ohm) to the gadgeteer so i would be able to control it through to code.

Any ideas ?


#5

@ bioengproject - making a module is a bit of challenge if you dont have much electronics experience but not impossible. Ive done it and I’m certainly not an electronics engineer or a pro coder.

Your experience levels with both of these will dictate how fast you can do it but dont be put off. Its a great feeling when you finish the module and it works.

Firstly go to the gadgeteer codeplex and grab the module builders guide and the templates (these templates will help you make the software module to go into the VS designer) http://gadgeteer.codeplex.com/releases

Read the builders guide carefully. It gives you all the info on how the module should look and be labled (eg rounded corners, 5mm grid spacing on the holes etc.

Next grab a copy of Eagle PCB its free and relativley easy to use.
Then you can start the process remember to make sure that the socket connections are correct http://gadgeteer.codeplex.com/wikipage?title=.NET%20Gadgeteer%20Socket%20Types

Pete brown did a nice writeup on how to make a module here http://10rem.net/blog/2011/10/30/building-a-net-gadgeteer-compatible-hardware-and-software-module-der-blinkenled
another one from our own Ransomhall http://www.ransomhall.com/Pages/Piezo.aspx
and http://stevenjohnston.co.uk/2013/05/30/i-built-my-own-net-gadgeteer-module/

laslty ask as many questions here as you want. we are all here to help :slight_smile: this is possibly the finest help forum on the net. No question is too simple so dont be afraid to ask.
Once you have finished you can add the module to the creations section of this site and maybe sell a few modules too :slight_smile: another great incentive to get building.


#6

I’m creating an electrical circuit for my engineering project. I thought it would be cool to control the resistor with the code. In the mean time it’s not module for sale but maybe if all goes well I will publish here the code, hopefully :slight_smile:


#7

Get an extender module and a breakout board for your digital potentiometer, wire it up, and that’s all you need. If you want a more polished solution, you want both a physical hardware module (ie the Eagle PCB route) as well as a software defined module (ie the Module Builder documentation for a driver). If you just want to control the pot with code, the code I pointed you to should work and the only thing you need is to wire it up somehow (that’s why I suggest a breakout board and extender above).

I think controlling this in code is the easy part, since someone has already done that for you. Slightly harder is connecting one up, slightly harder is making a self contained hardware module and hardest is writing a driver/wrapper as a real module that you can use from the toolbox.


#8

But this is idea of the SPI protocol, isn’t it? To make life easier.
Thanks for the advice though


#9

Is what the idea of SPI? SPI just happens to be a protocol that is commonly used in integrating two different microprocessors together.

The concept of Gadgeteer is to provide easy ways for people to connect common building blocks in a usable prototype or small production runs. It’s not a be-all-end-all list of every single device (like your Microchip digital potentiometer), but it gives an extensible way to make these things accessible to people should the need arise. It is designed to allow simple ways to interact with these devices - so that you don’t need to know the fundamental SPI communication layer for instance, or the specific SPI commands to interact with the processor - you just need to use the high level functions that the module driver exposes.

For example, high level functions for a digital pot might be

SetResistance(potentiometer.10k);
SetResistance(potentiometer.min);
SetResistance(potentiometer.max);

Below that, the code would need to know how to set a particular resistance via the SPI commands that need to be issued to the chip. Below that, the driver needs to know how to talk to the device over SPI. Below that, the netmf implementation needs to know how to talk to the SPI peripheral on the mainboard processor (and you don’t need to worry about that as either an end-user or a module designer).

So in your case, because you’re setting out on this journey, you first need a way to connect your physical digital pot to a Gadgeteer mainboard - that’s the hardware part, where you will wire things up. As I said, a breakout module and a MCP device on a breakout board is probably the simplest way to achieve that.

You then need a way to communicate to the MCP device - there’s code for that already, but you can create your own if desired, or extend it for your needs. If you only need to use the device and you aren’t intending to develop this more fully as a module, then you really don’t need to do much more than what the existing code does - you certainly don’t need to “Gadgeteer-ise” it