SH1107 reading ID
Posted: Fri Dec 31, 2021 2:35 pm
Hi, I just managed to get working a micropython project for the following hardware setup:
- Pimoroni Pico Breakout Garden (BG) base with;
- a Raspberry Pi Pico;
- a Pimoroni BG RV3028 rtc (I2C);
- an Adafruit TMP117 via Qwiic to a Pimoroni BG adapter;
- a Pimoroni BG OLED 1.12in 128x128 SPI LCD (SH1107).
In the many examples and drivers for SH1106 that I have seen, there are only used command to WRITE command or data.
I did not see commands to READ, for example READ the status of a register.
In the datasheet for the SH1107, page 40, paragraph 22 (or command 22 ?) "Read ID" is described the register that contains:
a) the SH1107 BUSY bit (b7);
b) the SH1107 ON/OFF bit (b6);
c) the SH1107 ID bits (b5~b0)
The datasheed writes on c): "These bits contain the information of the chip. They output bits 000111(it means 07)."
This paragraph also describes which lines need to have a logical state HIGH or LOW:
```
+----+--------+--------------------+-------+-----------+--------------------------+
| A0 | RD (E) | WR ( R / W ) | D7 | D6 | D5 D4 D3 D2 D1 D0 |
+----+--------+-------------------+-------+------------+--------------------------+
| 0 | 0 | 1 | BUSY | ON/OFF | ID |
+----+--------+-------------------+-------+------------+--------------------------+
```
I don't know to which lines of the OLED BG board these three lines "A0", "RD" and "WR" are connected.
The 1.12in OLED SPI BG board has 7 pins: 3-6V, CS, SCK, MOSI, DC, 0 (not connected?), GND.
My guess is the following hardware connection:
A0 -> dc ;
RD -> mosi ;
WR -> cs.
In this moment, in my version of sh1107.py, to read the ID information, I created three functions:
```
def get_ID(self):
if self.id is None:
self.read_ID() # get the OLED ID
return self.id
def clr_ID(self):
self.id_buf[0] = 0
self.id = None
def read_ID(self): # See datasheet, p.40, command # 22
self.clr_ID()
self.write_cmd(GET_ID)
# read ID D5~D0
self.spi.readinto(self.id_buf) # fill self.id_buf for test read
u = struct.unpack('>B', self.id_buf, 0)[0]
self.cs(1)
print("SH1107.read_ID(): unpacked self.id_buf = 0b{:08b}".format(u),end='\n')
# self.id = (self.id_buf[0] & 0x3F) == 0x3F # set self.id
self.id = u & 0x3F
```
while in: sh1107.__init__() are defined:
GET_ID = const(0x00)
self.id_buf = bytearray(1) # 1 byte to read SH1106's data
self.id = None
From the main.py script I used the following call :
print("OLED ID: 0x{:x}".format(OLED.get_ID()),end='\n')
The datasheet of the SH1107 in the paragraph of 'read ID' states:
ID: These bits contain the information of the chip. They output bits 000111(it means 07).
However the output of my script is:
```SH1107.read_ID(): unpacked self.id_buf = 0xffffh
SH1107.read_ID(): self.id_buf = 0b11111111``` which means 15 and means that the bits BUSY and ON/OFF are (always?) On.
for the ON/OFF this is OK but for the BUSY bit not. That should go to a LOW
state at times.
and not '0b000111' which means 7.
The 'result' in the main.py script:
OLED ID: 0x3f
I was thinking that maybe I am getting wrong data because of wrong programming.
Anyone who has an idea?
- Pimoroni Pico Breakout Garden (BG) base with;
- a Raspberry Pi Pico;
- a Pimoroni BG RV3028 rtc (I2C);
- an Adafruit TMP117 via Qwiic to a Pimoroni BG adapter;
- a Pimoroni BG OLED 1.12in 128x128 SPI LCD (SH1107).
In the many examples and drivers for SH1106 that I have seen, there are only used command to WRITE command or data.
I did not see commands to READ, for example READ the status of a register.
In the datasheet for the SH1107, page 40, paragraph 22 (or command 22 ?) "Read ID" is described the register that contains:
a) the SH1107 BUSY bit (b7);
b) the SH1107 ON/OFF bit (b6);
c) the SH1107 ID bits (b5~b0)
The datasheed writes on c): "These bits contain the information of the chip. They output bits 000111(it means 07)."
This paragraph also describes which lines need to have a logical state HIGH or LOW:
```
+----+--------+--------------------+-------+-----------+--------------------------+
| A0 | RD (E) | WR ( R / W ) | D7 | D6 | D5 D4 D3 D2 D1 D0 |
+----+--------+-------------------+-------+------------+--------------------------+
| 0 | 0 | 1 | BUSY | ON/OFF | ID |
+----+--------+-------------------+-------+------------+--------------------------+
```
I don't know to which lines of the OLED BG board these three lines "A0", "RD" and "WR" are connected.
The 1.12in OLED SPI BG board has 7 pins: 3-6V, CS, SCK, MOSI, DC, 0 (not connected?), GND.
My guess is the following hardware connection:
A0 -> dc ;
RD -> mosi ;
WR -> cs.
In this moment, in my version of sh1107.py, to read the ID information, I created three functions:
```
def get_ID(self):
if self.id is None:
self.read_ID() # get the OLED ID
return self.id
def clr_ID(self):
self.id_buf[0] = 0
self.id = None
def read_ID(self): # See datasheet, p.40, command # 22
self.clr_ID()
self.write_cmd(GET_ID)
# read ID D5~D0
self.spi.readinto(self.id_buf) # fill self.id_buf for test read
u = struct.unpack('>B', self.id_buf, 0)[0]
self.cs(1)
print("SH1107.read_ID(): unpacked self.id_buf = 0b{:08b}".format(u),end='\n')
# self.id = (self.id_buf[0] & 0x3F) == 0x3F # set self.id
self.id = u & 0x3F
```
while in: sh1107.__init__() are defined:
GET_ID = const(0x00)
self.id_buf = bytearray(1) # 1 byte to read SH1106's data
self.id = None
From the main.py script I used the following call :
print("OLED ID: 0x{:x}".format(OLED.get_ID()),end='\n')
The datasheet of the SH1107 in the paragraph of 'read ID' states:
ID: These bits contain the information of the chip. They output bits 000111(it means 07).
However the output of my script is:
```SH1107.read_ID(): unpacked self.id_buf = 0xffffh
SH1107.read_ID(): self.id_buf = 0b11111111``` which means 15 and means that the bits BUSY and ON/OFF are (always?) On.
for the ON/OFF this is OK but for the BUSY bit not. That should go to a LOW
state at times.
and not '0b000111' which means 7.
The 'result' in the main.py script:
OLED ID: 0x3f
I was thinking that maybe I am getting wrong data because of wrong programming.
Anyone who has an idea?