/*================================================================= # Project : I2C OLED (SSD1306) # : # Date : 2021-04-09 # Version : 1.3 # # Note: # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY : without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE # # Board : Raspberry Pi Pico # IDE : Arduino IDE # Library : # Adafruit_SSD1306 : https://github.com/adafruit/Adafruit_SSD1306 # Adafruit_GFX : https://github.com/adafruit/Adafruit-GFX-Library #=================================================================*/ #include #include #include #include #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) // The pins for I2C are defined by the Wire-library. // On an arduino UNO: A4(SDA), A5(SCL) // On an arduino MEGA 2560: 20(SDA), 21(SCL) // On an arduino LEONARDO: 2(SDA), 3(SCL), ... #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3c // i2c slave address Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); //======================================================================= void setup() { Serial.begin(115200); // Wire.setSDA(16); // Wire.setSCL(17); Wire.begin(); Wire.setClock(400000); //400kHz delay(10000); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!oled.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. oled.display(); delay(2000); // Pause for 2 seconds } //======================================================================= void test(void) { // float v = 0.0; float v = analogRead(A0); Serial.print("Value: "); Serial.println(v); //String myStr; //myStr = String(v); // delay(500); oled.clearDisplay(); oled.setTextSize(1); // Normal 1:1 pixel scale oled.setTextColor(SSD1306_WHITE); // Draw white text oled.cp437(true); // Use full 256 char 'Code Page 437' font oled.setFont(&FreeSans12pt7b); oled.drawRect(0, 0, SCREEN_WIDTH-1,SCREEN_HEIGHT-1 , SSD1306_WHITE); oled.setCursor(10, 25); oled.write("Value:"); oled.setCursor(10, 50); oled.print(String(v)); oled.display(); // delay(2000); } //======================================================================= void loop() { // Sensorwerte: // int Value = analogRead(26); // Serial.print("Value: "); // Serial.println(Value); // delay(500); test(); // delay(3000); oled.clearDisplay(); oled.display(); // delay(3000); }