SSD1306 with APA102?

ZanderPIC

New Member
Hi guys,

Working on a project where I need both a OLED display and RGB LEDs. I've experiment with the SSD1306 display and APA102 LEDs. My issue is I cannot use the 20X2 to communicate with both the display and LEDs. The display requires I2C protocol and the LEDs require SPI.

For the veterans, how would you solve this issue? Because of the relation between the LEDs and display running two controllers would not be optimal. The LEDs need a fast response rate (hardware interrupt) but the OLED can have a long delay >500ms.

I've been trying to figure out this problem for a couple weeks now and figured I'd ask the forum.

Thanks, Zander
 

premelec

Senior Member
Depends on your actual required timing... bit bang the APA102 if the SPI function somehow is in conflict... have you tried it?
 

AllyCat

Senior Member
Hi,

I haven't used either the APA102 or 20X2s, but you could "bit-bang" (software drive) either the SPI or the I2C on any pair of I/O pins. But it will run MUCH slower than the chip hardware (the I2C about 400 times slower) so you will need to decide if either bus can be run more slowly.

Alternatively, although the Clock pin is common, the I2C SDA pin is the SPI Input line, but I would expect the LEDs to require (only) the SPI Output pin? You might need to do a few tests, but I would expect the I2C to "ignore" any signals on the SCL provided that the SDA remains high (which should be possible if no input is applied to the "SPI Iinput"pin). Then I guess you'd need to add an "external" gate to the SPI clock line (SCK) to the LEDs, but that might be a single diode , a transistor, or perhaps the internal "SR Latch". Sadly, only the M2s have the internal "Data Signal Modulator" which could gate the SCK line directly, but you might be able to use one of the internal comparators?

Cheers, Alan.
 

oracacle

Senior Member
As other have suggested, bit bang on our the other. Or if you have a spare pin, you could use opto isolators and a transistor to switch between the two. Or maybe a cd4066. It depends on what you have available on the picaxe
 

ZanderPIC

New Member
Hi,

I haven't used either the APA102 or 20X2s, but you could "bit-bang" (software drive) either the SPI or the I2C on any pair of I/O pins. But it will run MUCH slower than the chip hardware (the I2C about 400 times slower) so you will need to decide if either bus can be run more slowly.

Alternatively, although the Clock pin is common, the I2C SDA pin is the SPI Input line, but I would expect the LEDs to require (only) the SPI Output pin? You might need to do a few tests, but I would expect the I2C to "ignore" any signals on the SCL provided that the SDA remains high (which should be possible if no input is applied to the "SPI Iinput"pin). Then I guess you'd need to add an "external" gate to the SPI clock line (SCK) to the LEDs, but that might be a single diode , a transistor, or perhaps the internal "SR Latch". Sadly, only the M2s have the internal "Data Signal Modulator" which could gate the SCK line directly, but you might be able to use one of the internal comparators?

Cheers, Alan.
Thanks for the very in-depth answer! After looking closely at the spiout function I seem to have "bit-bang" working! I didn't realize you can use any two pins on the controller for software SPI. From what I can tell the latency between using hspi and spiout is very similar. Maybe in situations where more bytes are being sent you'd see the differences.

Code for future reference:

Code:
#picaxe 20x2
setfreq m64

symbol number_of_LEDs = 60

symbol dio = C.3 'LED strip data
symbol clk = C.2 'LED strip clock

symbol blue = b0
symbol green = b1
symbol red = b2
symbol counter = b3

Main:

    ' set LED RGB colours
    blue = 60
    green = 255
    red = 0
    
    counter = 0
    
    gosub StartFrame
    do while counter < number_of_LEDs
        
        gosub LEDframe
        counter = counter + 1
    loop
    gosub StartFrame
    
    gosub Main
    
    
StartFrame:
    spiout clk,dio,MSBFirst_l, (0x00)
    spiout clk,dio,MSBFirst_l, (0x00)
    spiout clk,dio,MSBFirst_l, (0x00)
    spiout clk,dio,MSBFirst_l, (0x00)
    
return

LEDframe:

    'global brightness
    spiout clk,dio,MSBFirst_L, (0xff)

    'blue
    spiout clk,dio,MSBFirst_L, (blue)
    
    'green
    spiout clk,dio,MSBFirst_L, (green)
    
    'red
    spiout clk,dio,MSBFirst_L, (red)

return
Cheers, Zander
 

hippy

Senior Member
I would go for a two chip solution. The master controlling SPI for the APA102, while using HSEROUT to pass the raw data to a second to display on the SSD1306.
 

Aries

New Member
Hippy - what has happened? You are now (a very well-deserved of course) "Senior Member", rather than "Staff Member". I do hope this is only temporary.

PS I am still a "New Member" after six years - what does one have to do to move "up"?
 

hippy

Senior Member
I do hope this is only temporary
Should be.

PS I am still a "New Member" after six years - what does one have to do to move "up"
It's a bit complicated. Members migrated from the old forum I believe are 'frozen in time' with their rank as they were, never advancing, and you have probably been stuck in that time trap. New members progress by the number of postings, I think, but on a different ranking scheme; rookie, normal member, well-known or something like that.

I am sure there would be no problem with labelling members however they'd like, within reason. Maybe there can be an 'after lockdown' party where those who care can decide what they'd like to be.
 
Top