Confusion with datasheet-SCL and SDA

Hi all,

I am using an ATTiny3217 QFN package and I need some clafification on which pins SDA and SCL are. The code below used to work but for some reason I have no clock signal to the display.

Any ideas.

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <EEPROM.h>
//#include <GEARS_TNR.h>
//#include <GEARS_TNR_INV.h>
//#include <GEARS_NAVILU.h>
//#include <GEARS_NAVILU_INV.h>
//#include <GEARS_C059.h>
#include <GEARS_C059_INV.h>

#define OLED_RESET 4

int GearStart;
int Gear;
int SetGear;
int sensorVal;
int out1 = (PIN_PC0); //17;
int out2 = (PIN_PC1); //18;
int out3 = (PIN_PC2); //19;
//int out4 = 15; //Unsure why this is here, forgot why I put it here.

Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);


void setup()
{

  delay(500); //wait to settle
  pinMode(out1, OUTPUT);
  pinMode(out2, OUTPUT);
  pinMode(out3, OUTPUT);
//  pinMode(out4, OUTPUT);

  // Read sensor value
  sensorVal = analogRead1(PIN_PC5);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //or 0x3D                                                    
  display.setRotation(1);

  //Save Gear to EEPROM

  SetGear = EEPROM.read(0); //Load gear from EEPROM

  if (SetGear == 0) {
    Set_ATRE_Gear();
  }

  if (sensorVal <= 665 )
  {
    // No Change
    Gear = EEPROM.read(0); //Load gear from EEPROM
  }
  else if  (sensorVal > 665 and sensorVal <= 800)
  {
    Gear = 1; //4th Gear
  }
  else if  (sensorVal > 800 and sensorVal <= 905)
  {
    Gear = 2; //5th Gear
  }
  else if (sensorVal > 905 and sensorVal <= 980)
  {
    Gear = 3; //6th Gear
  }

  EEPROM.update(0, Gear); // Only writes if different

  switch (Gear)
  {
    case 1:  digitalWrite(out1, HIGH); break;
    case 2:  digitalWrite(out2, HIGH); break;
    case 3:  digitalWrite(out3, HIGH); break;
  }

}

void loop()
{
//  digitalWrite (out4, LOW);

  // Read sensor value
  sensorVal = analogRead1(PIN_PC5);

  Gear = EEPROM.read(0); //Load gear from EEPROM

  if (sensorVal > 300)

    switch (Gear)
    {
      case 1:  digitalWrite(out1, HIGH); break;
      case 2:  digitalWrite(out2, HIGH); break;
      case 3:  digitalWrite(out3, HIGH); break;
    }

  if (sensorVal > 300 and sensorVal <= 420)
  { display.clearDisplay (); //for Clearing the display
    display.drawBitmap (0, 0, GEAR1, 64, 128, 1);
    display.display ();
  }

  else if (sensorVal > 420 and sensorVal <= 540)
  { display.clearDisplay (); //for Clearing the display
    display.drawBitmap (0, 0, GEAR2, 64, 128, 1);
    display.display ();
  }

  else if (sensorVal > 540 and sensorVal <= 665)
  { display.clearDisplay(); //for Clearing the display
    display.drawBitmap (0, 0, GEAR3, 64, 128, 1);
    display.display ();
  }

  else if (sensorVal > 665 and sensorVal <= 800)
  { display.clearDisplay (); //for Clearing the display
    display.drawBitmap (0, 0, GEAR4, 64, 128, 1);
    display.display ();
  }

  else if (sensorVal > 800 and sensorVal <= 905)
  { display.clearDisplay (); //for Clearing the display
    display.drawBitmap (0, 0, GEAR5, 64, 128, 1);
    display.display ();
  }

  else if (sensorVal > 905 and sensorVal <= 980)
  { display.clearDisplay (); //for Clearing the display
    display.drawBitmap (0, 0, GEAR6, 64, 128, 1);
    display.display ();
  }

  else if (sensorVal > 980)
  {
    digitalWrite(out1, LOW);
    digitalWrite(out2, LOW);
    digitalWrite(out3, LOW);

    display.clearDisplay (); //for Clearing the display
    display.drawBitmap (0, 0, GEAR7, 64, 128, 1);
    display.display ();
  }

}

void Set_ATRE_Gear()
{
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("");
  display.println("YOU");
  display.println("NEED");
  display.println("TO");
  display.println("SET");
  display.println("YOUR");
  display.println("GEAR!");
  display.display();
  delay(5000);

}```

Not sure about your pin problem, but...

EEPROM read(), write(), and update() operate on a single byte.

If you are using multi-byte types, like int, then you should use get() and put().

EDIT.. the pins for I2C looks like PB0 (SCL) & PB1 (SDA) ... physical pins 16 & 15.

Thanks for your reply.

They are the pins I am using but for some reason I am not getting the SCL signal on the pin.

Also I am only writing a single byte.

Do I need to set baud rates or enable SCL or is this automatic?

Do you have pull up resistors on the I2C lines? (typically 4.7k)

No.

Should I have them?

I also see about 50mV of noise at 3.3V which in itself seems odd seeing I am running on 5V.

Yes, because there are only 2 logic level outputs from I2C, Low and Open circuit . The default condition is all chips on the line are in open circuit mode, and the pull-up resistor makes the line high.

EDIT: Note that sometimes they are already part of the client device.

I think I will replace the chip again. I may have fried it. I am sure this used to work. It programs ok but doesn't do what it should. The current display show a whole lot of random dots which I am assuming what the last clocked input. I changed the display and it shows nothing.

I would like to see an annotated schematic as you have it wired showing all connections including power and ground.

I will post it tonight.

Sorry for the delay. Here at is.

WondATRE_R0.4.pdf (57.7 KB)

If the SSD1306 display you are using does not include pull-up resistors then you need them in your circuit... I2C won't work without them.

Nice Schematic! I would use something in the 50 Ohm range for the gate resistors. Also you can then use the 10K resistors as pull down for the arduino pins driving the MOSFETs. This will guarantee they are off during power up and reset.

It has worked before.

I had a hard drive crash and lost the latest version of the software so the one I am using just doesn't seem to work. I am guessing it is going to be a combination of things. I will try pull ups anyway.

Wouldn't 50R be a bit small?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.