Page 1 of 1
Driver for MY9231/Sonoff B1?
Posted: Wed May 08, 2019 5:57 pm
by mowo94
Someone managed to write a driver for that bulb?
There are two MY9231 in series, so i tried using SPI to write an bytearray, but neither software nor hardware SPI worked.
Then i customized/used the MY9221 lib from mcauser, but that didn't work either.
It might be some timing issue, i only got some random color using the APA102 driver.
Re: Driver for MY9231/Sonoff B1?
Posted: Wed May 08, 2019 7:05 pm
by jimmo
I've used the my9221 before. I don't know what's different compared to the my9231 (other than being able to sink more current) but I remember that they aren't quite SPI devices, you have to do the latching process on just the data line (whereas a SPI driver will always drive both lines).
There's no way that something based purely on machine.SPI is going to work (or the APA102 driver, the data format is different).
Can you share your code and how you've wired it up?
Re: Driver for MY9231/Sonoff B1?
Posted: Thu May 09, 2019 8:25 am
by mowo94
I tried to port some Arduino code, which worked befor
Code: Select all
#Port from Tasmota/Arduino Code
from machine import Pin
from utime import sleep_us as sleep
clockPin = Pin(14, Pin.OUT)
dataPin = Pin(12, Pin.OUT)
chips = 2 #Two chips cascaded
def dataPulse(times):
for x in range(times):
dataPin.value(1)
dataPin.value(0)
def clockPulse(times):
for x in range(times):
clockPin.value(1)
clockPin.value(0)
def write(data):
for x in range(4): #Send 8bit
clockPin.value(0)
dataPin.value(data & 0x80) #I'm not sure about that
clockPin.value(1)
data = data << 1 #Bitshift Left
dataPin.value(data & 0x80)
clockPin.value(0)
dataPin.value(0)
data = data << 1
def my92xxInit():
clockPulse(32 * chips) # Clear all duty register
sleep(12) #Stop after 12us
dataPulse(12)
#Send 12 DI pulse, after 6 pulse's falling edge store duty data, and 12
#pulse's rising edge convert to command mode.
sleep(12)
for x in range(chips):
write(0x18) #ONE_SHOT_DISABLE, REACTION_FAST, BIT_WIDTH_8, FREQUENCY_DIVIDE_1, SCATTER_APDM
sleep(12)
dataPulse(16)
#Send 16 DI pulse, at 14 pulse's falling edge store CMD data, and
#at 16 pulse's falling edge convert to duty mode.
sleep(12)
def colorDuty(r,g,b,w,c):
channels = 3 * chips
duty = [w,c,0,g,r,b] #One channel on the 2nd chip isn't connected
sleep(12)
for channel in range(channels):
write(duty[channel])
sleep(12)
dataPulse(8) #Send 8 DI pulse. After 8 pulse falling edge, store old data.
sleep(12)
my92xxInit()
[\code]