Hi, I'm trying to display "Hello World" on Ole 128x32,SSD1306 display on Arduino Nano, but it does not work.
The Ole is I2C. Pressing the button on the HC-12, send, lights up on the HC-12 receive, and it works. Now I have loaded this sketch and it continues to work but the Ole does not display the message "Hello World". How to?
Thank you
Chip
SEND
//HC-12 Toggle button Send
//Autor Tom Heylen tomtomheylen.com
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //RX, TX
int buttonPin = 8;
void setup() {
pinMode(buttonPin, INPUT);
mySerial.begin(9600);
}
void loop() {
int buttonState = digitalRead(buttonPin);
if(buttonState == 1){//if button is down
mySerial.println(1234);//send unique code to the receiver in this case 1234
}
delay(20);//delay little for better serial communication
}
RECEIVE
//HC-12 Toggle button Receive
//Autor Tom Heylen tomtomheylen.com
#include <SoftwareSerial.h>
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
//A5 -> SCL
//A4 -> SDA
//GND
//3.3V
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
SoftwareSerial mySerial(2, 3); // RX, TX
int ledPin = 13;
unsigned long last = millis();//set timer
void setup() {
mySerial.begin(9600);
pinMode(ledPin, OUTPUT);
u8g2.begin();
u8g2.setColorIndex(1);
}
void loop() {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_logisoso32_tr);
u8g2.drawStr(0,32,"Hello!");
u8g2.sendBuffer();
boolean ledState = digitalRead(ledPin);//check if the LED is turned on or off. Returns 1 or 0
if(mySerial.available() > 1){
int input = mySerial.parseInt();//read serial input and convert to integer (-32,768 to 32,767)
if(millis() - last > 250){//if time now is 250 milliseconds greater than last time
if(ledState == 0 && input == 1234){//if LED is off and button code is ok
digitalWrite(ledPin, HIGH);
}else if(ledState == 1 && input == 1234){//if LED is on and button code is ok
digitalWrite(ledPin, LOW);
}
}
mySerial.flush();//clear the serial buffer for unwanted inputs
last = millis();//reset timer
}
delay(20);//delay little for better serial communication
}