Wire/i2c on Trinket 5v and M0

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
dkernal
 
Posts: 1
Joined: Tue Jun 12, 2018 11:12 am

Wire/i2c on Trinket 5v and M0

Post by dkernal »

***Update #1

The testing I've done to date has been with two TI PCF8574AN (according to their markings) chips right on the breadboard. In my effort to understand what's going on, I tried a breakout board which uses an NXP PCF8574T (according to its markings) and all of my boards can speak to it. That is, everything works as expected. Additionally, if I wire the breakout into the i2c bus on the original circuit, the trinkets can see all three PCF8574 slaves and all three are fully addressable. The two TIs work continue to work as expected even with SDA disconnected from tne NXP breakout.

So, whatever was wrong is fixed by adding the breakout. I'm out of my depth in interpreting these symptoms, and would appreciate any thoughts that might help explain things to me.




*** Original Post

I'm at a loss here, and hope someone can offer some advice, insight or suggest a next step. I have the same sketch working separately on an Uno r3 and a Teensy 2.0, but failing when I try it on a Trinket 5V or a Trinket M0.

The the code below is based on a TronixStuff i2c example using the PCF8574 I/O expander to flash a sequence of LEDs. My schematic is the same as the TronixStuff example, except I'm only using two PCF8574 chips.

https://tronixstuff.com/2010/10/29/tuto ... -part-two/

FWIW, I'm on Adafruit board manager 1.6.23 and the Ardunio IDE 1.8.9 trusted Windows install

I've also run the i2cscanner sketch from here https://playground.arduino.cc/Main/I2cScanner/, (modified to use tones instead of serial.print for the trinket 5v ) and neither Trinket sees any i2c devices.

thanks
...D

Code: Select all

// for trinket
// i2c SDA pin 0
// i2c SCL pin 2

// for uno
// i2c SDA pin A4
// i2c SCL pin A5

#include <Wire.h>

#define firstbank 0x38  // 7bit i2c address of our first PCF8574 chip
#define secondbank 0x39 // 7bit i2c address of our second PCF8574 chip

int blinkDelay = 20; // used for delay timing

void setup()
{
  Wire.begin();
  allOff(); // the PCF8574N defaults to high, so this functions turns all outputs off
}


void allOff()
{
  byte highOff = 255;
  Wire.beginTransmission(firstbank);
  Wire.write( highOff );
  Wire.endTransmission();
  Wire.beginTransmission(secondbank);
  Wire.write( highOff );
  Wire.endTransmission();
}

void sequencelights( byte bank)
{
  byte highOff = 255;
  for (int y = 1; y < 256; y *= 2)
  {
    Wire.beginTransmission(bank);
    Wire.write( highOff - y ); // we need the inverse, that is high = off
    Wire.endTransmission();
    delay(blinkDelay);
    Wire.beginTransmission(bank);
    Wire.write(highOff);
    Wire.endTransmission();
    delay(blinkDelay);
  }
}

void alert()
{
  for (int z = 0; z < 5; z++)
  {
    sequencelights(firstbank);
    sequencelights(secondbank);
    delay(100);
  }
}

void loop()
{
  alert();
  allOff();
}
Attachments
Wiring2.png
Wiring2.png (380.42 KiB) Viewed 205 times

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Wire/i2c on Trinket 5v and M0

Post by adafruit_support_mike »

You probably need to add external pull-up resistors to the SDA and SCL lines.

The Trinkets are small enough that they don't have built in pull-ups.

User avatar
jps2000
 
Posts: 811
Joined: Fri Jun 02, 2017 4:12 pm

Re: Wire/i2c on Trinket 5v and M0

Post by jps2000 »

Pullups are there. But I get cold shudder noticing all those LED`s without series resistors.

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”