Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neopixel not working! #53

Open
signorettae opened this issue Aug 28, 2019 · 1 comment
Open

Neopixel not working! #53

signorettae opened this issue Aug 28, 2019 · 1 comment

Comments

@signorettae
Copy link

Hi everybody!
I'm trying to implement some code in order to use the library also on Fishino boards (once it'ill work I'll do a pull request), but something isn't working wery well. When I upload the sketch the board connects to the AP but leds don't work or sometimes do random colors. I tried to comment pieces of code ad I saw that if i comment Artnet artnet; leds start to work as they should. I'm sending Artnet data from LightJams on my pc (192.168.1.100) and my board's ip is 192.168.1.101. Anyone can help me?

Thank you
PS: I modified also the .cpp and .h files in order to work with Fishino boards.

`/*
This example will receive multiple universes via Artnet and control a strip of ws2811 strip via
Adafruit's NeoPixel library: https://github.com/adafruit/Adafruit_NeoPixel
This example may be copied under the terms of the MIT license, see the LICENSE file for details
*/

#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

#include <Artnet.h>
#include <Fishino.h>
#include <FishinoUdp.h>
#include <SPI.h>

// Neopixel settings
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN 2

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 240
const int channelsPerLed = 3;
const int numberOfChannels = LED_COUNT * channelsPerLed; // Total number of channels you want to receive (1 strip = 3 channels)
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

// Artnet settings

Artnet artnet;
const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.

// Check if we got all universes
const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
bool universesReceived[maxUniverses];
bool sendFrame = 1;
int previousDataLength = 0;

byte broadcast[] = {192, 168, 1, 101};

//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// CONFIGURATION DATA -- ADAPT TO YOUR NETWORK !!!
// DATI DI CONFIGURAZIONE -- ADATTARE ALLA PROPRIA RETE WiFi !!!
#ifndef __MY_NETWORK_H

// here pur SSID of your network
// inserire qui lo SSID della rete WiFi
#define MY_SSID "TIM-"

// here put PASSWORD of your network. Use "" if none
// inserire qui la PASSWORD della rete WiFi -- Usare "" se la rete non │ protetta
#define MY_PASS "Signoretta"

// here put required IP address (and maybe gateway and netmask!) of your Fishino
// comment out this lines if you want AUTO IP (dhcp)
// NOTE : if you use auto IP you must find it somehow !
// inserire qui l'IP desiderato ed eventualmente gateway e netmask per il fishino
// commentare le linee sotto se si vuole l'IP automatico
// nota : se si utilizza l'IP automatico, occorre un metodo per trovarlo !
#define IPADDR 192, 168, 1, 101
#define GATEWAY 192, 168, 1, 1
#define NETMASK 255, 255, 255, 0

#endif
// END OF CONFIGURATION DATA //
// FINE CONFIGURAZIONE //
///////////////////////////////////////////////////////////////////////

// define ip address if required
// NOTE : if your network is not of type 255.255.255.0 or your gateway is not xx.xx.xx.1
// you should set also both netmask and gateway
#ifdef IPADDR
IPAddress Ip(IPADDR);
#ifdef GATEWAY
IPAddress gw(GATEWAY);
#else
IPAddress gw(ip[0], ip[1], ip[2], 1);
#endif
#ifdef NETMASK
IPAddress nm(NETMASK);
#else
IPAddress nm(255, 255, 255, 0);
#endif
#endif

void initTest() {
for (int i = 0 ; i < LED_COUNT ; i++)
strip.setPixelColor(i, 127, 0, 0);
strip.show();
delay(500);
for (int i = 0 ; i < LED_COUNT ; i++)
strip.setPixelColor(i, 0, 127, 0);
strip.show();
delay(500);
for (int i = 0 ; i < LED_COUNT ; i++)
strip.setPixelColor(i, 0, 0, 127);
strip.show();
delay(500);
for (int i = 0 ; i < LED_COUNT ; i++)
strip.setPixelColor(i, 0, 0, 0);
strip.show();
}

void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data, IPAddress remoteIP) {
sendFrame = 1;
// set brightness of the whole strip
if (universe == 15) {
strip.setBrightness(data[0]);
strip.show();
}

// Store which universe has got in
if ((universe - startUniverse) < maxUniverses)
	universesReceived[universe - startUniverse] = 1;

for (int i = 0 ; i < maxUniverses ; i++) {
	if (universesReceived[i] == 0) {
		//Serial.println("Broke");
		sendFrame = 0;
		break;
	}
}

// read universe and put into the right part of the display buffer
for (int i = 0; i < length / channelsPerLed; i++) {
	int led = i + (universe - startUniverse) * (previousDataLength / channelsPerLed);
	if (led < LED_COUNT) {
		if (channelsPerLed == 4)
			strip.setPixelColor(led, data[i * channelsPerLed], data[i * channelsPerLed + 1], data[i * channelsPerLed + 2], data[i * channelsPerLed + 3]);
		if (channelsPerLed == 3)
			strip.setPixelColor(led, data[i * channelsPerLed], data[i * channelsPerLed + 1], data[i * channelsPerLed + 2]);
	}
}
previousDataLength = length;

if (sendFrame) {
	strip.show();
	// Reset universeReceived to 0
	memset(universesReceived, 0, maxUniverses);
}

}

void setup() {
Serial.begin(115200);
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(AVR_ATtiny85) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.

strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP

// reset and test WiFi module
// resetta e testa il modulo WiFi
while (!Fishino.reset())
	Serial << F("Fishino RESET FAILED, RETRYING...\n");
Serial << F("Fishino WiFi RESET OK\n");

Fishino.setPhyMode(PHY_MODE_11N);

// go into station mode
// imposta la modalità stazione
Fishino.setMode(STATION_MODE);

// try forever to connect to AP
// tenta la connessione finchè non riesce
Serial << F("Connecting to AP...");
while (!Fishino.begin(MY_SSID, MY_PASS)) {
	Serial << ".";
	delay(2000);
}
Serial << "OK\n";


// setup IP or start DHCP client
// imposta l'IP statico oppure avvia il client DHCP

#ifdef IPADDR
Fishino.config(Ip, gw, nm);
#else
Fishino.staStartDHCP();
#endif

// wait till connection is established
Serial << F("Waiting for IP...");
while (Fishino.status() != STATION_GOT_IP) {
	Serial << ".";
	delay(500);
}
Serial << "OK\n";

//artnet.begin(mac, ip);
artnet.begin();
artnet.setBroadcast(broadcast);

initTest();

// this will be calstrip for each packet received
artnet.setArtDmxCallback(onDmxFrame);

}

void loop() {
// we call the read function inside the loop
artnet.read();
}

`

