BCM2835 LIB + SSIS1306 LIB 사용 샘플소스코드 입니다.
동작은 잘 됩니다.
아울러 PIGPIO LIB도 동시에 같이 사용할 수 있도록 프로그램 했으니 참고하시기 바랍니다.
빌드옵션입니다.
gcc -Wall -o "%e" "%f" -lbcm2835 -lSSD1306_OLED_RPI -lpigpio -lrt
#include <bcm2835.h>
#include <time.h>
#include <stdio.h>
#include <pigpio.h>
// My LIBRARy
#include "My_Rpi_GPIO_Lib_V2_3.h"
#define I2C_Mode 1
#define I2C_1 2
//#include "My_OLED_U8G2_LIB_V1_3.h"
#include "SSD1306_OLED.hpp"
#define myOLEDwidth 128
#define myOLEDheight 64
const uint16_t I2C_Speed = 626; // bcm2835I2CClockDivider
const uint8_t I2C_Address = 0x3C;
SSD1306 myOLED(myOLEDwidth ,myOLEDheight);
// =============== Function prototypes ================
void setup(void);
void myLoop(void);
// ======================= Main ===================
int main(int argc, char **argv)
{
// pigpio
if(gpioInitialise()<0) exit(1);
if(!bcm2835_init())
{
printf("Error 1201 : Failure to init bcm2835 library\r\n");
return -1;
}
//bcm2835_delay(50);
gpioDelay(d_50ms);
printf("OLED Begin\r\n");
setup();
myOLED.setRotation(0);
myLoop();
myOLED.OLEDPowerDown();
bcm2835_close(); // Close the library,
printf("OLED End\r\n");
//pigpio
gpioTerminate();
return 0;
}
// ======================= End of main =====
// =============== Functions ================
void setup()
{
myOLED.OLEDbegin(I2C_Speed, I2C_Address); // initialize the OLED
myOLED.OLEDFillScreen(0x11, 0); // splash screen
myOLED.setTextColor(WHITE);
bcm2835_delay(1000);
}
void myLoop()
{
// Define a full screen buffer and struct
uint8_t screenBuffer[myOLEDwidth * (myOLEDheight / 8) ];
myOLED.buffer = (uint8_t*) &screenBuffer; // set that to library buffer pointer
myOLED.OLEDclearBuffer(); // clear the buffer
// Set text parameters
myOLED.setTextColor(WHITE);
myOLED.setTextSize(1);
// ** Test 501 OLED display enable and disable **
myOLED.setCursor(0, 30);
myOLED.print("Disable test 501");
printf("OLED Disable test 501\r\n");
myOLED.OLEDupdate();
bcm2835_delay(2000);
myOLED.OLEDEnable(0);
bcm2835_delay(2000);
myOLED.OLEDEnable(1);
bcm2835_delay(2000);
myOLED.OLEDclearBuffer();
// ** Test 502 inverse **
myOLED.setCursor(0, 10);
myOLED.print("Inverse test 502");
printf("OLED Inverse test 502\r\n");
myOLED.OLEDupdate();
bcm2835_delay(1500);
myOLED.OLEDInvert(1); // Inverted
bcm2835_delay(1500);
myOLED.OLEDInvert(0);
bcm2835_delay(1500);
// ** Test 503 contrast **
myOLED.OLEDclearBuffer();
myOLED.setCursor(0, 0);
myOLED.print("Contrast test 503");
printf("OLED Contrast test 503\r\n");
myOLED.OLEDupdate();
bcm2835_delay(1500);
myOLED.OLEDFillScreen(0x77, 0);
myOLED.OLEDContrast(0x00);
bcm2835_delay(1000);
myOLED.OLEDContrast(0x80);
bcm2835_delay(1000);
myOLED.OLEDContrast(0xFF);
bcm2835_delay(1000);
myOLED.OLEDContrast(0x81);
bcm2835_delay(1000);
myOLED.OLEDclearBuffer();
// ***** Test 504 Scroll **
myOLED.setCursor(20,20 );
myOLED.print("scroll test 504");
printf("OLED scroll test 504\r\n");
myOLED.OLEDupdate();
bcm2835_delay(2500);
myOLED.OLED_StartScrollRight(0, 0x0F);
bcm2835_delay(3000);
myOLED.OLED_StopScroll();
myOLED.OLED_StartScrollLeft(0, 0x0F);
bcm2835_delay(3000);
myOLED.OLED_StopScroll();
myOLED.OLED_StartScrollDiagRight(0, 0x07);
bcm2835_delay(3000);
myOLED.OLED_StopScroll();
myOLED.OLED_StartScrollDiagLeft(0, 0x07);
bcm2835_delay(3000);
myOLED.OLED_StopScroll();
// ** Test 505 rotate test **
myOLED.OLEDclearBuffer();
printf("OLED rotate test 505\r\n");
myOLED.setRotation(1);
myOLED.OLEDclearBuffer();
myOLED.print(" rotate 1");
myOLED.setCursor(5,5 );
myOLED.OLEDupdate();
bcm2835_delay(3000);
myOLED.setRotation(2);
myOLED.OLEDclearBuffer();
myOLED.print("rotate 2");
myOLED.setCursor(5,5 );
myOLED.OLEDupdate();
bcm2835_delay(3000);
myOLED.setRotation(3);
myOLED.OLEDclearBuffer();
myOLED.setCursor(5,5 );
myOLED.print("rotate 3");
myOLED.OLEDupdate();
bcm2835_delay(3000);
myOLED.setRotation(0); //default normal
myOLED.OLEDclearBuffer();
myOLED.setCursor(5,5 );
myOLED.print("rotate 0");
myOLED.OLEDupdate();
bcm2835_delay(3000);
// ** end of tests **
myOLED.OLEDclearBuffer();
myOLED.setCursor(5, 5);
myOLED.print("End of tests");
myOLED.OLEDupdate();
bcm2835_delay(3000);
}
//================================================================
//int main()
//{
/*
if(gpioInitialise()<0) exit(1);
my_u8g2_init(&u8g2);
u8g2_SetFontMode(&u8g2, 1);
u8g2_SetFontDirection(&u8g2, 0);
u8g2_SetFont(&u8g2, u8g2_font_ncenB12_tr);
// u8g2_SetDrawColor(&u8g2, 1);
u8g2_DrawStrX2(&u8g2, 25, 25, "u8g2");
u8g2_SetFont(&u8g2, u8g2_font_timR10_tf);
u8g2_DrawStr(&u8g2, 2, 40,"Test123!@~#$%^&*");
u8g2_SendBuffer(&u8g2);
*/
//while(1)
// {
// }
//gpioTerminate();
// return 0;
//}