Display SSD1309 con Arduino

Ciao!

in questo post vedremo come collegare e testare un display SSD1309 con Arduino.




Questo display, si differenzia leggermente dal più noto SSD1306 perchè più grande (2.42" contro 0.96")

Il display è meno diffuso del suo cugino SSD1306, ma è comunque facilmente reperibile anche su Amazon.


I collegamenti ad Arduino sono molto semplici:




Per il test ho utilizzato la notevole libreria u8g2, dovrete scaricarla ed aggiungerla nella directory libraries del vostro ide Arduino per poter compilare il codice sottostante.

Per testare il display ho caricato l'esempio HelloWorld  nel quale ho lasciato solo il display che ci interessa


  1. /*
  2.  
  3.   HelloWorld.ino
  4.  
  5.   Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  6.  
  7.   Copyright (c) 2016, olikraus@gmail.com
  8.   All rights reserved.
  9.  
  10.   Redistribution and use in source and binary forms, with or without modification,
  11.   are permitted provided that the following conditions are met:
  12.  
  13.   * Redistributions of source code must retain the above copyright notice, this list
  14.     of conditions and the following disclaimer.
  15.    
  16.   * Redistributions in binary form must reproduce the above copyright notice, this
  17.     list of conditions and the following disclaimer in the documentation and/or other
  18.     materials provided with the distribution.
  19.  
  20.   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  21.   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  22.   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23.   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24.   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  25.   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26.   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27.   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28.   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29.   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  30.   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31.   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  32.   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
  33.  
  34. */
  35.  
  36. #include <Arduino.h>
  37. #include <U8g2lib.h>
  38.  
  39. #ifdef U8X8_HAVE_HW_SPI
  40. #include <SPI.h>
  41. #endif
  42. #ifdef U8X8_HAVE_HW_I2C
  43. #include <Wire.h>
  44. #endif
  45.  
  46. /*
  47.   U8g2lib Example Overview:
  48.     Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption
  49.     Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards.
  50.     U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only.
  51.    
  52. */
  53.  
  54. U8G2_SSD1309_128X64_NONAME0_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
  55.  
  56.  
  57. // End of constructor list
  58.  
  59.  
  60. void setup(void) {
  61.   u8g2.begin();
  62. }
  63.  
  64. void loop(void) {
  65.   u8g2.clearBuffer();                   // clear the internal memory
  66.   u8g2.setFont(u8g2_font_ncenB08_tr);   // choose a suitable font
  67.   u8g2.drawStr(0,10,"Hello World!");    // write something to the internal memory
  68.   u8g2.sendBuffer();                    // transfer internal memory to the display
  69.   delay(1000);  
  70. }


Ecco il risultato:


Questo è tutto,
Seguimi sulle mie pagine per rimanere sempre aggiornato sui nuovi post!

Nessun commento:

Posta un commento

Lascia un commento qui sotto, ti risponderò il prima possibile!

Altri Post