BlinkM and Spark Core

BlinkM Library for Spark Core. Original BlinkM_funcs.h and removed some method that are not compiling for Spark Core. Those uses twi_writeTo function. Is there any replacement function in Spark Core?

3 Likes

Awesome!

I’m not super familiar with porting that over, but I can point you to our Wire.write function in the docs here: http://docs.spark.io/#/firmware/wire-write

Thanks!
David

1 Like

Hi, I am using the BlinkM_funcs.h too and came across the twi_writeTo functions. i know the wire library is built in to the dev but how does it cover the twi_writeTo functionality? is there a wiring function that substitutes that or is there another header that you should inlcude?

You could try this implementation to bundle a set of instructions into the respective functions

// Write data to the register having address = reg_address on the device having address = dev_address 
void twi_writeTo(int dev_address, int reg_address, int data) {
  Wire.beginTransmission((uint8_t)dev_address);
  Wire.send((uint8_t)reg_address);
  Wire.send((uint8_t)data);
  Wire.endTransmission();
}

// Read data from the register having address = reg_address from the device having address = dev_address
// for quantity bytes
void twi_readFrom(int dev_address, int reg_address, int *buff, int quantity) {
  Wire.beginTransmission((uint8_t)dev_address);
  Wire.send((uint8_t)reg_address);
  Wire.endTransmission();
  Wire.beginTransmission((uint8_t)dev_address);
  Wire.requestFrom((uint8_t)dev_address, (uint8_t)quantity);
  uint8_t i = 0;
  while(Wire.available() && i < quantity) {
    buff[i++] = (int)Wire.receive(); // receive a byte
  }
  Wire.endTransmission();
}

Code taken from here and slightly altered (untested)

If you could report back whether my proposed functions do what you expect, it would be nice to know, since it might even be worth a pull request.

1 Like

Hi @coldquanta

Have you tried using @krvarma library above from github? It looks like he fixed the blinkm.h file to use standard Wiring calls for the i2c interface. He set this up before the web IDE build could take libraries so you will have to cut-and-paste code using the circle-plus to open a new tab if you are using the web IDE.

Or I see the @ScruffR has a different idea for you. Either would work.

1 Like

ok so the @krvarma library fixed everything. the only error that i am getting now is about a missing “;” in saprk_wiring_I2c.h!!! isn’t this a built in declaration?

the script from @ScruffR needs some mods, the Wire.send and Wire.recieve seems to need to change to Wire.write and Wire.read and also the void return type causes some error in the BlinkM_funcs.h

Thanks for the input, I’ll look into it then :+1:

Found a “better” source for twi_ implementations
http://todbot.com/arduino/sketches/GPSWiiUI/twi_funcs.h

i found the missing “;” in my code, it is a little difficult to find if you have a large code. the error does not point to the correct line in the correct file.
but after that all works perfect.

1 Like