`

@MathieuMH
Copy link

@signorettae
I don't know how familiar you are with the protocol Art-Net. But a lot off artnet problems like this are caused by network issue. Been there myself.
By convention the artnet ip range should be within 2.x.x.x
However, this does not mean that 192.x.x.x or 10.x.x.x are not going to work. They will. Tricky part is in the subnet mask. Artnet by default a broadcast protocol and therefor it is recommended to use 255.0.0.0 as subnet mask in your network.
In order to subscribe to a artnet port your node needs to reply on the ArtPoll messages. If both are not within the same subnet you will have troubles. Also a lot of lighting tools (mainly dedicated hardware like lighting desks) require an IP within that 2.x.x.x range.
Also artnet requires a dedicated network. I've never really tried it myself but artnet cannot co exist in your home network. But again, just an assumption.
In theory if both IPs are within the 192.168.0.x range and your subnet mask is set to 255.255.255.0 it should work.

Beside that, I quickly looked at your code and noticed the defines to set your IP, subnet, etc.
It gave me the chills, I'm not sure the compiler will implement this the correct way. You defined decimal values separated by a comma. Very confusing.
Have you check you ip address once compiled?

this being said, the broadcast address is your controller address. Did you set artnet to unicast then?
Otherwise you would need something like 192.168.0.255 (note that the default broadcast address is 2.255.255.255)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants