OLED дисплей 0.96" I2C 128x64
- Войдите на сайт для отправки комментариев
Вс, 02/01/2022 - 17:37
Имеется OLED дисплей 0.96" I2C 128x64. Подключил его работает. Но не могу привязать его к работающему скетчу дисплей 1602. Это контроллер точечной сварки. Может кто нибудь поможет.
#include <LiquidCrystal.h>
int bta = 13; //Вывод к котрому подключен симистор
int svarka = 8; // Вывод клавиши сварки
int secplus = 9; // Вывод клавиши увеличении времени варки
int secminus = 10; // Вывод клавиши уменьшении времени варки
int razplus = 11; // Вывод клавиши увеличения количества проварок
int razminus = 12; // Вывод клавиши уменьшении количества проварок
int lastReportedPos = 1;
int lastReportedPos2 = 1;
volatile int sec = 40;
volatile int raz = 0;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup() {
pinMode(svarka, INPUT);
pinMode(secplus, INPUT);
pinMode(secminus, INPUT);
pinMode(razplus, INPUT);
pinMode(razminus, INPUT);
pinMode(bta, OUTPUT);
lcd.begin(12, 2); // Указываем какой установлен индикатор
lcd.setCursor(2, 0); // Устанавливаем курсор в начало 1 строки
lcd.print("Svarka v.1.0"); // Выводим текст
lcd.setCursor(2, 1); // Устанавливаем курсор в начало 2 строки
lcd.print("Tehnopage.ru"); // Выводим текст
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Delay: Ms");
lcd.setCursor(0, 1);
lcd.print("Repeat: times");
}
void fire() {
for (int i = 1; i <= raz; i++) {
digitalWrite(bta, HIGH);
delay (sec);
digitalWrite(bta, LOW);
delay (sec);
}
delay(1000);
}
void loop() {
if (sec <= 9 ) {
sec = 10;
lastReportedPos = 11;
}
if (sec >= 201 ) {
sec = 200;
lastReportedPos = 199;
}
else
{ if (lastReportedPos != sec) {
lcd.setCursor(7, 0);
lcd.print(" ");
lcd.setCursor(7, 0);
lcd.print(sec);
lastReportedPos = sec;
}
}
if (raz <= 0 ) {
raz = 1;
lastReportedPos2 = 2;
}
if (raz >= 11 ) {
raz = 10;
lastReportedPos2 = 9;
}
else
{ if (lastReportedPos2 != raz) {
lcd.setCursor(8, 1);
lcd.print(" ");
lcd.setCursor(8, 1);
lcd.print(raz);
lastReportedPos2 = raz;
}
}
if (digitalRead(secplus) == HIGH ) {
sec += 1;
delay(250);
}
if (digitalRead(secminus) == HIGH ) {
sec -= 1;
delay(250);
}
if (digitalRead(razplus) == HIGH ) {
raz += 1;
delay(250);
}
if (digitalRead(razminus) == HIGH ) {
raz -= 1;
delay(250);
}
if (digitalRead(svarka) == HIGH ) {
fire();
}
}
Воспользуйтесь библиотеками для SSD1306, например https://github.com/adafruit/Adafruit_SSD1306
В папке examples примеры использования, подключите #include <***.h> и замените свой объект lcd на oled из подключённой библиотеки и замените методы на используемые в библиотеке, экран подключается к А4, А5.
А где код с попытками «привязки»?
А где код с попытками «привязки»?
тут начало )))
#include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #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 4 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); int bta = 13; // Вывод к котрому подключен симистор int svarka = 8; // Вывод клавиши сварки int secplus = 9; // Вывод клавиши увеличении времени варки int secminus = 10; // Вывод клавиши уменьшении времени варки int razplus = 11; // Вывод клавиши увеличения количества проварок int razminus = 12; // Вывод клавиши уменьшении количества проварок int lastReportedPos = 1; int lastReportedPos2 = 1; volatile int sec = 40; volatile int raz = 0; void setup() { pinMode(svarka, INPUT); pinMode(secplus, INPUT); pinMode(secminus, INPUT); pinMode(razplus, INPUT); pinMode(razminus, INPUT); pinMode(bta, OUTPUT); // 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 // Clear the buffer display.clearDisplay(); display.setTextSize(2); // Normal 1:1 pixel scale display.setTextColor(SSD1306_WHITE); // Draw white text display.setCursor(0, 0); // Start at top-left corner display.println("Svarka v.1.0"); // Выводим текст display.println("Tehnopage.ru"); // Выводим текст display.display(); delay(3000); display.clearDisplay(); display.setCursor(0, 0); display.println("Delay: Ms"); display.println("Repeat: times"); display.display(); } void fire() { for (int i = 1; i <= raz; i++) { digitalWrite(bta, HIGH); delay (sec); digitalWrite(bta, LOW); delay (sec); } delay(1000); } void loop() { if (sec <= 9 ) { sec = 10; lastReportedPos = 11; } if (sec >= 201 ) { sec = 200; lastReportedPos = 199; } else { if (lastReportedPos != sec) { display.setCursor(7, 0); display.print(" "); display.setCursor(7, 0); display.print(sec); lastReportedPos = sec; } } if (raz <= 0 ) { raz = 1; lastReportedPos2 = 2; } if (raz >= 11 ) { raz = 10; lastReportedPos2 = 9; } else { if (lastReportedPos2 != raz) { display.setCursor(8, 1); display.print(" "); display.setCursor(8, 1); display.print(raz); lastReportedPos2 = raz; } } if (digitalRead(secplus) == HIGH ) { sec += 1; delay(250); } if (digitalRead(secminus) == HIGH ) { sec -= 1; delay(250); } if (digitalRead(razplus) == HIGH ) { raz += 1; delay(250); } if (digitalRead(razminus) == HIGH ) { raz -= 1; delay(250); } if (digitalRead(svarka) == HIGH ) { fire(); } }Вот на чем застрял.
#include <OLED_I2C.h> int bta = 13; //Вывод к котрому подключен симистор int svarka = 8; // Вывод клавиши сварки int secplus = 9; // Вывод клавиши увеличении времени варки int secminus = 10; // Вывод клавиши уменьшении времени варки int razplus = 11; // Вывод клавиши увеличения количества проварок int razminus = 12; // Вывод клавиши уменьшении количества проварок int lastReportedPos = 1; int lastReportedPos2 = 1; volatile int sec = 40; volatile int raz = 0; OLED display(SDA, SCL, 8); extern uint8_t RusFont[]; void setup() { pinMode(svarka, INPUT); pinMode(secplus, INPUT); pinMode(secminus, INPUT); pinMode(razplus, INPUT); pinMode(razminus, INPUT); pinMode(bta, OUTPUT); display.begin(); display.clrScr(); // очистить экран display.setFont(RusFont); display.print("Cdfhrf", CENTER, 0); // текст "Сварка" display.print("Pflth;rf VC", 0,20); // текст "Задержка" display.print("Gjdnjh Rjk", 0, 40); // текст "Повтор" display.update(); // обновить экран } void fire() { for (int i = 1; i <= raz; i++) { digitalWrite(bta, HIGH); delay (sec); digitalWrite(bta, LOW); delay (sec); } delay(1000); } void loop() { if (sec <= 9 ) { sec = 10; lastReportedPos = 11; } if (sec >= 201 ) { sec = 200; lastReportedPos = 199; } else { if (lastReportedPos != sec) { display.setCursor(7, 0); display.print(" "); display.setCursor(7, 0); display.print(sec); lastReportedPos = sec; } } if (raz <= 0 ) { raz = 1; lastReportedPos2 = 2; } if (raz >= 11 ) { raz = 10; lastReportedPos2 = 9; } else { if (lastReportedPos2 != raz) { display.setCursor(8, 1); display.print(" "); display.setCursor(8, 1); display.print(raz); lastReportedPos2 = raz; } } if (digitalRead(secplus) == HIGH ) { sec += 1; delay(250); } if (digitalRead(secminus) == HIGH ) { sec -= 1; delay(250); } if (digitalRead(razplus) == HIGH ) { raz += 1; delay(250); } if (digitalRead(razminus) == HIGH ) { raz -= 1; delay(250); } if (digitalRead(svarka) == HIGH ) { fire(); } }Ну выше же дали ссылку на библиотеку, как подключать, что подключать, ну посмотри примеры, например: https://github.com/adafruit/Adafruit_SSD1306/blob/master/examples/ssd1306_128x32_i2c/ssd1306_128x32_i2c.ino
display.setTextSize(1); // Normal 1:1 pixel scale display.setTextColor(SSD1306_WHITE); // Draw white text display.setCursor(0,0); // Start at top-left corner display.println(F("Hello, world!")); display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Draw 'inverse' text display.println(3.141592); display.setTextSize(2); // Draw 2X-scale text display.setTextColor(SSD1306_WHITE); display.print(F("0x")); display.println(0xDEADBEEF, HEX); display.display();ну и так далее, изучай....