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();
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.
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.