D1 mini 0.66" OLED and I2C buttons

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
derkomai
Posts: 4
Joined: Sun Apr 05, 2020 5:36 pm

D1 mini 0.66" OLED and I2C buttons

Post by derkomai » Sun Apr 05, 2020 5:47 pm

Hi everyone. I'm new over here and I'm fiddling with a Lolin D32 mini and the following 0.66" OLED screen with 2 x I2C buttons:

https://docs.wemos.cc/en/latest/d1_mini ... _0_66.html

After a few hours trying to make the two buttons work and looking for some docs, I'm starting to think that maybe I'm not understanding correctly how they work. First of all, if I have the display connected on top of the D1 mini instead of using an I2C cable, can I read the buttons state from any of the digital pins? I've looked at the schematic, but I'm not very good at understanding wiring. I've tried all pins without success.

Second, I've also tried using the i2c module, but without success. If I understood correctly, I should first write an I2C command and the read, right? Something like:

Code: Select all

i2c.writeto(49, b'4')
i2c.readfrom(49, 1)
But I could not see any change on the buttons' status using that code. Can someone help me out?

VicLuna
Posts: 11
Joined: Fri Sep 13, 2019 8:36 pm

Re: D1 mini 0.66" OLED and I2C buttons

Post by VicLuna » Sat Apr 11, 2020 9:07 am

can you write your I2C object definition?

because at the datasheet say

D1 mini GPIO Shield
D1 5 SCL
D2 4 SDA

so are you wiring ping 5, and pin 4 with SCL and SDA respectively.

derkomai
Posts: 4
Joined: Sun Apr 05, 2020 5:36 pm

Re: D1 mini 0.66" OLED and I2C buttons

Post by derkomai » Sat Apr 11, 2020 11:55 am

Code: Select all

from machine import Pin, I2C
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
print(i2c.scan())  # returns [49, 60] as expected

i2c.writeto(49, b'4')  # returns 1, so I get 1 ACK, correct.
i2c.readfrom(49, 1)  # returns \x02, or \x02\xff\xff\xff\xff\xff\xff\xff if I read more bytes
This is the code I'm running, line by line, in the REPL. The wiring should be correct, as the oled comes in a shield specifically designed for the Lolin D1 mini. I've soldered the shield on top it, and so far the OLED works great. It's just the buttons were I have trouble.

Having a look at Wemos' i2c-button-library, it seems that I have to proceed in the following way:

- Send i2c command GET_KEY_VALUE (0x04) (1 byte) and get 1 ACK
- Read i2c response (value from 0x00 to 0x04) (1 byte)

That's what I'm trying to replicate.

https://github.com/wemos/LOLIN_OLED_I2C ... C_BUTTON.h

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: D1 mini 0.66" OLED and I2C buttons

Post by jimmo » Tue Apr 14, 2020 5:57 am

derkomai wrote:
Sat Apr 11, 2020 11:55 am
- Send i2c command GET_KEY_VALUE (0x04)
derkomai wrote:
Sat Apr 11, 2020 11:55 am
i2c.writeto(49, b'4') # returns 1, so I get 1 ACK, correct.
These two are not the same thing.

b'4' is 0x34 (i.e. the ascii code for the '4' character). You want to use b'\x04'

derkomai
Posts: 4
Joined: Sun Apr 05, 2020 5:36 pm

Re: D1 mini 0.66" OLED and I2C buttons

Post by derkomai » Tue Apr 14, 2020 8:00 am

jimmo wrote:
Tue Apr 14, 2020 5:57 am
derkomai wrote:
Sat Apr 11, 2020 11:55 am
- Send i2c command GET_KEY_VALUE (0x04)
derkomai wrote:
Sat Apr 11, 2020 11:55 am
i2c.writeto(49, b'4') # returns 1, so I get 1 ACK, correct.
These two are not the same thing.

b'4' is 0x34 (i.e. the ascii code for the '4' character). You want to use b'\x04'
Oh, thanks! I'll give it a try later.

derkomai
Posts: 4
Joined: Sun Apr 05, 2020 5:36 pm

Re: D1 mini 0.66" OLED and I2C buttons

Post by derkomai » Thu Apr 16, 2020 6:13 am

jimmo wrote:
Tue Apr 14, 2020 5:57 am
derkomai wrote:
Sat Apr 11, 2020 11:55 am
- Send i2c command GET_KEY_VALUE (0x04)
derkomai wrote:
Sat Apr 11, 2020 11:55 am
i2c.writeto(49, b'4') # returns 1, so I get 1 ACK, correct.
These two are not the same thing.

b'4' is 0x34 (i.e. the ascii code for the '4' character). You want to use b'\x04'
Yes, hat was it, thak you for your help!

Post Reply