Advertisement
MrRockchip

test

Aug 23rd, 2023 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.33 KB | None | 0 0
  1. sudo avrdude -P /dev/ttyUSB0 -c stk500 -p m2560 -b 115200 -U flash:r:flash_raw2.bin:r
  2.  
  3. https://forum.arduino.cc/t/ili9341-controller-rotation-180/488473
  4. domcl
  5.  
  6.  
  7. 1835030405
  8.  
  9. Arduino Forum
  10. ILI9341 controller, rotation 180°
  11. Using Arduino Displays
  12. souf_nucl October 30, 2017, 9:11am 1
  13.  
  14. Hi,
  15.  
  16. I've seen that vagos21 posted some time ago a topic for the rotation a his display (UTFT, rotate the screen 180 degrees ?)
  17. He used a SSD1963 controller with the UTFT library.
  18. Thecode that seems to do the work for him was these two lines:
  19. LCD_Write_COM(0x36); //rotation
  20. LCD_Write_DATA(0x22 ^ 0x03); //invert both SS and GS to rotate 180 degrees
  21.  
  22. I tried to used them for the same issue that I have with an ILI9341_16.
  23. But clearly I didn't understood how they are working.
  24.  
  25. Can someone help me understand these two lines and how I can ortate me screen 180°.
  26. Thanks all
  27. david_prentice October 30, 2017, 10:02am 2
  28.  
  29. Your current initialisation will be somewhere like this:
  30.  
  31. C:\Users\David Prentice\Documents\Arduino\libraries\UTFT_v2.82\tft_drivers\ili9341\16
  32.  
  33. and it has a sequence:
  34.  
  35. LCD_Write_COM(0x36); // Memory Access Control
  36. LCD_Write_DATA(0x48);
  37.  
  38. change it to :
  39.  
  40. LCD_Write_COM(0x36); // Memory Access Control
  41. LCD_Write_DATA(0x48 ^ 0xC0); //invert the MY and MX bits for 180 degrees
  42.  
  43. You can see what the MY, MX, MV, ML, ... bits do by studying the ILI9341 datasheet.
  44. You quoted an example for the SSD1963. The SSD1963 has slightly different behaviour in its 0x36 register.
  45.  
  46. Most libraries will use the TFT hardware to implement rotations. You have to set all the bits correctly.
  47. UTFT just does it in software. You only need to get the regular PORTRAIT correct.
  48.  
  49. David.
  50. souf_nucl October 30, 2017, 10:31am 3
  51.  
  52. Thanks David
  53.  
  54. that work just great, has expected.
  55. I have been looking in the datasheet of the ILI9341 and I found that I needed to write on the register 0x36, but my parameters were :
  56.  
  57. LCD_Write_COM(0x36); // Memory Access Control
  58. LCD_Write_DATA(0xD6);
  59.  
  60. Which didn't worked,
  61. I also tried to add your code in my main code rather than changing the library, which is more clean for me, except that doesn't work.
  62.  
  63. here is my code :
  64.  
  65. #include <UTFT.h>
  66.  
  67. Declare which fonts we will be using
  68. extern uint8_t SmallFont[];
  69.  
  70. UTFT myGLCD(ILI9341_16,82,83,84,85);
  71.  
  72. void setup()
  73. {
  74. randomSeed(analogRead(0));
  75.  
  76. // Setup the LCD
  77. myGLCD.InitLCD();
  78.  
  79. myGLCD.LCD_Write_COM(0x36);
  80. myGLCD.LCD_Write_DATA(0x48 ^ 0xC0);
  81.  
  82. myGLCD.setFont(SmallFont);
  83. }
  84.  
  85. void loop()
  86. {
  87. int buf[318];
  88. int x, x2;
  89. int y, y2;
  90. int r;
  91.  
  92. // Clear the screen and draw the frame
  93. myGLCD.clrScr();
  94.  
  95. myGLCD.setColor(255, 0, 0);
  96. myGLCD.fillRect(0, 0, 319, 13);
  97. myGLCD.setColor(64, 64, 64);
  98. myGLCD.fillRect(0, 226, 319, 239);
  99. myGLCD.setColor(255, 255, 255);
  100. myGLCD.setBackColor(255, 0, 0);
  101. myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1);
  102. myGLCD.setBackColor(64, 64, 64);
  103. myGLCD.setColor(255,255,0);
  104. myGLCD.print("http://www.RinkyDinkElectronics.com/", CENTER, 227);
  105. }
  106.  
  107. so my next question is how can I do this rotation without changing the library?
  108.  
  109. Thanks again
  110. david_prentice October 30, 2017, 11:46am 4
  111.  
  112. I presume that you want to rotate by 180 degrees because your wiring is more convenient that way.
  113.  
  114. So you might just as well edit the initlcd.h file once. Every sketch will work with 180 rotation.
  115.  
  116. Of course you can put it into every sketch but that gets a bit painful.
  117.  
  118. #include <UTFT.h>
  119.  
  120. //Declare which fonts we will be using
  121. extern uint8_t SmallFont[];
  122.  
  123. UTFT myGLCD(ILI9341_16, 82, 83, 84, 85); //souf_nucl
  124. //UTFT myGLCD(ILI9341_S5P, 11, 13, 10, 8, 9); //.kbv
  125.  
  126. void setup()
  127. {
  128. randomSeed(analogRead(0));
  129.  
  130. // Setup the LCD
  131. myGLCD.InitLCD();
  132.  
  133. cbi(myGLCD.P_CS, myGLCD.B_CS); // CS Active
  134. myGLCD.LCD_Write_COM(0x36);
  135. myGLCD.LCD_Write_DATA(0x48 ^ 0xC0);
  136. sbi(myGLCD.P_CS, myGLCD.B_CS); // CS Idle
  137.  
  138. myGLCD.setFont(SmallFont);
  139. }
  140.  
  141. void loop()
  142. {
  143. int buf[318];
  144. int x, x2;
  145. int y, y2;
  146. int r;
  147.  
  148. // Clear the screen and draw the frame
  149. myGLCD.clrScr();
  150.  
  151.  
  152.  
  153. myGLCD.setColor(255, 0, 0);
  154. myGLCD.fillRect(0, 0, 319, 13);
  155. myGLCD.setColor(64, 64, 64);
  156. myGLCD.fillRect(0, 226, 319, 239);
  157. myGLCD.setColor(255, 255, 255);
  158. myGLCD.setBackColor(255, 0, 0);
  159. myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1);
  160. myGLCD.setBackColor(64, 64, 64);
  161. myGLCD.setColor(255, 255, 0);
  162. myGLCD.print("<http://www.RinkyDinkElectronics.com/>", CENTER, 227);
  163. }
  164.  
  165. David.
  166. souf_nucl October 30, 2017, 1:01pm 5
  167.  
  168. Thanks David,
  169.  
  170. It work perfectly, can you explain me how can I find the two lines that you added:
  171. cbi(myGLCD.P_CS, myGLCD.B_CS);
  172. sbi(myGLCD.P_CS, myGLCD.B_CS); // CS Idle
  173.  
  174. I'd like to understand them so I can use the same method later
  175.  
  176. Thanks a lot
  177. david_prentice October 30, 2017, 3:38pm 6
  178.  
  179. Look in the UTFT.cpp file. You will see that every command sequence starts with making CS active (low). And ends with making CS idle (high)
  180.  
  181. cbi (P_CS, B_CS);
  182. ...
  183. sbi (P_CS, B_CS);
  184.  
  185. Since P_CS and B_CS are class variables from the UTFT class, your sketch needs to use the full myGLCD.P_CS name.
  186.  
  187. You could use digitalWrite() if the class stored the digital pin number. The class stores the CS PORT address and the PORT bit. Libraries often store address and bitmask because it will be faster than digitalWrite() on some Arduinos.
  188.  
  189. Please think about the initlcd.h solution. It applies to your particular ILI9341 screen. It will not upset any other screens.
  190.  
  191. David.
  192. souf_nucl October 31, 2017, 10:26am 7
  193.  
  194. Thank a lot David.
  195.  
  196. I think I understand the thinking behind your solution.
  197. That really helped me.
  198.  
  199. The reason why I can't change the library is because I'm not the only one that use it, and the shield card that I use made me have to rotate the display in the code.
  200.  
  201. Again thanks David.
  202. best regards
  203. hydrocontrol January 2, 2018, 2:18pm 8
  204.  
  205. David Prentice,
  206.  
  207. your information was very useful to me. It saved me hours of research. Thank you!
  208. (Unfortunately, one can only add 1 karma per hour :slight_smile:
  209.  
  210. Thomas
  211. system Closed May 6, 2021, 3:52am 9
  212.  
  213. Home Categories FAQ/Guidelines Terms of Service Privacy Policy
  214.  
  215. Powered by Discourse, best viewed with JavaScript enabled
  216. Unfortunately, your browser is unsupported. Please switch to a supported browser to view rich content, log in and reply.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement