// Simple I2C test for ebay 128x64 oled.
#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"
// 0X3C+SA0 - 0x3C or 0x3D
#define I2C_ADDRESS 0x3C
// Define proper RST_PIN if required.
#define RST_PIN -1
SSD1306AsciiWire oled;
//------------------------------------------------------------------------------
void setup() {
Wire.begin();
Wire.setClock(400000L);
#if RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
#else // RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS);
#endif // RST_PIN >= 0
oled.setFont(Adafruit5x7);
uint32_t m = micros();
oled.clear();
oled.println("Hello world!");
oled.println("A long line may be truncated");
oled.println();
oled.set2X();
oled.println("2X demo");
oled.set1X();
oled.print("\nmicros: ");
oled.print(micros() - m);
}
//------------------------------------------------------------------------------
void loop() {}
/*
// Load Cell Code troubles
// https://forum.arduino.cc/t/load-cell-code-troubles/1413335
// Oled screen,sck and sda go to an analog pin
// push button in pin 6
#include "HX711.h"
#include <Arduino.h>
#include <Pushbutton.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"
#include <Wire.h>
int DT_Pin = 4;
int SCK_Pin = 5;
int Dy = 2000;
//CALIBRATION
HX711 scale;
int reading; // can use float if we need the decimals
int lastReading;
//OLED DISPLAY
#define SCREEN_WIDTH 128 // OLED dimensions are in pxls
#define SCREEN_HEIGHT 64
// SSD DECLARATION
#define OLED_RESET -1//RESET PIN
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//BUTTON
int BUTTON_PIN = 6;
Pushbutton button(BUTTON_PIN);
//DISPLAY WEIGHT
void displayWeight(float weight)//float
{
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
// Display static text
display.println("Weight: ");
//display.display();, can remove for refrsh rate.
display.setCursor(0, 30);
display.setTextSize(2);
display.print(weight, 1);// number add decimals, 1;
display.print(" ");
display.print("g");
display.display();
}
void setup() {
Serial.begin(115200);
Serial.println("Rocket Thrust...");
Serial.println("Initializing Scale");
// OLED
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 ALLOCATION FAILED"));
for (;;);
}
delay(Dy);
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
//calibration
scale.begin(SCK_Pin, DT_Pin);
Serial.println("Before setting up scale");
Serial.print("read:\t\t");
Serial.println(scale.read()); // the raw reading
Serial.print("read avg: \t");
Serial.println(scale.read_average(20)); //prints after 20 readings
Serial.print("Get value: \t\t");
Serial.println(scale.get_value(5));
Serial.print("Get units: \t\t");
Serial.println(scale.get_units(5), 1); //ADC minus tare weight (not set) divided by the SCALE parameter
scale.set_scale();// this value is obtained by calibrating the scale with known weights, RAW OUTPUT/KNOWN WIEGHT;
scale.tare(); // reset the scale to 0
Serial.println("After setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC
Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
Serial.print("get value: \t\t");
Serial.println(scale.get_value(5));// print the average of 5 readings from the ADC minus the tare weight, set with tare()
Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided
// by the SCALE parameter set with set_scale GETS OUR WIEGHT IN DESIRED UNTS
Serial.println("Readings:");
}
void loop() {
//tare calibration
if (scale.is_ready()) {
scale.set_scale();// weight calibration; the factor is reading/known weight;
Serial.println("Tare... remove any weights from scale");
delay(Dy);
scale.tare();
Serial.println("Tare Done.");
Serial.print("Place Rocket motor on scale pls...");
delay(Dy);
long reading = scale.get_units(10);// read in g,kg, or Lbs; 10 means it deos ten reading for better accuracy
Serial.print("Force");
Serial.println(reading);
} else {
Serial.println("HX711 NOT FOUND!");
}
delay(Dy);
Serial.print("one reading:\t");
Serial.print(scale.get_units(), 1);
Serial.print("\t avg:\t");
Serial.println(scale.get_units(10), 5);
delay(Dy);
if ( button.getSingleDebouncedPress()) {
Serial.print("Tare");
scale.tare();
}
if (scale.wait_ready_timeout(200)) {
reading = round(scale.get_units());
Serial.print("weight");
Serial.println(reading);
}
if (reading != lastReading) {
displayWeight(reading);
lastReading = reading;
}
}*/