0

Dotstar Class using Raspberry Pi and IOT
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Dotstar Class using Raspberry Pi and IOT

by MonicaSPI on Tue Aug 01, 2017 3:50 pm

I'm trying to use a Raspberry Pi IOT to control the Adafruit Dotstars Strips. I'm newer to C# but it was the only language I could find IOT compatible code that already had the DotStar class built in, so I added it into my project via the nuget manager. I've wrote two programs now, one complicated and one very simplistic and both get stuck on the Show()Show() method. I get an error that says:

System.NullReferenceException:'object reference not set to an instance of an object'

I'm using a Raspberry Pi, Windows 10 Laptop, Visual Studio Community 2017, Adafruit 5m DotStar Strip, Adafruit 74HCT125 Quad Level Shifter, battery supplies for the strip.

I've found online versions of the C# Adafruit Dotstar class so I could look through it myself but nothing I do seems to fix the problem. Here is my more simplistic code in visual studio:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Gpio;
using AdafruitClassLibrary;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId ... lcid=0x409

namespace DotStar_New
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private GpioPin DinPin;
private GpioPinValue DinPinValue;
private const int LED_PIN = 19;

public MainPage()
{
this.InitializeComponent();

InitGPIO();

DotStar LedRace = new DotStar(150, 19, 23, 1); //pin 19 for data and pin 23 for clock
LedRace.BeginAsync();
LedRace.Clear();
LedRace.UpdateLength(150); //length is 30 pixels/meter and we are using 5 meters

uint r = 0; //initiallizes variables
uint g = 255;
uint b = 0;

uint c=LedRace.Color(r, g, b);
for (int i=0; i <150; ++i)
{
LedRace.SetPixelColor(i, c);
}
LedRace.Show();
}

void InitGPIO() //initialize the GPIO of the Raspberry Pi
{
var gpio = GpioController.GetDefault();

// Show an error if there is no GPIO controller
if (gpio == null)
{
DinPin = null;
GpioStatus.Text = "There is no GPIO controller on this device.";
return;
}

DinPin = gpio.OpenPin(LED_PIN);
DinPinValue = GpioPinValue.High;
DinPin.Write(DinPinValue);
DinPin.SetDriveMode(GpioPinDriveMode.Output);

GpioStatus.Text = "GPIO pin initialized correctly.";

}
}
}

MonicaSPI
 
Posts: 12
Joined: Mon Jul 31, 2017 2:29 pm

Re: Dotstar Class using Raspberry Pi and IOT

by mosart on Wed Oct 24, 2018 5:53 pm

Hi.

Would you have a working sample to post? I'm not getting anywhere with my attempts.

Thank you!

mosart
 
Posts: 3
Joined: Wed Oct 24, 2018 5:20 pm

Please be positive and constructive with your questions and comments.