Why are the values on the OLED screen sometimes exceeding the upper limit given in the random function?

There is also another problem occurring that I'm not sure how to adequately describe—the video in the (last) link shows both problems.

I am using an Arduino Uno WiFi Rev. 2, and the SSD1315 OLED display that came with the Arduino Sensor Kit.

This is the code I am using:

#include "Arduino_SensorKit.h"

void setup() {
  Oled.begin();
  Oled.setFlipMode(false);
}

void loop() {
  int random_value = random(0, 1023);   // create a random value

  Oled.setFont(u8x8_font_chroma48medium8_r); 
  Oled.setCursor(0, 3);
  Oled.print("Value: ");
  Oled.print(random_value);
  delay(1000);
}

Here is a video of what is happening: SSD1315 bug? - YouTube

Print 23.
Now print, without erasing, 1000.
(All left-justified, obviously)
See the problem?

I'm a beginner, so...maybe?

#include "Arduino_SensorKit.h"

void setup() 
{
  Oled.begin();
  Oled.setFlipMode(false);
  Oled.setFont(u8x8_font_chroma48medium8_r); 
}

void loop() 
{
  int random_value = 1000;

  Oled.setCursor(0, 3);
  Oled.print("Value: ");
  Oled.print(random_value);
  delay(1000);
  random_value = 23;
  Oled.setCursor(0, 3);
  Oled.print("Value: ");
  Oled.print(random_value);
  delay (5000);
}

(uncompiled, untested)

I don't really see that display being generated by the code you posted.
Or the code I posted.

Is this a new question?

No, this isn't a new question.

If the display (or its associated circuitry) was damaged by my removing it from the breakout board, would it likely result in this or similar behavior? Or is this glitch more likely to be originating from the Arduino itself? I haven't tried all of the sensors nor all the capabilities of the Arduino itself, but of the things I have tried, this is the only one that I am certain is malfunctioning.

I bought the Arduino and the sensor kit from the official site, in case you're wondering.

In the error pane at the bottom of the IDE window. the following was displayed after uploading:

WARNING: library Arduino_Sensorkit claims to run on avr architecture(s) and may be incompatible with your current board which runs on megaavr architecture(s).
Sketch uses 11243 bytes (23%) of program storage space. Maximum is 48640 bytes.
Global variables use 621 bytes (10%) of dynamic memory, leaving 5523 bytes for local variables. Maximum is 6144 bytes.
avrdude: WARNING: invalid value for unused bits in fuse "fuse5", should be set to 1 according to datasheet
This behaviour is deprecated and will result in an error in future version
You probably want to use 0xcd instead of 0xc9 (double check with your datasheet first).

Is this the expected behavior: "Value:" alternating between 1000 and 2300?

My WiFi router being next to my computer, I thought maybe its signal could be causing interference, so I took the Arduino (and display) to the other side of my room and powered it using an AC adapter, which resulted in the above behavior. However, after turning off the router and connecting the Arduino to the computer, the (previous) erroneous behavior resumed.

  Oled.setCursor(0, 3);
  Oled.print("Value: ");
  if (random_value < 1000)
    Oled.print(' ');
  if (random_value < 100)
    Oled.print(' ');
  if (random_value < 10)
    Oled.print(' ');
  Oled.print(random_value);
#include "Arduino_SensorKit.h"

void setup() 
{
  Oled.begin();
  Oled.setFlipMode(false);
  Oled.setFont(u8x8_font_chroma48medium8_r); 
}

void loop() 
{
  int random_value = 1000;
  Oled.setCursor(0, 3);
  Oled.print("Value: ");
  if (random_value < 1000)
    Oled.print(' ');
  if (random_value < 100)
    Oled.print(' ');
  if (random_value < 10)
    Oled.print(' ');
    Oled.print(random_value);
}

Powered by the AC adapter, it displays "Value: 1000".

Powered by my computer's USB port, results in more of the glitchy behavior.

[EDIT] More, possibly relevant info: the AC adapter is plugged into the DC power jack on the Arduino.

When you write to the OLED it only sets the characters you currently sent.... confusing so:

  1. you print 123456

123456

  1. you print abcde

abcde6 < the 6 is left over from the 123456

To fix this you could use the command that clears to the end of the line, right after you print your value.

In addition to my other two replys: Not sure what title to give this video right now - YouTube. (As I tend to be the opposite of verbose, I'll let the video speak for me and itself.)

In other words, it seems I may be wrong in assuming the problem lies with the display. Should I start a new post/thread linking back to this one?

No, but you did anyway.

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