Driving a Mote APA102*16 ledbar using FEZ Flea

So I need help with the following:

I have Fez Flea board and a Mote APA10*16 RGB led bar. I want to drive the led bar using the flea board and I am running it on TinyCLROS using Visual studio 2022.

Hardware connection:

Connected my fez flea board to my pc using a usb c to usb A cable.
Connected the Mote APA led bar to the board using a usb mini connector on the led bar side and soldered wires to the flea board: red to 5V, black to GND, white to pin 10 (PB15 MOSI2), green to pin 8 (PB13 SCK2)

What works:
I can let the onboard LED of the fez flea blink using the following code:

using System;
using System.Collections;
using System.Diagnostics;
using System.Text;
using System.Threading;

using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Drivers.BasicGraphics;
using GHIElectronics.TinyCLR.Drivers.Worldsemi.WS2812;
using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.Drivers.ShijiLighting;
using GHIElectronics.TinyCLR.Drivers.ShijiLighting.APA102C;
using GHIElectronics.TinyCLR.Devices.Spi;

var LED = GpioController.GetDefault().OpenPin(SC13048.GpioPin.PA8);
LED.SetDriveMode(GpioPinDriveMode.Output);

while (true)
{
    LED.Write(GpioPinValue.High);
    Thread.Sleep(100);

    LED.Write(GpioPinValue.Low);
    Thread.Sleep(100);
}

When I tried to drive the LED bar using SPI communication, it won`t work, there is simply not sufficient documentation. First of all: is my hardware connection OK? If not, what needs to change?
Second, is my code OK (see below)?
Third is there any in depth guide about how to this? And yes, I already checked the ghi electronics website and tutorials, but is very very short and missing alot of information.

Code that doesn`t work for driving the led bar:

using System;
using System.Collections;
using System.Diagnostics;
using System.Text;
using System.Threading;

using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Drivers.BasicGraphics;
using GHIElectronics.TinyCLR.Drivers.Worldsemi.WS2812;
using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.Drivers.ShijiLighting;
using GHIElectronics.TinyCLR.Drivers.ShijiLighting.APA102C;
using GHIElectronics.TinyCLR.Devices.Spi;

var cs = GpioController.GetDefault().OpenPin(SC13048.GpioPin.PB15);

var settings = new SpiConnectionSettings()
{ ChipSelectType = SpiChipSelectType.Gpio,
    ChipSelectLine = cs,
    Mode = SpiMode.Mode1,
    ClockFrequency = 4_000_000,
};

var spiBus = SpiController.FromName(SC13048.SpiBus.Spi2);
var led = new APA102CController(spiBus, 24);

led.SetColor(1, 255, 0, 0); // 2nd LED is Red
Thread.Sleep(100);
led.Flush();

Are you sure the white is data and green is clock? Do you see any lablels on the bar?

No, that I am not sure of. I will try to swap them.
But does the code seem correct?

you need to remove

var cs = GpioController.GetDefault().OpenPin(SC13048.GpioPin.PB15);

That pin is MOSI. Don’t you see any exception?

Those are enough

Hi,

No exception, everything compiles without errors. That pin is indeed MOSI and I guess that is what is required to drive the led bar? MOSI is Master Out Slave IN, so that should be correct pin?

Compile has no exception, only run time give exception.

Yes.

So proper full code should be:

using System;
using System.Collections;
using System.Diagnostics;
using System.Text;
using System.Threading;

using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Drivers.BasicGraphics;
using GHIElectronics.TinyCLR.Drivers.Worldsemi.WS2812;
using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.Drivers.ShijiLighting;
using GHIElectronics.TinyCLR.Drivers.ShijiLighting.APA102C;
using GHIElectronics.TinyCLR.Devices.Spi;



var spiBus = SpiController.FromName(SC13048.SpiBus.Spi2);
var led = new APA102CController(spiBus, 24);

led.SetColor(1, 255, 0, 0); // 2nd LED is Red
Thread.Sleep(100);
led.Flush();

Ok so I tried this code, but now I have reversed the green wire and white wire and it does not work.
I will try to reverse those back again right now and see if that works.

Send us the exactly model so we can take a look for wire

Exact model of Mote APA102-16 is following:

Fez Flea is only one model, it is revision B, firmware version 2.1.0.6500.

Also,

var led = new APA102CController(spiBus, 24);

24 means total led is 24 led. If you have 16 then need to be 16.

I don’t see wires? where is black, blue, green you said?

Please check the following pictures:

This is the response from the debugger:

Found debugger!

Create TS.

Loading Deployment Assemblies.

Attaching deployed file.

   Assembly: mscorlib (2.1.0.0)  Attaching deployed file.

   Assembly: GHIElectronics.TinyCLR.Devices.Spi (2.1.0.0)  Attaching deployed file.

   Assembly: GHIElectronics.TinyCLR.Native (2.1.0.0)  Resolving.

Link failure: some assembly references cannot be resolved!!


Assembly: GHIElectronics.TinyCLR.Devices.Spi (2.1.0.0) needs assembly 'GHIElectronics.TinyCLR.Devices.Gpio' (2.1.0.0)

Error: a3000000

Waiting for debug commands...

The program '[29] TinyCLR application: Managed' has exited with code 0 (0x0).

you need to add “GHIElectronics.TinyCLR.Devices.Gpio 2.1.0.0”

That nugget I already downloaded and added to the project, so it`s strange…
To be sure i also downloaded and added “GHIElectronics.TinyCLR.Devices.GpioLowLevel" now.

No need that one. Just show us how your “Solution Explore” look like?

One more thing. Can you please erase all and reflash firmware , application again?

This is how it looks like:

Look good.

  1. Erase Application and deploy again?
  2. if still not work, select Erase All and reflash and deploy again?

Note: To enable / select Erase All, need to enter bootloader by holding LDR and press reset buttons.

In tinyCLR config, you will see this button once connect SC13

image

1 Like