Example #1
0
        private static void WriteData(byte data)
        {
            //set D/C pin 7 high for data
            GPIOCmd.digitalWrite(4, 1);

            WriteByte(data);
        }
Example #2
0
        private static void WriteCommand(byte command)
        {
            //set D/C pin 7 low for command
            GPIOCmd.digitalWrite(4, 0);

            WriteByte(command);
            ShortDelay();
        }
Example #3
0
        private static bool InitDisplay()
        {
            bool result = false;

            //Reset first!!
            GPIOCmd.digitalWrite(17, 0);
            ShortDelay();
            GPIOCmd.digitalWrite(17, 1);   //release reset
            ShortDelay();

            // Init sequence for 128x64 OLED module
            WriteCommand(SSD1306_DISPLAYOFF);                    // 0xAE
            WriteCommand(SSD1306_SETDISPLAYCLOCKDIV);            // 0xD5
            WriteCommand(0x80);                                  // the suggested ratio 0x80
            WriteCommand(SSD1306_SETMULTIPLEX);                  // 0xA8
            WriteCommand(0x3F);
            WriteCommand(SSD1306_SETDISPLAYOFFSET);              // 0xD3
            WriteCommand(0x0);                                   // no offset
            WriteCommand(SSD1306_SETSTARTLINE | 0x0);            // line #0
            WriteCommand(SSD1306_CHARGEPUMP);                    // 0x8D
            WriteCommand(0x14);                                  //I always use the onboard switcher
            WriteCommand(SSD1306_MEMORYMODE);                    // 0x20
            WriteCommand(0x00);                                  // 0x0 act like ks0108
            WriteCommand(SSD1306_SEGREMAP | 0x1);
            WriteCommand(SSD1306_COMSCANDEC);
            WriteCommand(SSD1306_SETCOMPINS);                // 0xDA
            WriteCommand(0x12);
            WriteCommand(SSD1306_SETCONTRAST);               // 0x81
            WriteCommand(0xCF);                              //I always use the onboard switcher
            WriteCommand(SSD1306_SETPRECHARGE);              // 0xd9
            WriteCommand(0xF1);                              //I always use the onboard switcher
            WriteCommand(SSD1306_SETVCOMDETECT);             // 0xDB
            WriteCommand(0x40);
            WriteCommand(SSD1306_DISPLAYALLON_RESUME);       // 0xA4
            WriteCommand(SSD1306_NORMALDISPLAY);             // 0xA6

            //Finally turn on the display
            WriteCommand(SSD1306_DISPLAYON);

            //WriteCommand(SSD1306_DISPLAYALLON);                   //Screen should be white here!!
            return(result);
        }
Example #4
0
        public static int RunTest()
        {
            //Init PiIO library
            int result = Init.Setup();

            if (result == -1)
            {
                Console.WriteLine("PiIO init failed!");
                return(result);
            }

            //Init PiIO SPI library
            result = SPICmd.Setup(0, 20000000);;
            if (result == -1)
            {
                Console.WriteLine("SPI init failed!");
                return(result);
            }

            Console.WriteLine("SPI init completed, using channel 0 at 20MHz for OLED Display");

            //Now initialise the OLED device and write a hello world message on it!
            //GPIO4 is used for data/~command in 4 wire spi mode
            GPIOCmd.pinMode(4, (int)GPIOCmd.GPIOpinmode.Output);
            GPIOCmd.pinMode(17, (int)GPIOCmd.GPIOpinmode.Output);

            InitDisplay();

            WriteCommand(SSD1306_INVERTDISPLAY);

            ShortDelay();

            WriteCommand(SSD1306_NORMALDISPLAY);

            ClearScreen();
            WriteScreen();

            ShortDelay();
            ShortDelay();

            SetScreen();
            WriteScreen();

            ShortDelay();
            ShortDelay();

            ClearScreen();
            WriteScreen();

            while (true)
            {
                //Write Hello World on display
                ShortDelay();
                ShortDelay();
                WriteText(" " + System.DateTime.Now.ToLongTimeString());
                ShortDelay();
                ShortDelay();
                WriteScreen();

                ShortDelay();
                ShortDelay();

                ShortDelay();
                ShortDelay();

                InitDisplay();
            }
        }