Breazile / MandoPuter

Electronics to drive a Mandalorian gauntlet
MIT License
41 stars 9 forks source link

driver for ST7735 #9

Open Rodnehh opened 1 year ago

Rodnehh commented 1 year ago

Hey Breazile, first of all; thanks for your work, from what i've seen it looks awesome!

I have a question for making my own mandoputer. I'm trying to run it on a "Wemos Lolin s3 pro" with a breakout shield with SD (ST7735) without sd connection. I happened to have these around and wanted to see if i could get it to work. Unfortunately i havent been able to get it running just yet. My screen is connected correctly, but it doesnt show anything. Could this be driver related? I'm not very familiar with microcontrollers.

Thanks in advance!

Breazile commented 1 year ago

My code is based on CircuitPython and associated libraries. Are you able to load and run CircuitPython on that board?

https://circuitpython.org/board/lolin_s3/

Breazile commented 1 year ago

If so, then let me know how you have the display wired to it.

Rodnehh commented 1 year ago

I did manage to load circuitpython on it. I've taken all the steps to install and put the files on the board. Ive also edited the code.py file.

Added is the picture if how i wired it up. I tried the screen with an arduino test earlier and it did work with the graphicstest sketch.

16798724058793057978891631166714 16798724297311215701501024197320 16798724817315013388626297526167

Breazile commented 1 year ago

Quick look at the wiring it looks like you have pins 3 and 10 swapped, but it is hard to tell. I would expect the brown wire to go to the LED pin on the display and the white wire to go to VCC. The pin naming on the display is I2C not SPI, but I see SPI written there, so I assume that SDA is slave data in for the display. There is no DC pin on the display, so I assume that A0 does the function? Do you have any specs on the display?

The code would need to be updated to drive the right pins. Can you send me code.py? Is there any example code of driving a display with that board we can look at to make sure the right pins are used in the code?

Rodnehh commented 1 year ago

A0 is supposed to be used as DC (has worked on the arduino coding).

I added the manual that i used as an attachment. 1,8 TFT Display_EN (1).pdf

also attached code.py (had to zip it) code.zip

i tried switching pin 3 & 10 but to no avail. The only thing that i thought might be an issue is that in the manual they say that VCC should be 5v. so i have a bidirectional logic shifter on the way to give that a try. With the arduino coding it has worked fine on 3.3v however.

as for the example code; i'm REALLY new to this haha. I have only tried fiddling around with arduino. Is this code fine? graphicstest.zip

Breazile commented 1 year ago

Have you ever used MU before? If not, you should probably give it a try with your board connected to your computer so we can make sure the code is running. It has a serial console that will spit out an error as well as the line of code so we can make sure it is not hitting an error even before it tries to display something

Breazile commented 1 year ago

https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor

Breazile commented 1 year ago

I think we will need Mu running and then we can work through any problems that come up. My gut tells me that it is throwing an error before the display init. Regardless though, I think the display init code should be something like this:

Old code: display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=lcd_rst, polarity=spi_pol, phase=spi_phase)

New code: display_bus = displayio.FourWire(spi, command=board.D47, chip_select=board.48, reset=board.D21, polarity=spi_pol, phase=spi_phase)

We will need to work through some combinations of the polarity and phase probably.

Rodnehh commented 1 year ago

i'll give MU a try right away. let me get back to you on that

Rodnehh commented 1 year ago

i'm getting an error stating the following:

code.py output: Traceback (most recent call last): file "code.py", rule 111, in AttributeError: 'module' object has no attribute 'VOLTAGE_MONITOR'

Code done running

Breazile commented 1 year ago

Change this line: vbat_voltage = AnalogIn(board.VOLTAGE_MONITOR) # for measuring battery voltage

To this: vbat_voltage = AnalogIn(board.A1)

Breazile commented 1 year ago

Then let's see where the next error is

Rodnehh commented 1 year ago

i now have a solid green light on the S3. In Mu it doesnt show any errors anymore. it only says "code stopped by autoreload.reloading soon". Screen is still white though.

Breazile commented 1 year ago

OK, did you make this other change?

display_bus = displayio.FourWire(spi, command=board.D47, chip_select=board.48, reset=board.D21, polarity=spi_pol, phase=spi_phase)

Rodnehh commented 1 year ago

i see that for some reason that one reverted to the old one. I changed it back now and now it states

"module does not have attribute D47"

Breazile commented 1 year ago

I think you need to change this as well:

Old code: spi = board.SPI()

New code: spi = busio.SPI(clock=board.D12, MOSI=board.D11, MISO=board.D13)

Rodnehh commented 1 year ago

i changed that too. Now it says busio is not defined

Breazile commented 1 year ago

Try GP47 or IO47

This is where I need an example of CircuitPython for your board. They don't have any code samples for it? Those labels are board specific, so I'm just guessing at the names

Breazile commented 1 year ago

Same thing for all of the other labels like D12, D11, etc.

Breazile commented 1 year ago

Add this near the top

import busio

Rodnehh commented 1 year ago

