How do I print data to a SSD1306 64x32 OLED without using the obdWriteString so I can post data.
Example:
Serial.print("Humid: "); Serial.println(bmx280.getHumidity());
is used to print to the serial monitor.
"Serial.print" is the command for the serial monitor what is it for the OLED??
What does the documentation for the SSD1306 Arduino library you are using say to do?
It doesn't say anything maybe someone can suggest a library to use.
There is this rather popular library, which has examples showing use of the .print() function.
Adafruit library.
It doesn’t look like the Adafruit library supports the display I’m using.
64x32
An internet search on some words like Arduino SSD1308 64x32.
Or you can try use the U8g2 library or some other library you find on the internet.
Good luck.
What is "it"? Where did you find "it"?
It’s a really micro small miniature display I found it on eBay ordered a couple of them they were really cheap and a lot of fun with what code is available I just can’t take data from another module and do like a Serial print to view it on the display there’s no such command all they have is a writestring that writes characters to the display only.
I use the Adafruit libraries
SSD1306Ascii.h
SSD1306AsciiAvrI2c.h
for the I2C version of that display. I believe the same libraries can be used for your serial version.
Ok I need a little help here I cant figure out why Im getting this error display' was not declared in this scope
im flying by the seat of my pants when it comes to code ive never coded one from scratch so ive been pasting code from another program altering it. and this is what I have so far. Im not to savvy on the structure of c++.
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <BMx280I2C.h>
#include <Adafruit_SSD1306.h>
#define SDA_PIN 20
#define SCL_PIN 21
#define SCREEN_WIDTH 64 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define I2C_ADDRESS 0x76
#define OLED_RESET
#define SCREEN_ADDRESS 0x3C for Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//create a BMx280I2C object using the I2C interface with I2C Address 0x76
BMx280I2C bmx280(I2C_ADDRESS);
void setup() {
// put your setup code here, to run once:
display.begin(115200);
display.display();
//wait for display connection to open (only necessary on some boards)
while (!display);
//Wire.begin();
//begin() checks the Interface, reads the sensor ID (to differentiate between BMP280 and BME280)
//and reads compensation parameters.
bmx280.begin();
//reset sensor to default parameters.
bmx280.resetToDefaults();
//by default sensing is disabled and must be enabled by setting a non-zero
//oversampling setting.
//set an oversampling setting for pressure and temperature measurements.
bmx280.writeOversamplingPressure(BMx280MI::OSRS_P_x16);
bmx280.writeOversamplingTemperature(BMx280MI::OSRS_T_x16);
//if sensor is a BME280, set an oversampling setting for humidity measurements.
if (bmx280.isBME280())
bmx280.writeOversamplingHumidity(BMx280MI::OSRS_H_x16);
}
void loop() {
// put your main code here, to run repeatedly:
delay(500);
// Clear display buffer
display.clearDisplay();
//start a measurement
if (!bmx280.measure())
//wait for the measurement to finish
delay(10000);
}
while (!bmx280.hasValue());
display.print("Press: "); display.println(bmx280.getPressure());
display.print("Temp: "); display.println(bmx280.getTemperature());
if (bmx280.isBME280())
{
display.print("Humid: "); display.println(bmx280.getHumidity());
display.print("\r\n");
display.print("Current Weather\r\n");
}
}
Get rid of the junk after 0x3C above, and declare an instance of display
Thanks J, I have it compiling but no output to the display. I have it hooked up correct as it functions with two separate programs. Do I need two separate i2c connections? (I thought it worked by addressing,) anyway here is the code without errors but must be missing something. More help and suggestions please.
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <BMx280I2C.h>
#include <Adafruit_SSD1306.h>
#define SDA_PIN 20
#define SCL_PIN 21
#define SCREEN_WIDTH 64 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define SCREEN_ADDRESS 0x3C
#define OLED_RESET 2
Adafruit_SSD1306 display(64, 32, &Wire, OLED_RESET);
#define I2C_ADDRESS 0x76
//create a BMx280I2C object using the I2C interface with I2C Address 0x76
BMx280I2C bmx280(I2C_ADDRESS);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
Wire.begin();
//begin() checks the Interface, reads the sensor ID (to differentiate between BMP280 and BME280)
//and reads compensation parameters.
if (!bmx280.begin());
//reset sensor to default parameters.
bmx280.resetToDefaults();
//by default sensing is disabled and must be enabled by setting a non-zero
//oversampling setting.
//set an oversampling setting for pressure and temperature measurements.
bmx280.writeOversamplingPressure(BMx280MI::OSRS_P_x16);
bmx280.writeOversamplingTemperature(BMx280MI::OSRS_T_x16);
//if sensor is a BME280, set an oversampling setting for humidity measurements.
if (bmx280.isBME280())
bmx280.writeOversamplingHumidity(BMx280MI::OSRS_H_x16);
}
}
void loop() {
// put your main code here, to run repeatedly:
// Clear display buffer
display.clearDisplay();
display.print("Current Weather");
//start a measurement
if (!bmx280.measure())
//wait for the measurement to finish
do
delay(10000);
while (!bmx280.hasValue());
display.print("Press: "); display.println(bmx280.getPressure());
display.print("Temp: "); display.println(bmx280.getTemperature());
if (bmx280.isBME280())
{
display.print("Humid: "); display.println(bmx280.getHumidity());
display.print("\r\n");
display.print("Current Weather\r\n");
}
}
Have you run the I2C scanner to test connections, and to see the actual I2C address of the display? Are there pullups on the I2C connections?
There is this comment in the library I2C example, which may not apply to your display.
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Please explain in some detail what this comment means, and post the code that works.
I have it hooked up correct as it functions with two separate programs.
Yes the i2c scan works and found both devices. the new code is:
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <BMx280I2C.h>
#include <Adafruit_SSD1306.h>
#define SDA_PIN 20
#define SCL_PIN 21
#define SCREEN_WIDTH 64 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define SCREEN_ADDRESS 0x3C
#define OLED_RESET 2
Adafruit_SSD1306 display(64, 32, &Wire, OLED_RESET);
#define I2C_ADDRESS 0x3C
//create a BMx280I2C object using the I2C interface with I2C Address 0x3C
BMx280I2C bmx280(I2C_ADDRESS);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
Wire.begin();
//begin() checks the Interface, reads the sensor ID (to differentiate between BMP280 and BME280)
//and reads compensation parameters.
if (!bmx280.begin());
//reset sensor to default parameters.
bmx280.resetToDefaults();
//by default sensing is disabled and must be enabled by setting a non-zero
//oversampling setting.
//set an oversampling setting for pressure and temperature measurements.
bmx280.writeOversamplingPressure(BMx280MI::OSRS_P_x16);
bmx280.writeOversamplingTemperature(BMx280MI::OSRS_T_x16);
//if sensor is a BME280, set an oversampling setting for humidity measurements.
if (bmx280.isBME280())
bmx280.writeOversamplingHumidity(BMx280MI::OSRS_H_x16);
}
}
void loop() {
// put your main code here, to run repeatedly:
// Clear display buffer
display.clearDisplay();
display.print("Current Weather");
//start a measurement
if (!bmx280.measure())
//wait for the measurement to finish
do
delay(10000);
while (!bmx280.hasValue());
display.print("Press: "); display.println(bmx280.getPressure());
display.print("Temp: "); display.println(bmx280.getTemperature());
if (bmx280.isBME280())
{
display.print("Humid: "); display.println(bmx280.getHumidity());
display.print("\r\n");
display.print("Current Weather\r\n");
}
}
You misplaced a closing bracket } in setup:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
Wire.begin();
//begin() checks the Interface, reads the sensor ID (to differentiate between BMP280 and BME280)
//and reads compensation parameters.
In the sample Adafruit code:
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
Yes, that is a mistake. Also, this should not be in setup() as it is already done by the display routines.
Wire.begin();
Study the example code carefully!
Im getting closer made a few more tweeks and did your suggestions and got some gibberish on the display. photo coming.
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <BMx280I2C.h>
#include <Adafruit_SSD1306.h>
#define SDA_PIN 20
#define SCL_PIN 21
#define SCREEN_WIDTH 64 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define SCREEN_ADDRESS 0x3C
#define OLED_RESET 2
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define I2C_ADDRESS 0x3C
//create a BMx280I2C object using the I2C interface with I2C Address 0x3C
BMx280I2C bmx280(I2C_ADDRESS);
void setup() {
// put your setup code here, to run once:
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
//begin() checks the Interface, reads the sensor ID (to differentiate between BMP280 and BME280)
//and reads compensation parameters.
if (!bmx280.begin());
//reset sensor to default parameters.
bmx280.resetToDefaults();
//by default sensing is disabled and must be enabled by setting a non-zero
//oversampling setting.
//set an oversampling setting for pressure and temperature measurements.
bmx280.writeOversamplingPressure(BMx280MI::OSRS_P_x16);
bmx280.writeOversamplingTemperature(BMx280MI::OSRS_T_x16);
//if sensor is a BME280, set an oversampling setting for humidity measurements.
if (!bmx280.isBME280())
bmx280.writeOversamplingHumidity(BMx280MI::OSRS_H_x16);
}
void loop() {
// put your main code here, to run repeatedly:
// Clear display buffer
display.clearDisplay();
display.print("Current Weather");
//start a measurement
if (!bmx280.measure())
//wait for the measurement to finish
do
delay(5000);
while (!bmx280.hasValue());
display.print("Press: "); display.println(bmx280.getPressure());
display.print("Temp: "); display.println(bmx280.getTemperature());
if (!bmx280.isBME280())
{
Why is this line still in setup()?
Wire.begin();
You should not expect the default splash screen to work for your display.