vitroid / M5Stack

2 stars 0 forks source link

Doesn't work code on stm32f4ccu6 and ILI9486 display? #1

Open brightproject opened 1 year ago

brightproject commented 1 year ago

Good afternoon. Have you tried running this code on stm32f4? photo1687114319

I try to adapt the code, but somehow it does not work well with the black pill. Sprites do not want to display at all, just an empty display. https://github.com/Bodmer/TFT_eSPI/issues/2710#issuecomment-1595974553 I also asked the author of the library about this problem, but perhaps you, working with the library, know some nuances? And in general, the code for working with sprites from the library TFT_eSPI? I create aircraft instruments, I'm interested in your solutions in the code. Are you still interested in creating an artificial horizon?

vitroid commented 1 year ago

I am very interested in your project and want to help you.

As far as I can read from my code, it prepares an image buffer and draws everything on the buffer, and finally the image is transfered to the video memory. It is a solution by software and you do not need special support for the hardware sprite.

I have no experience on programming stm32f4 and the LCD module, but if it equips the graphics library (that have at least line and polygon functions drawing on an image buffer), I would be able to port the code.

brightproject commented 1 year ago

Thank you for your response. In your code, I was more interested in the "mathematical" component. How are roll and pitch positions calculated. And of course I wanted to see the code in work, but I ran into the problem of the library TFT_eSPI not working properly with sprites on the microcontroller stm32f4ccu6. As for the buffer, I realized that this buffet, as you said in the TFT display, but the microcontroller, not the display, is still involved in the calculation and formation of the sprite. And these are different things - a picture buffer and a sprite. Probably the library works well with sprites on the ESP32 and specifically on the M5Stack. In the article you talked about the use of a double buffer, but I did not find it in the code. 画面がちらちらするのは、Spriteを使ってダブルバッファーに作画すればいいことがわかった。 Or is double buffering the use of sprites?

vitroid commented 1 year ago

In my code, I use the sprite just for full-screen double buffering. I prepare a sprite image whose size is the same as the screen size, and draw everything in an image, then finally the last img.pushSprite(0, 0); (probably) exposes the image to the screen.

I found a sample code for TFT_eSPI here: https://forum.arduino.cc/t/esp32-st7735-tft-espi-correct-way-to-use-sprite/1078516 It seems that the usage is the same, although the header file is not included explicitly in my code.

Mathematics is very simple.

  float x = (float)IMU.accelCount[0]*IMU.aRes;
  float y = (float)IMU.accelCount[1]*IMU.aRes;
  float z = (float)IMU.accelCount[2]*IMU.aRes;
  // snip
  float ba = atan2(x,y);
  float pitch = atan2(z,y)*180/3.14;

x, y, and z indicates the direction of the acceleration, which is the direction to the earth, and the coordinate system is fixed to the mother board of the M5Stack. Yaw and pitch angles are simply calculated from the acceleration vector. It just works, but I am not sure it is the correct definition of yaw and picth.