Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

My display doesn't behave like I expect

3 posters

Go down  Message [Page 1 of 1]

1My display doesn't behave like I expect Empty My display doesn't behave like I expect Wed May 17, 2023 9:08 pm

Popopo

Popopo

Hello everyone!

I am testing some basic display code in the simulator, but I don't get the expected behavior. Could somebody help me to understand what is happening?

It doesn't show some texts, pixel or line depending on what I comment into the code.

I have noticed that instead run the test method, it jump into Loop method.

Here is a video with the behavior: https://youtu.be/LmFDx2qz6po

Thank you very much.

arcachofo

arcachofo

Without the source code of your sketch it is difficult to say.
Can you share it?

Popopo

Popopo

arcachofo wrote:Without the source code of your sketch it is difficult to say.
Can you share it?

Oh sorry!
Sure, here we go with some small changes that I am doing to find out what is wrong (but same behavior):

Code:
/*
Programa de pruebas para las comunicaciones de un Arduino Nano
con el programa de Tester de memorias.
*/
//Importar librerías necesarias
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

//Definición de variables y abreviaturas.
#define SCR_W 128           //Ancho de la pantalla.
#define SCR_H 32            //Alto de la pantalla.
#define SCR_A 0x3C          //Dirección de memoria para comunicar con la pantalla
                                //De modo general: 0x3D para oLED 128x64, 0x3C para 128x32
#define SCR_RST -1          //Indica que usa el mismo pin reset que el Nano.

//Impresión de mensajes por puerto serie.
#define DEBUG(a) Serial.println(a);  //Define función DEBUG para apreviar el print.
boolean activo = false;              //Valor inicial del led (de usarse).

//Inicializa los parámetros de la pantalla en el Nano.
Adafruit_SSD1306 display(SCR_W, SCR_H, &Wire, SCR_RST);


void setup() {
  // initialize serial:
  Serial.begin(9600);
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, activo);
  
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, SCR_A)){
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }

  //Pruebas de diferentes dibujos y textos en pantalla.
  testdrawstyles();
}

void loop() {
  while (Serial.available() > 0) {
    //Leer caracter
    char data = Serial.read();
    //Cambiar estado del LED que corresponda
    if (data == 'A') {changeStateLED();}
    DEBUG((char)data);
  }
}

//Función espera teclado
int readKey(){
    int k = -1;
    return k;
}

//Función mostrar menú
int showMenu(){


}

//Función de prueba
void testdrawstyles(void){
  // 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();

  // Dibuja un pinxel a mitad ded pantalla.
  display.drawPixel(SCR_W/2, SCR_H/2, WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);

  //Prueba de línea
  display.clearDisplay();
  display.drawLine(0,0, display.width()-1, display.height()-1, WHITE);
  display.display();
  delay(2000);
  display.clearDisplay();
  display.setTextSize(1);             // Normal 1:1 pixel scale
  display.setTextColor(WHITE);        // Draw white text
  display.setCursor(0, 0);            // Start at top-left corner
  display.println(F("Hello, world!"));

  display.setTextSize(2);             // Draw 2X-scale text
  display.print(F("0x")); display.println(0xDEADBEEF, HEX);

  display.display();
  delay(2000);
}



void changeStateLED() {
    DEBUG("Cambio de estado del LED: ");
    DEBUG((boolean)activo);
    activo = !activo;
    digitalWrite(LED_BUILTIN, activo);  
    delay(1000);
}

Note: after testing some options, I see what is happening (at least). It is skipping lines. The point is not shown because the line is draw over it, but... why the line is drawn without the pause of 2 secs before? and the other lines?... no idea.
I tried the debugger but I don't master it yet. Seems anyway skipping lines.

Note2: Checked out the same code in a real hardware and it is shown correctly. So I guess it is related to a setup in the SimulIDE (that I avoided) or perhaps a bug. No idea.

arcachofo likes this post

Defran

Defran

Try to do this with Height to 64 in properties of SSD1306:

#define SCR_H 64

I think it improbes a lot...

Popopo

Popopo

Defran wrote:Try to do this with Height to 64 in properties of SSD1306:

#define SCR_H 64

I think it improves a lot...

In one hand it improves how it draws (not skipping lines), and that is good, but.. int the other hand, the image is shown in wrong way.

Moreover, it forces me to use a screen with 64px height, that is not what I need.

Defran

Defran

My display doesn't behave like I expect Test_s10
Attachments
My display doesn't behave like I expect AttachmentTEST_SSD1306_128x32.zip
You don't have permission to download attachments.
(18 Kb) Downloaded 3 times

arcachofo and Popopo like this post

Popopo

Popopo

Defran wrote:My display doesn't behave like I expect Test_s10

Thank you for your test.
It works properly with this design...
I am gonna try to use a Nano in your schema  and try it.
...
and that's work fine also with Nano...
so why doesn't work properly with my schema?
What I am doing wrong?

I have tried it out with 2 different circuits and the same result. Only now with yours it is working.

Edit: no no... something come wrong... firstly it is crashing the whole time when I remove the IC you placed... let me do some more tests...

Here is the video showing how it crash
: https://youtu.be/PCM06L2ujI0

So it is working with an empty schema, but what is wrong with my 2 schemas?

Edit2:

I see your code, you call the function display() before and after giving the new instruction to draw at.
Code:
 display.clearDisplay();
  display.display();
  display.drawLine(0,0, display.width()-1, display.height()-1, WHITE); // Line
  display.display();
  delay(2000);

