I'm porting the SH1106 driver to netmf and have found several libraries that more or less accomplish the same thing. A few were much easier to understand and had less abstraction so I followed those.
I've tried the U8glib with my arduino and it works just fine. The ported display driver yields these results:
inverted:
What you're looking at is the screen right after the initialization and attempting to draw a filled circle. You can see the bottom of the circle at the top of the screen. Somehow the origin or page is shifted, but I don't fully understand what's going on. I can send the invert display command and that works as well and turn the display on and off. My initialization code is this:
public void init2()
{
resetPin.Write(true);
Thread.Sleep(1); // VDD (3.3V) goes high at start, lets just chill for a ms
resetPin.Write(false); // bring reset low
Thread.Sleep(10); // wait 10ms
resetPin.Write(true); // bring out of reset
dcPin.Write(DisplayCommand);
SendCommandB(0xAE); /*display off*/
SendCommandB(0x02); /*set lower column address*/
SendCommandB(0x10); /*set higher column address*/
SendCommandB(0x41);//0x40); /*set display start line*/
SendCommandB(0xB0); /*set page address*/
SendCommandB(0x81); /*contract control*/
SendCommandB(0x80);//contrast); /*128*/
SendCommandB(0xA1); /*set segment remap*/
SendCommandB(0xA6);//invertSetting); /*normal / reverse*/
SendCommandB(0xA8); /*multiplex ratio*/
SendCommandB(0x3F); /*duty = 1/32*/
SendCommandB(0xAD); /*set charge pump enable*/
SendCommandB(0x8B); /*external VCC */
SendCommandB(0x30); // | Vpp); /*0X30---0X33 set VPP 9V liangdu!!!!*/
SendCommandB(0xC8); /*Com scan direction*/
SendCommandB(0xD3); /*set display offset*/
SendCommandB(0x00); /* 0x20 */
SendCommandB(0xD5); /*set osc division*/
SendCommandB(0x80);
SendCommandB(0xD9); /*set pre-charge period*/
SendCommandB(0x1F); /*0x22*/
SendCommandB(0xDA); /*set COM pins*/
SendCommandB(0x12);
SendCommandB(0xDB); /*set vcomh*/
SendCommandB(0x40);
SendCommandB(0xAF); /*display ON*/
// Switch to 'data' mode
dcPin.Write(Data);
this.ClearScreen();
this.Refresh();
}
I've tried fiddling with the start line, but I didn't see any changes.
Here's the circle code:
public void FillCircle(int x0, int y0, int r, Color color)
{
int f = 1 - r;
int ddF_x = 1;
int ddF_y = -2 * r;
int x = 0;
int y = r;
for (int i = y0 - r; i <= y0 + r; i++)
{
SetPixel(x0, i, color);
}
while (x < y)
{
if (f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
for (int i = y0 - y; i <= y0 + y; i++)
{
SetPixel(x0 + x, i, color);
SetPixel(x0 - x, i, color);
}
for (int i = y0 - x; i <= y0 + x; i++)
{
SetPixel(x0 + y, i, color);
SetPixel(x0 - y, i, color);
}
}
if (AutoRefreshScreen)
{
Refresh();
}
}
and the Refresh Code:
public virtual void Refresh()
{
Spi.Write(displayBuffer);
}
At this point I'm a little lost. My hunch is something to do with paging and or display RAM. I'm looking for some insight here on how to fix this as I know there's a lot of experience here with these displays. Thanks!