Data Logger with OLED

Help, i am building a scale that will record weight from 2 scales and display it on an OLED. The hardware i am using
2 X HV711 from Spark fun
1 X datalogging shield from Adafruit

Everything works when i run the code individually however i cant seem to get everything to work all at once.

My code is Below.

  Example using the SparkFun HX711 breakout board with a scale
  By: Nathan Seidle
  SparkFun Electronics
  Date: November 19th, 2014
  License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

  This example demonstrates basic scale output. See the calibration sketch to get the calibration_factor for your
  specific load cell setup.

  This example code uses bogde's excellent library:
  bogde's library is released under a GNU GENERAL PUBLIC LICENSE

  The HX711 does one thing well: read load cells. The breakout board is compatible with any wheat-stone bridge
  based load cell which should allow a user to measure everything from a few grams to tens of tons.

  SD card attached to SPI bus as follows:
 ** CS - pin 10
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 **SDA - A4
 **SCL - A5
   Setup For the Sd Card Logger and RTC
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
//#include "RTClib.h"

#include <Adafruit_SSD1306.h>
#define OLED_RESET 4 
Adafruit_SSD1306 display(OLED_RESET);
const int chipSelectPin = 10;// for the data logging shield, we use digital pin 8 for the SD cs line
//RTC_DS1307 RTC; // define the Real Time Clock object

/* The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.

  Setup for the HX711(Dat,Clk,Gain) Gain can be omitted.

#include "HX711.h"

#define calibration_factor 500.0 //This value is obtained using the SparkFun_HX711_Calibration sketch

HX711 scaleA(2, 3);
HX711 scaleB(5, 4);

#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()

// the logging file
File logfile;

void error(const char *str)
  Serial.print("error: ");
  while (1);
void setup()
  Serial.println("HX711 scale demo");

  //////////////////////////////////// SD Card Setup///////////////////////////////////
  Serial.println("Type any character to start");
  while (!Serial.available());

#endif //WAIT_TO_START

  // initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(chipSelectPin, OUTPUT);

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelectPin)) {
    error("Card failed, or not present");
      Serial.print("error: ");
      // Serial.println(str);
      while (1);

  Serial.println("card initialized.");

  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i / 10 + '0';
    filename[7] = i % 10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile =, FILE_WRITE);
      break;  // leave the loop!

  if (! logfile) {
    error("couldnt create file");
      Serial.print("error: ");
      //  Serial.println(str);

      while (1);

  Serial.print("Logging to: ");
  logfile.println("millis,Year,Time,Reading A(grams),Reading B(grams)");
  Serial.println("millis,Year,Time,Reading A,Reading B");

 /* // connect to RTC
  if (!RTC.begin()) {
    logfile.println("RTC failed");
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL

  scaleA.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scaleB.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch

  scaleA.tare(10);  //Assuming there is no weight on the scale at start up, reset the scale to 0
  scaleB.tare(10);  //Assuming there is no weight on the scale at start up, reset the scale to 0


void loop(void) {
  //////////////////////////////////////////SD-LOG Code Start/////////////////////////////////////////
 // DateTime now;
  // log milliseconds since starting
  uint32_t m = millis();   // milliseconds since start
  logfile.print(m);           // milliseconds since start
  logfile.print(", ");
  Serial.print(m);         // milliseconds since start
  Serial.print(", ");

/*  // fetch the time
  now =;
  // log time
  logfile.print(now.year(), DEC);
  logfile.print(now.month(), DEC);
  logfile.print(, DEC);
  logfile.print(" , ");
  logfile.print(now.hour(), DEC);
  logfile.print(now.minute(), DEC);
  logfile.print(now.second(), DEC);
  logfile.print(scaleA.get_units(), 2);
  logfile.println(scaleB.get_units(), 2);

  Serial.print(", ");
  /*Serial.print(now.year(), DEC);
  Serial.print(now.month(), DEC);
  Serial.print(, DEC);
  Serial.print(" ");
  Serial.print(now.hour(), DEC);
  Serial.print(now.minute(), DEC);
  Serial.print(now.second(), DEC);
  Serial.print("ReadingA: ");
  Serial.print(scaleA.get_units(), 2); //scale.get_units() returns a float
  Serial.print(" g,     "); //You can change this to kg but you'll need to refactor the calibration_factor
  Serial.print("ReadingB: ");
  Serial.print(scaleB.get_units(), 2); //scale.get_units() returns a float
  Serial.println(" g"); //You can change this to kg but you'll need to refactor the calibration_factor


  // Now we write data to disk! Don't sync too often - requires 2048 bytes of I/O to SD card
  // which uses a bunch of power and takes time
  // if ((millis() - syncTime) < SYNC_INTERVAL) return;
  //syncTime = millis();

  //////////////////////////////////////////SD-LOG Code end/////////////////////////////////////////

void displaydata() {
  display.setCursor(0, 0);
  display.println(scaleA.get_units(), 2);
  display.setCursor(35, 0);
  display.setCursor(50, 0);
  display.println(scaleB.get_units(), 2);
  display.setCursor(95, 0);
  display.setCursor(0, 10);
  display.setCursor(65, 10);
  display.setCursor(0, 20);
  display.setCursor(65, 20);


So, the code

you posted does something.

But, you didn't post it properly OR tell us what it does.

You expect the code, with the ridiculous amounts of white

space to do something, but you failed to tell us what you expect.

How can you expect us to help you correct your expectations when you don't tell us what they are, or how they differ from reality?

Sorry, this is my first attempt at posting on any forum. If i remove any reference to the OLED from the code above everything works a treat. After adding the OLED code the SD card is not detected and everything stops. want the code to read 2 HV711, save the weight to an SD card and display it on the OLED with the current time.

Using which Arduino? I suspect that you do not have enough memory if you are using a 328-based Arduino.

I am using the Arduino Uno. Do you have any advice on anyway I can verify that?

You're not making much use of the F() macro - maybe start with that - it'll get some RAM back

Or a '1284P board, 16K of SRAM.
I offer a '1284P board with SD, RTC, some prototype area, Signal/5V/Gnd at each pin, onboard or offboard (shown) USB, RS232 buffer for 2nd hardware serial if needed, screw terminals are an option