Page 1 of 1
D1 mini 0.66" OLED and I2C buttons
Posted: Sun Apr 05, 2020 5:47 pm
by derkomai
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?
Re: D1 mini 0.66" OLED and I2C buttons
Posted: Sat Apr 11, 2020 9:07 am
by VicLuna
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.
Re: D1 mini 0.66" OLED and I2C buttons
Posted: Sat Apr 11, 2020 11:55 am
by derkomai
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
Re: D1 mini 0.66" OLED and I2C buttons
Posted: Tue Apr 14, 2020 5:57 am
by jimmo
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'
Re: D1 mini 0.66" OLED and I2C buttons
Posted: Tue Apr 14, 2020 8:00 am
by derkomai
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.
Re: D1 mini 0.66" OLED and I2C buttons
Posted: Thu Apr 16, 2020 6:13 am
by derkomai
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!