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
- /*
- HelloWorld.ino
- Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
- Copyright (c) 2016, olikraus@gmail.com
- All rights reserved.
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this list
- of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice, this
- list of conditions and the following disclaimer in the documentation and/or other
- materials provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include <Arduino.h>
- #include <U8g2lib.h>
- #ifdef U8X8_HAVE_HW_SPI
- #include <SPI.h>
- #endif
- #ifdef U8X8_HAVE_HW_I2C
- #include <Wire.h>
- #endif
- /*
- U8g2lib Example Overview:
- Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption
- Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards.
- U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only.
- */
- U8G2_SSD1309_128X64_NONAME0_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
- // End of constructor list
- void setup(void) {
- u8g2.begin();
- }
- void loop(void) {
- u8g2.clearBuffer(); // clear the internal memory
- u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
- u8g2.drawStr(0,10,"Hello World!"); // write something to the internal memory
- u8g2.sendBuffer(); // transfer internal memory to the display
- delay(1000);
- }
Ecco il risultato:
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!