peter-l5/SH1107

Garbage on the screen, text not rotated, general Noob confusion.

Closed this issue · 3 comments

First off let me explain that normally I work with M5Stack Micropython so this is somewhat new to me as I constantly forget things.
The following is the code I'm trying to use:

from machine import I2C, Pin
import bmp280
from micropython_sht4x import sht4x
import sh1107
import time

i2c = I2C(1, sda=Pin(2), scl=Pin(3), freq=400000)
sht = sht4x.SHT4X(i2c)
bmp = bmp280.BMP280(i2c)
bmp.oversample(bmp280.BMP280_OS_HIGH)
display = sh1107.SH1107_I2C(128, 64, i2c, address=0x3c, rotate=90)


while True:
    display.sleep(False)
    display.fill(0)
    display.text('SH1107', 0, 0, 1)
    display.text('driver', 0, 8, 1)
    bmp.use_case(bmp280.BMP280_CASE_WEATHER)
    temperature, relative_humidity = sht.measurements
    print(f"SHT40 Temperature: {temperature:.2f}°C")
    print(f"SHT40 Relative Humidity: {relative_humidity:.2%}%")
    print("")
    print("BMP280 tempC: {}".format(bmp.temperature))
    print("BMP280 pressure: {}Pa".format(bmp.pressure))
    print("")
    display.show()
    time.sleep(0.5)

When I run the code the first line is rotated as per the function but is filled with garbage.
The SHT and driver lines aren't rotated and appear in the unrotated locations.
Next (please help with my forgetful ness) How do I display the SHT and BMP readings on the OLED screen please?

Hi Adam,
By garbage on the screen do you mean random black and white pixels on the display? If so that could be caused by several things, so it is difficult to give definite advice. Powering off and on might help, of course. It would be worth checking the set up and that the wiring has good connections. Something that might cause the effect is using the wrong parameters. You have the parameters set for a 128x64 display, which may be correct but with a 128x128 display you could get random pixels and would need to change the settings.

To put text on the screen use display.text() and not print().
More generally, the SH1107 module builds on the micropython framebuf module. As a sub-class, it provides the methods offered by the framebuf module. These are demonstrated in the example code for the module.

If you have further problems specifically related to the SH1107 module I would be happy to try and help, but can't offer general help with MicroPython.

Ok that was weird I had to set the following line:
display = sh1107.SH1107_I2C(128, 64, i2c, address=0x3c, rotate=180)
to 180 for it to work but thanks I was being a noob and you can see the project on hackster.io

Hi Adam,
Thanks for letting me know. Glad you found a solution.
I'll close the issue.