You're amazing friend. it works! Thank you very, very much!

it was the IO.

The images are loading now, but it "flashes" when it changes to the next set of characters. Do you know if there's anything i can do to make it more smooth?

Breazile commented 1 year ago

Can you post a video of what the flashing looks like?

Rodnehh commented 1 year ago

I'm thinking it might be related to the refreshrate of the images since they change fairly quickly?

https://user-images.githubusercontent.com/33353696/227834087-b1a770f5-aeb4-45b9-91f6-7c8e6463167b.mp4

Breazile commented 1 year ago

I have not seen that before. The only thing I can think of is try selecting one of these options:

SPI_COM = "Adafruit" # SPI bus polarity=0 and phase=0 for an Adafruit LCD

SPI_COM = "Alt1" # SPI bus polarity=1 and phase=0 for an alternate brand LCD

SPI_COM = "Alt2" # SPI bus polarity=1 and phase=1 for an alternate brand LCD

SPI_COM = "Alt3" # SPI bus polarity=0 and phase=1 for an alternate brand LCD

Comment out the Adafruit one and try one of the Alt ones (one at a time).

Rodnehh commented 1 year ago

unfortunately that does not fix it. The adafruit one, Alt2 and Alt3 all show the lines.

Breazile commented 1 year ago

It's unique to that board, probably the graphics library for that board. I have not seen that flash with all of the boards and displays I have tested. BTW the code base you have is older, you can try the V2 I posted a while ago, but it would need to be fixed again to work with your board.

Rodnehh commented 1 year ago

would that be mandoputer v6.zip?

Breazile commented 1 year ago

No, that is 2 years old

https://github.com/Breazile/MandoPuter

Rodnehh commented 1 year ago

i tried editing the V2, but i think there needs to be some more editing to that file. for example i have the 1.8" screen. Im gonna stick with the old one for now, thanks a lot!

Breazile commented 1 year ago

Send me your code.py again, and I'll integrate the changes into the new code tomorrow. I'm getting my kids to bed, but it should not take me long to integrate tomorrow. Since I do not have your board you'll have to be my tester :)

Rodnehh commented 1 year ago

Do you mean the code we just edited and works now? if so the attached file is the working one.

Thanks for your efforts! working code.zip

Breazile commented 1 year ago

Give this a try. Copy all files and replace existing ones. Open with Mu and we can work through the errors. LolinS3-18.zip

Breazile commented 1 year ago

You'll need CircuitPython 8 or later on your board

Rodnehh commented 1 year ago

I copied the files onto the board and in Mu the first error is

rule 25: import error: no module with name adafruit_ssd1331

Breazile commented 1 year ago

I'm a dumbass, copied the wrong file into the zip. Try this LolinS3-18.zip

Rodnehh commented 1 year ago

haha shit happens. now it says rule 284: runtimeError: Brightness is not adjustable

Breazile commented 1 year ago

LolinS3-18.zip

Just need code.py this time. Give it a shot

Rodnehh commented 1 year ago

rule 311: NameError: name "offset" is not defined

Breazile commented 1 year ago

Add a line of code (offset = 6) around line 215:

Old: display = ST7735R(display_bus, rotation=180, width=160, height=128) font = bitmap_font.load_font("mandalor120.bdf") # 128 pixel tall bitmap font

New: display = ST7735R(display_bus, rotation=180, width=160, height=128) font = bitmap_font.load_font("mandalor120.bdf") # 128 pixel tall bitmap font offset = 6

Rodnehh commented 1 year ago

its showing the symbols now, but sizing seems off and theres a prompt on the top of the screen.

Breazile commented 1 year ago

Can you send me a picture? Is the orientation correct?

Rodnehh commented 1 year ago

im uploading a video :) one sec.

Rodnehh commented 1 year ago

https://user-images.githubusercontent.com/33353696/228075326-0f55e9f2-f6ec-4036-8238-4b2b86120722.mp4

Breazile commented 1 year ago

try offset = 0 instead of offset =6

I think I need to get you a smaller font as well

Breazile commented 1 year ago

around line 214 change the font name to this:

font = bitmap_font.load_font("mandalor82.bdf")  # 128 pixel tall bitmap font
Breazile commented 1 year ago

We'll have to dial in the best sized font for your setup

Rodnehh commented 1 year ago

oof, this one looks distorted haha. i also still have the bar on the top of te screen

Breazile commented 1 year ago

Line 213 let's swap the width and height

old: display = ST7735R(display_bus, rotation=180, width=160, height=128)

new: display = ST7735R(display_bus, rotation=180, width=128, height=160)

Rodnehh commented 1 year ago

that seems to have fixed it. The only thing that remains for me is the flicker when it does the sequence. whenever it changes to the next image, theres the flicker. Besides that: working like a charm!

Breazile commented 1 year ago

Did you end up with offset = 6 or offset =0?

I'll see if I have a display here that uses the ST7735R driver and see if it has flicker. Can you send me a link to the display? I think this is close to the Adafruit 1.8", but different