Hello all, ive recently tried to start a project for a car that im building to make a digital boost gauge with an arduino uno and a .96 oled screen. Using i2c address locating code, i could not find them at all. I figured out that they work on the ug8 library rather than ssd1306. I have code compiled that i found somewhere else, that i planned to just use for now and then modify it to fit my needs a little better. Im very new to programming other than a few classes in school 20+ years ago and lots of html experience around the same time frame. My questions are, is there an easy way to convert this code to work with the ug8 library, or does someone have a link for actual ssd1306 oled screens? I got the ones that i have right now on ebay, but again they were labeled as ssd1306, and i have spent a few weeks trying to get them to work, only to finally get them to power up and work with an example from the ug8lib. heres the code im trying to run. Its a boost gauge with dual ls3 map sensors, one for atmospheric pressure, one for boost.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define sensorPin A0
#define refPin A2
#define WINDOW_SIZE 6
#define LOGO_HEIGHT 64
#define LOGO_WIDTH 128
// 'vw128x64', 128x64px
const unsigned char VWround [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x80, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x80, 0x00, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x1f, 0xc0, 0x03, 0xfc, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xe0, 0x03, 0xf8, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x07, 0xf0, 0x07, 0xf0, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x07, 0xf8, 0x0f, 0xe0, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0xe0, 0x03, 0xfc, 0x1f, 0xc0, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0x01, 0xfc, 0x3f, 0x80, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xf0, 0x00, 0xfe, 0x7f, 0x00, 0x0f, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x00, 0x7f, 0xff, 0x00, 0x0f, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7d, 0xfc, 0x00, 0x3f, 0xfe, 0x00, 0x1f, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0xfc, 0x00, 0x1f, 0xfc, 0x00, 0x3f, 0x9f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x7e, 0x00, 0x1f, 0xf8, 0x00, 0x7f, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0x80, 0x0f, 0xf8, 0x01, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x1f, 0xc0, 0x1f, 0xfc, 0x01, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x0f, 0xe0, 0x3f, 0xfc, 0x03, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7e, 0x07, 0xf0, 0x7f, 0xfe, 0x07, 0xf0, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3e, 0x03, 0xf0, 0xff, 0x7f, 0x0f, 0xe0, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x03, 0xf8, 0xfe, 0x3f, 0x9f, 0xc0, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0xff, 0xfc, 0x1f, 0xff, 0x80, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x7f, 0xf8, 0x0f, 0xff, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x7f, 0xf0, 0x07, 0xfe, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x3f, 0xe0, 0x03, 0xfc, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x0f, 0xc0, 0x03, 0xf8, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xef, 0x80, 0x01, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x80, 0x00, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
//---------------
int OLED_RESET = 4;
Adafruit_SSD1306 display(OLED_RESET); //driver for the screen
// bar graph
float rawval = 0; // Setup raw sensor value
float refval = 0; // Setup raw refernce sensor value
float barboost = 0; // Setup value for boost bar
float realboost = 0; // Setup value for real boost
int INDEX = 0;
int VALUE = 0;
int SUM = 0;
int READINGS[WINDOW_SIZE];
int AVERAGED = 0;
byte count;
byte sensorArray[128];
byte drawHeight;
boolean filled = 0; //decide either filled, or dot-display. 0==dot display.
void VWlogo() {
display.clearDisplay();
display.drawBitmap(0, 0, VWround, LOGO_WIDTH, LOGO_HEIGHT, 1);
display.display();
delay(1500);
}
void setup()
{
delay(250);
Serial.begin(9600); // start monitoring raw voltage for calibration
display.begin(SSD1306_SWITCHCAPVCC); // 3.3V power supply
display.clearDisplay(); // Clear the display and ram
display.display();
VWlogo();
delay(2000); // display Adafruit logo for 2 seconds
for (count = 0; count <= 128; count++) //zero all elements
{
sensorArray[count] = 0;
}
}
void loop() // Start loop
{
analogRead(sensorPin);
int boost1 = map(analogRead(sensorPin), 21, 961, 100, 2600);
analogRead(refPin);
int boost2 = map(analogRead(refPin), 21, 961, 100, 2600);
int boostmbar = boost1 - boost2;
rawval = (analogRead(A0) - analogRead (A2)); // Read MAP sensor raw value on analog port 0
SUM = SUM - READINGS[INDEX]; // Remove the oldest entry from the sum
VALUE = boostmbar * 1.215; // Read the next sensor value
READINGS[INDEX] = VALUE; // Add the newest reading to the window
SUM = SUM + VALUE; // Add the newest reading to the sum
INDEX = (INDEX + 1) % WINDOW_SIZE; // Increment the index, and wrap to 0 if it exceeds the window size
AVERAGED = SUM / WINDOW_SIZE; // Divide the sum of the window by the window size for the result
barboost = ((rawval * 0.19) + 10); // Calculate boost value for the graph
drawHeight = map((analogRead(A0) - analogRead(A2)), 0, 1023, 0, 25 );
sensorArray[0] = drawHeight;
for (count = 55; count <= 128; count++ )
{
if (filled == false)
{
display.drawPixel(count, 71 - sensorArray[count - 55], WHITE);
}
else
display.drawLine(count, 1, count, 71 - sensorArray[count - 55], WHITE);
}
for (count = 80; count >= 2; count--) // count down from 160 to 2
{
sensorArray[count - 1] = sensorArray[count - 2];
}
display.fillRect(0, 0, barboost, 4, WHITE); // Draws the bar depending on the sensor value
display.setTextSize(1);
display.setCursor(97, 20);
display.println("BOOST");
display.setTextColor(WHITE);
display.setTextSize(3);
display.setCursor(0, 10);
display.println(((AVERAGED * 0.001) * 14) + 0.12);
delay(1);
display.display();
display.clearDisplay();
delay(10); // delay between numbers
}