Use mikroBUS on C001

Are there any examples of using a mikroBUS Click board on the new impC001? Lots of the Click boards using the mikroBUS SDK. -Shawn

MikroBus boards are generally just breakouts for a specific chip and hence it’s not as much a MikroBus specific job as just a driver for the chip on the board.

eg, the GPS click works just fine with the imp GPS library. The Wiznet click works just fine with the imp Wiznet library… and so on.

What click were you looking at? There may be a driver for it already.

I was looking at the easiest DIY to measure some AC current. The MIKROE-2523 looks good. It’s using a MCP3201 which will be easy to use with the C001 SPI interface. I have not looked to see if the MCP3208 library can be used.

Thanks Hugo

The MCP3201 is super simple to use - it doesn’t even have a data input pin, so there are no commands you can send it.

Looking at figure 5-2 in the datasheet, you should just be able to read data like this:

// Configure SPI as mode 0, 500kHz, and CS pin as high (max rate 800kHz at 2.7v)
local spi = hardware.spiXX;
spi.configure(SIMPLEX_RX | CLOCK_IDLE_LOW | MSB_FIRST, 500);
cspin.configure(DIGITAL_OUT, 1);

// Drive /CS low and read two bytes (16 clocks output)
cspin.write(0);
local raw = spi.readstring(2);
cspin.write(1);

// Extract converted value: top 3 bits and bottom one bit are ignored
// Range should be between 0-4095
local sample = (((raw[0]<<8) | raw[1]) & 0x1ffe) >> 1;

That’s written blind but should work ok I think.

We intend to use the MCP3424 adc as it looks a better device with 4 inputs up to 18 bits plus internal ref and PGA. However, it use the I2C interface and looks more complicated to setup codewise. The nearest Imp library is MCP3208 which is SPI device.
There are arduino C libraries available for the MCP3424.

Hugo, maybe you will add this device in the future, but if not, it could be useful to include in tutorial on how to write Imp libraries.

Re. MCP3424 lib development, we already have the guides you need:

How to port Arduino code: here.
How to write and submit libraries: here.

Thanks for reply.
How do you deal with header ,h files in arduino libraries ?

There aren’t headers in squirrel, it all goes in one library file. Immutable values (like #defines in C) are done as class statics, see “immutable values” in the “how to write and submit libraries”.

However, you really don’t need to write a library unless you feel like it. You can just write a driver that does what you need and be done with it - libraries are things we test and support, many many customers don’t use any libraries.

Hi @hugo, do you have any guidance or template on how to write a mikroBUS driver that works with Imp development boards (I’m specifically looking at using a MikroE 3-click fingerprint sensor with a imp006 break-out board)? Thanks.

Mikrobus is not a “bus”, it’s just a common pinout. You’d need to check the datasheets for the fingerprint sensor and write an appropriate driver for that chip using whatever interface it needs (will be SPI, UART or I2C as those are the ones on the mikrobus pinout).