Испытание OLED дисплея Adafruit SSD1306

Обсуждение и вопросы по урокам Ардуино
dok
Сообщения: 5
Зарегистрирован: 11 дек 2017, 21:46

Испытание OLED дисплея Adafruit SSD1306

Сообщение dok » 05 янв 2018, 17:30

Как говорится: от новичка ардуинщика -- другим новичкам. Вдруг кому пригодится. В очередной посылке с "Али экспресс" пришёл малюсенький дисплей SSD1306. На основе уроков сенсея Эдуарда и примеров из библиотеки часов реального времени DS1307 и самого дисплея Adafruit SSD1306. .https://ru.aliexpress.com/item/1pcs-0-96-blue-0-96-inch-OLED-module-New-128X64-OLED-LCD-LED-Display-Module/32643950109.html?spm=a2g0s.9042311.0.0.OlL8Rf
вышел интересный скетч:

Код: Выделить всё

/*********************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/category/63_98

This example is for a 128x32 size display using I2C to communicate
3 pins are required to interface (2 I2C and one reset)

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada  for Adafruit Industries. 
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/
#include <OneWire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
#define POWER_MODE  0 // режим питания, 0 - внешнее, 1 - паразитное
OneWire sensDs (A0);  // датчик подключен к выводу 14, для 2560 надо писать А0
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16
byte bufData[9];  // буфер данных
float temperature;  // измеренная температура

static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11111111, B11100000,
  B11111100, B11111000,
  B01111100, B11111111,
  B00110001, B10001111,
  B00011111, B11111100,
  B00001100, B01110000,
  B00011001, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup()   {
  Wire.begin();
  Serial.begin(9600);
  while (!Serial) ; // wait for serial
  delay(200);
  Serial.println("DS1307RTC Test");
  Serial.println("--------------");             
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  // init done
   // text display tests
  display.setTextSize(1);
  display.setTextColor(WHITE);  // белый текст на чёрном фоне
  display.setCursor(0,0);
  display.println(" Kak dela? ");
  display.setTextColor(BLACK, WHITE); // 'inverted' text (чёрный текст на белом фоне)
  display.println(" Privet ");
  display.setTextSize(2);
  display.setTextColor(BLACK,WHITE); //чёрный текст на белом фоне
  display.display();
  delay(3000);

  // miniature bitmap display
  display.clearDisplay();
  display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
  display.display();
  delay(1000);

  // invert the display
  display.invertDisplay(true);
  delay(1000);
  display.invertDisplay(false);
  delay(1000);
 }
void loop() {
  sensDs.reset();  // сброс шины
  sensDs.write(0xCC, POWER_MODE); // пропуск ROM
  sensDs.write(0x44, POWER_MODE); // инициализация измерения
  delay(900);  // пауза 0,9 сек
  sensDs.reset();  // сброс шины
  sensDs.write(0xCC, POWER_MODE); // пропуск ROM 
  sensDs.write(0xBE, POWER_MODE); // команда чтения памяти датчика 
  sensDs.read_bytes(bufData, 9);  // чтение памяти датчика, 9 байтов

  if ( OneWire::crc8(bufData, 8) == bufData[8] ) {  // проверка CRC
    // данные правильные
    temperature=  (float)((int)bufData[0] | (((int)bufData[1]) << 8)) * 0.0625 + 0.03125;
 
  tmElements_t tm;
  if (RTC.read(tm)) {
    Serial.print(" Time = ");
    Serial.print(tm.Hour);
    Serial.write(':');
    Serial.print(tm.Minute);
    Serial.write(':');
    Serial.print(tm.Second);
    Serial.print(", Date (D/M/Y) = ");
    Serial.print(tm.Day);
    Serial.write('/');
    Serial.print(tm.Month);
    Serial.write('/');
    Serial.print(tmYearToCalendar(tm.Year));
    Serial.println();
    Serial.print(" temp   ");
    Serial.println(temperature);

  display.setTextSize(2);  // размер текста
  display.setTextColor(WHITE);  // белый текст на чёрном фоне
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);  // белый текст на чёрном фоне
  display.setCursor(20,0);
  display.print(tm.Hour);
  display.print(":");
  display.print(tm.Minute);
  display.print(":");
  display.print ( tm.Second);
  display.setTextSize(1);  // размер текста
  display.setCursor(1,20);
  display.print (tm.Day);
  display.print ('/');
  display.print(tm.Month);
  display.print ('/');
  display.print(tmYearToCalendar(tm.Year));
  display.print (" Tem ");
  display.print(temperature);
  display.println (" C");
  display.display();
  }
  }
  }

К сожалению не получается загрузить фото. На фото лучше видно подробности. Вот видео:
https://youtu.be/uWLUQf_xY00
Для чего такая мелкая вещь нужна? Не знаю. Для меня, это испытательный полигон для проверки на точность хода кварцевых резонаторов на DS1307. Вывел два проводка. Припаял фирменный кварц от какой то крутой техники. Гоняю, испытываю. В мониторе порта вся работа устройства продублирована. Опять же, выведена панелька для проверки двух датчиков DS18B20. Может кто ещё и по другому использует. Может какие недочёты найдёт. Рад буду поучиться уму разуму.


Вернуться в «Уроки Ардуино»

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и 5 гостей