Porting Nokia5110 lcd code in C to available in upython?

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
Delebel
Posts: 20
Joined: Thu May 25, 2017 2:21 pm
Contact:

Porting Nokia5110 lcd code in C to available in upython?

Post by Delebel » Fri May 26, 2017 9:33 pm

Hi I'm very certainly a Newbie but hopefully a persistent one so that I will advance my project... So turning C code from an 8 bit (pic18f4620) platform to some kind of driver like for the LCD upython already supports. Specially the LCD is a Nokia3110/5110 type. I got the code off github originally. I just want to get some guidance as to what an where to look for info on doing it because I wish to learn in the process.

Thanks Denis the newbie...

User avatar
Roberthh
Posts: 1074
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Porting Nokia5110 lcd code in C to available in upython?

Post by Roberthh » Sat May 27, 2017 7:16 am

If you search thi forum for 5110 you'll find a driver and a lot of useful discussion too. Just use the "search" button. @mcauser has contributed many useful drivers.

User avatar
mcauser
Posts: 326
Joined: Mon Jun 15, 2015 8:03 am

Re: Porting Nokia5110 lcd code in C to available in upython?

Post by mcauser » Thu Jun 01, 2017 5:29 am

I've used mbirth's wipy-upcd8544 driver in a bunch of my ESP8266 projects.
https://github.com/mbirth/wipy-upcd8544

It was originally created for wipy, but with a few small modifications, works with ESP8266.
https://github.com/mbirth/wipy-upcd8544/issues/1

Edit: since have created my own version, which is compatible with MicroPython 1.9, ESP8266 and uses the framebuf:
https://github.com/mcauser/micropython-pcd8544

https://github.com/mcauser/MicroPython- ... Nokia-5110
https://github.com/mcauser/MicroPython- ... me-of-Life
https://github.com/mcauser/MicroPython- ... 10-Bitcoin

It's really easy to write to the display. You can either throw a 84x48 byte array (84*48/8=504 bytes) at the lcd.data() method, or use framebuf, which lets you draw basic shapes an use fonts.

Bytes in the byte array passed to data() are in column major / horizontal orientation.

eg.

Code: Select all

from machine import Pin, SPI
from upcd8544 import PCD8544

spi = SPI(1)
spi.init(baudrate=8000000, polarity=0, phase=0)
RST = Pin(0, Pin.OUT)
CE = Pin(2, Pin.OUT)
DC = Pin(15, Pin.OUT)
BL = Pin(12, Pin.OUT)
lcd = PCD8544(spi, RST, CE, DC, BL)

from framebuf import FrameBuffer1
width = 84
height = 48
buffer = bytearray((height // 8) * width)
framebuf = FrameBuffer1(buffer, width, height)

# black screen
framebuf.fill(1)
lcd.data(buffer)

# white screen
framebuf.fill(0)
lcd.data(buffer)

# write some text
framebuf.text('Hello',0,0)
lcd.data(buffer)

# reset
lcd.clear()

# draw a 84x48 picture
image = bytearray([
0x80,0x00,0x00,0x80,0x00,0x00,0x80,0x00,0x00,0x80,0x00,0x00,0x80,0x00,0x00,0x80,0x00,0x00,0x80,0x80,0x40,0x40,0x40,0x80,0x80,0xC0,0xC0,0x40,0xC0,0xA0,0xE0,0xC0,0xE0,0xE0,0xF0,0xF0,0xF8,0xF8,0xF8,0xFC,0xFC,0xFE,0xEE,0xF4,0xF0,0xF0,0x70,0x30,0x00,0x80,0x00,0x00,0x80,0x00,0x0C,0x9C,0x1C,0x38,0xB8,0x38,0x38,0xB8,0xF8,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF8,0xF8,0xF8,0xF8,
0x88,0x20,0x8A,0x20,0x08,0x22,0x08,0x00,0x0A,0x00,0x00,0x02,0x80,0x71,0xBA,0xDA,0xFD,0xDD,0xED,0xDE,0xEE,0xF7,0xFF,0xFB,0xFD,0xFD,0xFE,0xFF,0x7F,0x3F,0x1F,0x9F,0x3F,0x7F,0x6F,0x0F,0xAF,0x1F,0xBF,0x3E,0x3C,0x7A,0x78,0x70,0x22,0x88,0xA0,0x2A,0x80,0x08,0x62,0xE0,0xE0,0xF2,0xF0,0x58,0xDA,0xF8,0xFC,0x92,0xFE,0xFF,0xFF,0xD3,0xFF,0xFD,0xF3,0xE1,0xF0,0xF9,0x7F,0xBF,0x3F,0x8F,0x2F,0x4F,0xAF,0x0F,0x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0x01,0x01,0x01,0x01,0xBE,0x1B,0x0D,0x07,0x03,0x41,0xE1,0xF1,0xF9,0x6D,0xFF,0xFF,0x00,0x01,0x01,0x01,0xFF,0xFF,0xEB,0x3E,0x0D,0x03,0x01,0x41,0x71,0x70,0x41,0x01,0x03,0x0E,0x3B,0xEF,0xFE,0xFB,0xEE,0x7D,0xF7,0xFF,
0xFF,0xFF,0xFF,0xFE,0xFF,0xF0,0xF0,0xF0,0xF0,0xFF,0xFF,0xFF,0xFF,0xFE,0xFC,0xF8,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xFF,0xFF,0xF8,0xF0,0xF0,0xF0,0xF1,0xF1,0xF1,0xF1,0xF1,0xF1,0xF1,0xF1,0xF0,0xF0,0xF0,0xF8,0xFF,0xFF,0xF0,0xF0,0xF0,0xF0,0xFF,0xFF,0xFE,0xFC,0xF8,0xF0,0xF0,0xF1,0xF3,0xF7,0xFF,0xFF,0xF0,0xF0,0xF0,0xF0,0xFF,0xF3,0xF0,0xF0,0xF0,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xF0,0xF0,0xF0,0xF3,0xFF,0xFF,0xFF,0xFF,0xFF
])
lcd.data(image)
This is the bitmap displayed above:
https://github.com/mcauser/WeMos-D1-min ... -84x48.bmp
The Nokia loading screen.
Last edited by mcauser on Fri Jun 23, 2017 12:54 am, edited 1 time in total.

Delebel
Posts: 20
Joined: Thu May 25, 2017 2:21 pm
Contact:

Re: Porting Nokia5110 lcd code in C to available in upython?

Post by Delebel » Thu Jun 01, 2017 12:25 pm

Thanks I'm still wrestling with the learning curve to learn uPython as an the old school C coder. I've setup the Pyboard with a compatible connector to my Homestat (thermostat/venmar/humidifyer/dehumidifyer+AC) IO panel so that I can experiment with the Pyboard and then retreat to my old C controller so I don't freeze at night... LOL

Thanks again...Denis

Delebel
Posts: 20
Joined: Thu May 25, 2017 2:21 pm
Contact:

Re: Porting Nokia5110 lcd code in C to available in upython?

Post by Delebel » Wed Jul 25, 2018 4:02 pm

Finally got the Nokia LCD to work with the example. Had a hardware issue with the io lines (SPI In/Out lines reversed). I also was trying to get the LCD to work without a RST line because I was getting away with it on my C coded platform. When I added it back the example code used it, it worked immediately. I will try later to have the LCD reset to happen in hardware (power up RC). Thanks for the feedback...Denis

Post Reply