Author Topic: Digispark with BareConductive library MPR121.  (Read 300 times)

juliusbangert

  • Newbie
  • *
  • Posts: 2
Digispark with BareConductive library MPR121.
« on: January 11, 2017, 07:41:57 am »
I've just got the blink sketch running on my Digispark Attiny85 board and was excited to discover that this little setup could do i2c. I've been working on a capacitive touch project using the MPR121 chip and an Arduino Pro Mini (Atmega328P), I use the BareConductive MPR121 library : https://github.com/BareConductive/mpr121.

This is all good and working and I would now like to port this over to the Attiny85. I have connected everything up as I did with the Pro Mini board using pins 0 & 2 for SDA & SCL and pin 4 for interrupt.

The problem is that the library uses Wire and Serial includes and I'm not sure which parts of these .h and .cpp files to alter. I guess the Wire include is needed to i2c communication, and the Serial include is for talking to Processing.

I know things are quite different with this chip, but please could anyone give me pointers to get things working with the Digispark board? I've read about SoftSerial and TinyWireM but don't know how to implement these.

PeterF

  • Hero Member
  • *****
  • Posts: 765
Re: Digispark with BareConductive library MPR121.
« Reply #1 on: January 11, 2017, 11:37:17 pm »
AFAIK (and exeng/et al will either back me up or call me out on it ;) ), you won't need to worry about the TinyWireM I2C, as a renamed copy was included as Wire, so it *should* be as near as a drop in substitute for that used on the Nanos/Unos etc.

Since the MPR121 uses I2C, any code referencing Serial is either using it for debugging / output / linking to Processing. So the question here is are you using some example code that uses Processing (which you can do away with), or are you developing something that needs to be able to talk to processing via Serial?

For the soft-serial stuff, have a look at the example provided with the Digispark Arduino IDE package - File -> Examples -> DigisparkSoftSerial -> SoftSerialExaample

But basically you'd include the libraries
Code: [Select]
#include <SoftSerial.h>   
#include <TinyPinChange.h> 

Create a soft serial object declaring which pins you'll be using (maybe 1 & 3 in your case?)
Code: [Select]
SoftSerial mySerial(1, 3); // RX, TX
In the setup function, initialize the soft serial, specifying baud rate (just like normal serial)
Code: [Select]
mySerial.begin(4800);
And then use it normally in the main loop... i.e
Code: [Select]
if (mySerial.available())
newInput = mySerial.read();

juliusbangert

  • Newbie
  • *
  • Posts: 2
Re: Digispark with BareConductive library MPR121.
« Reply #2 on: May 11, 2017, 05:01:31 am »
Hi PeterF, thanks for your reply. I've been away from this project for a while but now getting back to it, I've tried your suggestion.

I'm trying to run the BareConductive MPR121 SimpleTouch example with relevant changes and I get the following compile error :

Code: [Select]
..../Documents/Arduino/libraries/BareConductive_MPR121/MPR121.cpp: In member function 'void MPR121_t::goSlow()':
..../Documents/Arduino/libraries/BareConductive_MPR121/MPR121.cpp:129:7: error: 'class USI_TWI' has no member named 'setClock'
  Wire.setClock(100000L); // set I2C clock to 100kHz
       ^
..../Documents/Arduino/libraries/BareConductive_MPR121/MPR121.cpp: In member function 'void MPR121_t::goFast()':
..../Documents/Arduino/libraries/BareConductive_MPR121/MPR121.cpp:133:10: error: 'class USI_TWI' has no member named 'setClock'
     Wire.setClock(400000L); // set I2C clock to 400kHz
          ^
exit status 1
Error compiling for board Digispark (Default - 16.5mhz).

Do you have any idea how I can fix this to work with the digispark I2C and renamed copy of Wire / WireTinyWireM ?