After connecting the display, the values are not updated

Hello,
I am a new arduino user and i have one problem.
I have two Arduino UNO boards. One board receives the signal (speed) from the GPS NEO-6M and sends it through the RF module to the other Arduino UNO board, which displays it on the display.

The speed is sent from one board to another every second (it can also be seen in the Serial monitor of the receiving board). But if I implement the function to display the speed on the display in the code, only one value is displayed both on the display and in the serial monitor without the possibility of updating.

Can you advise me how to get the speed value to be updated every second even when the display function is implemented.

Thank you

void zobrazRychlost(float speed) {
  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("GPS Rychlost:");
  display.setTextSize(3);
  display.setCursor(0, 20);
  display.print(speed);
  display.setTextSize(2);
  display.print(" km/h");
  display.display(); // Asynchronně aktualizuje displej
}

Welcome to the forum

Please post the full Tx and Rx sketches and diagram showing how each Arduino is connected to its peripherals

...and make a better description of what happens, instead of "only one value is displayed both on the display and in the serial monitor without the possibility of updating". :wink:

OK, if I add a function to my code to show the speed on the display, I only get one value in the serail monitor, see the picture.

void zobrazRychlost(float speed) {
  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("GPS Rychlost:");
  display.setTextSize(3);
  display.setCursor(0, 20);
  display.print(speed);
  display.setTextSize(2);
  display.print(" km/h");
  display.display(); // Asynchronně aktualizuje displej
}

But if I delete this function, I get regularly updated speed data in the serial monitor.

Please show WHOLE YOUR CODE rather than one function.

We can't say anything unless you post the entire code, as @UKHeliBob already asked you, and like the forum guidelines require. This is an extract from "How to get the best out of this forum":

Posting a snippet of code is generally useless. The problem is usually in another part of the program.
...
It is very important to be clear about what is expected from code and what happens instead. Code ALWAYS works; that is the nature of code. Whether it does what you expect is a different thing altogether. We need to know what you expected the code to do and what happened instead.

TX

#include <SoftwareSerial.h>
#include <TinyGPS++.h>

#define RX_PIN 2
#define TX_PIN 3

SoftwareSerial gpsSerial(RX_PIN, TX_PIN);
TinyGPSPlus gps;

#include <VirtualWire.h>

#define RF_TX_PIN 12

void setup() {
  Serial.begin(9600);
  gpsSerial.begin(9600);
  
  vw_set_tx_pin(RF_TX_PIN);
  vw_setup(2000);
}

void loop() {
  while (gpsSerial.available() > 0) {
    if (gps.encode(gpsSerial.read())) {
      if (gps.speed.isValid()) {
        float speedKmph = gps.speed.kmph();
        Serial.print("Rychlost: ");
        Serial.println(speedKmph);
        
        // Odešli rychlost přes RF modul
        odeslatPresRF(speedKmph);
      }
    }
  }
}

void odeslatPresRF(float speed) {
  char speedStr[8];
  dtostrf(speed, 6, 2, speedStr);
  
  vw_send((uint8_t *)speedStr, strlen(speedStr));
  vw_wait_tx();
}

RX

#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define RX_PIN 2
#define TX_PIN 3

SoftwareSerial rfSerial(RX_PIN, TX_PIN);

#include <VirtualWire.h>

#define RF_RX_PIN 12

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET 4
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

////On an arduino UNO: A4(SDA), A5(SCL)
//#define OLED_RESET -1 //Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C //See datasheet for Address
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  Serial.begin(9600);
  rfSerial.begin(9600);
  
  vw_set_rx_pin(RF_RX_PIN);
  vw_setup(2000);
  vw_rx_start();

    // 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
      }
  display.clearDisplay();
  display.display();
  delay(2000);
}

void loop() {
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  
  if (vw_get_message(buf, &buflen)) {
    String speedStr = "";
    for (int i = 0; i < buflen; i++) {
      speedStr += (char)buf[i];
    }
    
    // Zpracuj přijatou rychlost
    float speed = speedStr.toFloat();
    Serial.print("Přijatá rychlost: ");
    Serial.println(speed);
    
// Zobraz rychlost na OLED displeji
 zobrazRychlost(speed);
 }
}

void zobrazRychlost(float speed) {
  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("GPS Rychlost:");
  display.setTextSize(3);
  display.setCursor(0, 20);
  display.print(speed);
  display.setTextSize(2);
  display.print(" km/h");
  display.display(); // Asynchronně aktualizuje displej
}

(I suppose with "delete" you mean "comment out the function call")
The code seems to do nothing special with that function, so it could be something to do with the display and/or its library. Have you double checked your library if it's the right and the latest one (e.g. running any other simple sketch to display things at 1 sec interval or less)?

In the meanwhile, as I hate "String" variables, please note you have "atof" function to convert a char array into a float without using "String". Try this:

...
  if (vw_get_message(buf, &buflen)) {
    // Zpracuj přijatou rychlost
    float speed = atof(buf);
    Serial.print("Přijatá rychlost: ");
    Serial.println(speed);
    
    // Zobraz rychlost na OLED displeji
    zobrazRychlost(speed);
  }
...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.