So...
1. clear buffer,
2. display whatever is in (after clear, is there anything yet?
3. give drawing instructions
4. display again.

Then, why my code works in real hardware fine and not here?
Is it "just" lucky that real hardw hand it somehow?

Thank you

arcachofo

arcachofo

First, note that this is the development version, I'm continuously implementing new things, so it can be quite unstable.

About SSD1306, I think there is a problem in the implementation.
SSD1306 in Simulide is expecting the software to configure the page start and end addresses to 128x32, but  Adafruit library is not doing it, it keeps end Y at 64, so the display is printing below row 32 which is not visible.

The sketch done by Defran solves this issue by clearing the display before any operation but I think that Popopo's sketch should work in the real device, so I will change the implementation to work this way.

firstly it is crashing the whole time when I remove the IC you placed...
I can't reproduce this issue.
It could be related to the debugger, I will have a look.

Popopo likes this post

Popopo

Popopo

Thanks both!
Smile

If I can do anything to trace the issue just tell me.

Till it will be solved, I will code using the process showed by @Defran in some function to save some memory

arcachofo

arcachofo

If I can do anything to trace the issue just tell me.
Next time it happens try to remember if the debugger was running or any other thing you did just before.

I could make it crash with this sequence, it is probably the same problem but not 100% sure:
- Start the debugger.
- Delete the Nano
- Close the sketch in the Editor while the debugger is running.

Till it will be solved, I will code using the process showed by @Defran in some function to save some memory
Ok, but in any case I was about to upload new executables.
Hopefully I will fix these issues and upload later today.

Popopo

Popopo

arcachofo wrote:
Next time it happens try to remember if the debugger was running or any other thing you did just before.
No, debugger was not running at all. What you see in the video is exactly how I reproduce the issue. No debugging.


arcachofo wrote:
Ok, but in any case I was about to upload new executables.
Hopefully I will fix these issues and upload later today.
Sounds great! Smile thank you

arcachofo

arcachofo

No, debugger was not running at all. What you see in the video is exactly how I reproduce the issue. No debugging.
Sorry I missed that video. Thanks.

Popopo likes this post

Popopo

Popopo

arcachofo wrote:
No, debugger was not running at all. What you see in the video is exactly how I reproduce the issue. No debugging.
Sorry I missed that video. Thanks.

Very probably I am wrong but...
It seems to me like... if ... when I Compile and "upload" the code to the controller it is pointing to a no controller. Null exception?

Cause mainly it happens when a new controller is added (removed or not yet), perhaps the reference to the new controller is not right or the system doesn't know (because old reference still exist) where to write (object).

arcachofo

arcachofo

Very probably I am wrong but...
It seems to me like... if ... when I Compile and "upload" the code to the controller it is pointing to a no controller. Null exception?

Cause mainly it happens when a new controller is added (removed or not yet), perhaps the reference to the new controller is not right or the system doesn't know (because old reference still exist) where to write (object).
Reproducing the issue is much simpler:It will crash after deleting any Mcu and then run the simulation.
The problem is a simple silly error: It's actually a NULL pointer but not to the Mcu, to one of it's elements that is not properly deleted.
Solved at Rev 1669.

It is quite weird that this issue was not detected before.

Popopo likes this post

Popopo

Popopo

arcachofo wrote:
Solved at Rev 1669.

It is quite weird that this issue was not detected before.

Great Smile

Where could I check fresh versions? in order to download them and use them?

Weird? hum... nothing is weird Smile when it take my hands Twisted Evil Twisted Evil Twisted Evil

arcachofo

arcachofo

Where could I check fresh versions? in order to download them and use them?
You can compile Simulide with the last changes at any moment or wait until I upload new executables.

Popopo likes this post

Popopo

Popopo

arcachofo wrote:
You can compile Simulide with the last changes at any moment or wait until I upload new executables.

I am not good at understanding https://launchpad.net/simulide

I cannot tell which one is the last version (update), and from where to get it.

Is there any thread describing the process?
I see this serie My display doesn't behave like I expect Launch10

But... no idea how to download SCRs.

arcachofo

arcachofo

Development version is "trunk":
But... no idea how to download SCRs.
- Install Bazaar:
sudo apt-get install bzr

- Get the code:
Open a terminal where you want the code and run:
bzr branch lp:simulide

- Compile:
cd simulide/build_XX
qmake
make


You need to install a bunch of things to be able to compile:
- Qt5 dev packages
- Qt5Core
- Qt5Gui
- Qt5Xml
- Qt5Widgets
- Qt5Concurrent
- Qt5svg dev
- Qt5 Multimedia dev
- Qt5 Serialport dev
- Qt5 qmake

Popopo likes this post

19My display doesn't behave like I expect Empty Re: My display doesn't behave like I expect Thu May 18, 2023 11:22 pm

Popopo

Popopo

arcachofo wrote:Development version is "trunk":
But... no idea how to download SCRs.
- Install Bazaar:
sudo apt-get install bzr

- Get the code:
Open a terminal where you want the code and run:
bzr branch lp:simulide

- Compile:
cd simulide/build_XX
qmake
make


You need to install a bunch of things to be able to compile:
- Qt5 dev packages
- Qt5Core
- Qt5Gui
- Qt5Xml
- Qt5Widgets
- Qt5Concurrent
- Qt5svg dev
- Qt5 Multimedia dev
- Qt5 Serialport dev
- Qt5 qmake

Done,
Thank you for your help, without it, I wouldn't do it.

20My display doesn't behave like I expect Empty Re: My display doesn't behave like I expect Fri May 19, 2023 12:37 am

arcachofo

arcachofo

Done,
Thank you for your help, without it, I wouldn't do it.
Nice.
One last thing:
To update your branch just run (from "simulide" folder): bzr pull

Not sure which revision did you got, but the issue in SSD1306 is solved at Rev 1671:
https://bazaar.launchpad.net/~arcachofo/simulide/trunk/changes

Popopo likes this post

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum