not-matt / Systematic-LEDs

Audio reactive, all in one, room lighting for your computer.
MIT License
100 stars 35 forks source link

Error when flashing FW #32

Open nullTakuro opened 6 years ago

nullTakuro commented 6 years ago

Whenever i flash the FW onto my Lolin ESP8266 NodeMcu 1.0m the flash goes through but the ESP doesnt connect to the wifi and if i open the serial monitor the ESP just keeps printing "⸮". I have tried the audio-reactive-led-strip-master by scottlawsonbc and it works perfectly. I would really like to get this fork running due to all the extra functionality

vincentadamthefirst commented 6 years ago

@nullTakuro Could you provide some code so we can look through it? As for the serial monitor, try using different baud rates (always restart your ESP when you changed it). Only one baud rate will work properly most of the time, some might have some distortion but one should work completely. If the error keeps occuring then somehtign is of with the code or your board, but let's hope it's just a minor bug.

nullTakuro commented 6 years ago

ws2812_controller this is what i flashed to my ESP8266

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WebSocketsServer.h>
#include <Hash.h>
#include <WiFiUdp.h>

#define FASTLED_ESP8266_DMA // better control for ESP8266 will output or RX pin requires fork https://github.com/coryking/FastLED
#include "FastLED.h"

/************ Network Information (CHANGE THESE FOR YOUR SETUP) ************************/
const char* ssid = "Anonymous";
const char* password = "My pass here i know";

const bool static_ip = true;
IPAddress ip(192, 168, 1, 212);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

const int udp_port = 7777;

/*********************************** FastLED Defintions ********************************/
#define NUM_LEDS      250
#define DATA_PIN      5
//#define CLOCK_PIN   2
#define CHIPSET       WS2812B
#define COLOR_ORDER   GRB

/*********************************** Globals *******************************************/
WiFiUDP port;
CRGB leds[NUM_LEDS];

/********************************** Start Setup ****************************************/
void setup() {
  Serial.begin(115200);

  // Setup FastLED
  #ifdef CLOCK_PIN
    FastLED.addLeds<CHIPSET, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  #else
    FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  #endif

  // Setup the wifi connection
  setup_wifi();

  // Initialize the UDP port
  port.begin(udp_port);
}

void setup_wifi() {

  Serial.println();
  Serial.print("Connecting to ");
  Serial.print(ssid);

  if (static_ip) {
    WiFi.config(ip, gateway, subnet);
  }

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected!");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  int packetSize = port.parsePacket();
  if (packetSize == sizeof(leds)) {
    port.read((char*)leds, sizeof(leds));
    FastLED.show();
  } else if (packetSize) {
    Serial.printf("Invalid packet size: %u (expected %u)\n", packetSize, sizeof(leds));
    port.flush();
    return;
  }
}

This is the config.py file that i edited

"""Default settings and configuration for audio reactive LED strip"""
from __future__ import print_function
from __future__ import division
import os

use_defaults = {"configuration": True,                           # See notes below for detailed explanation
                "GUI_opts": False,
                "devices": True,
                "colors": True,
                "gradients": True}

settings = {                                                      # All settings are stored in this dict

    "configuration":{  # Program configuration
                     'USE_GUI': True,                             # Whether to display the GUI
                     'DISPLAY_FPS': False,                        # Whether to print the FPS when running (can reduce performance)
                     'MIC_RATE': 48000,                           # Sampling frequency of the microphone in Hz
                     'MIC_NAME': '',                              # Set input name or keep empty to use default input
                     'FPS': 60,                                   # Desired refresh rate of the visualization (frames per second)
                     'MAX_BRIGHTNESS': 250,                       # Max brightness sent to LED strip
                     'N_ROLLING_HISTORY': 4,                      # Number of past audio frames to include in the rolling window
                     'MIN_VOLUME_THRESHOLD': 0.001                # No music visualization displayed if recorded audio volume below threshold
                    #'LOGARITHMIC_SCALING': True,                 # Scale frequencies logarithmically to match perceived pitch of human ear
                     },

    "GUI_opts":{"Graphs":True,                                    # Which parts of the gui to show
                "Reactive Effect Buttons":True,
                "Non Reactive Effect Buttons":True,
                "Frequency Range":True,
                "Effect Options":True},

    # All devices and their respective settings. Indexed by name, call each one what you want.
    "devices":{"Desk Strip":{
                      "configuration":{"TYPE": "ESP8266",                           # Device type (see below for all supported boards)
                                        # Required configuration for device. See below for all required keys per device
                                       "AUTO_DETECT": False,                         # Set this true if you're using windows hotspot to connect (see below for more info)
                                       "MAC_ADDR": "YOUR MAC ADDRESS HERE",             # MAC address of the ESP8266. Only used if AUTO_DETECT is True
                                       "UDP_IP": "192.168.1.212",                   # IP address of the ESP8266. Must match IP in ws2812_controller.ino
                                       "UDP_PORT": 7777,                            # Port number used for socket communication between Python and ESP8266
                                       "MAX_BRIGHTNESS": 250,                       # Max brightness of output (0-255) (my strip sometimes bugs out with high brightness)
                                         # Other configuration 
                                       "N_PIXELS": 300,                             # Number of pixels in the LED strip (must match ESP8266 firmware)
                                       "N_FFT_BINS": 24,                            # Number of frequency bins to use when transforming audio to frequency domain
                                       "MIN_FREQUENCY": 20,                         # Frequencies below this value will be removed during audio processing
                                       "MAX_FREQUENCY": 18000,                      # Frequencies above this value will be removed during audio processing
                                       "current_effect": "Scroll"                   # Currently selected effect for this board, used as default when program launches
                                      },

                      # Configurable options for this board's effects go in this dictionary.
                      # Usage: config.settings["devices"][name]["effect_opts"][effect][option]
                      "effect_opts":{"Energy":    {"blur": 1,                       # Amount of blur to apply
                                                   "scale":0.9,                     # Width of effect on strip
                                                   "r_multiplier": 1.0,             # How much red
                                                   "mirror": True,                  # Reflect output down centre of strip
                                                   "g_multiplier": 1.0,             # How much green
                                                   "b_multiplier": 1.0},            # How much blue
                                     "Wave":      {"color_wave": "Red",             # Colour of moving bit
                                                   "color_flash": "White",          # Colour of flashy bit
                                                   "wipe_len":5,                    # Initial length of colour bit after beat
                                                   "decay": 0.7,                    # How quickly the flash fades away 
                                                   "wipe_speed":2},                 # Number of pixels added to colour bit every frame
                                     "Spectrum":  {"r_multiplier": 1.0,             # How much red
                                                   "g_multiplier": 1.0,             # How much green
                                                   "b_multiplier": 1.0},            # How much blue
                                     "Wavelength":{"roll_speed": 0,                 # How fast (if at all) to cycle colour overlay across strip
                                                   "color_mode": "Spectral",        # Colour gradient to display
                                                   "mirror": False,                 # Reflect output down centre of strip
                                                   "reverse_grad": False,           # Flip (LR) gradient
                                                   "reverse_roll": False,           # Reverse movement of gradient roll
                                                   "blur": 3.0,                     # Amount of blur to apply
                                                   "flip_lr":False},                # Flip output left-right
                                     "Scroll":    {"lows_color": "Red",             # Colour of low frequencies
                                                   "mids_color": "Green",           # Colour of mid frequencies
                                                   "high_color": "Blue",            # Colour of high frequencies
                                                   "decay": 0.995,                  # How quickly the colour fades away as it moves
                                                   "speed": 4,                      # Speed of scroll
                                                   "mirror": True,                  # Reflect output down centre of strip
                                                   "r_multiplier": 1.0,             # How much red
                                                   "g_multiplier": 1.0,             # How much green
                                                   "b_multiplier": 1.0,             # How much blue
                                                   "blur": 0.2},                    # Amount of blur to apply
                                     "Power":     {"color_mode": "Spectral",        # Colour gradient to display
                                                   "s_count": 20,                   # Initial number of sparks
                                                   "s_color": "White",              # Color of sparks
                                                   "mirror": True,                  # Mirror output down central axis
                                                   "flip_lr":False},                # Flip output left-right
                                     "Single":    {"color": "Purple"},              # Static color to show
                                     "Beat":      {"color": "Red",                  # Colour of beat flash
                                                   "decay": 0.7},                   # How quickly the flash fades away
                                     "Bars":      {"resolution":4,                  # Number of "bars"
                                                   "color_mode":"Spectral",         # Multicolour mode to use
                                                   "roll_speed":0,                  # How fast (if at all) to cycle colour colours across strip
                                                   "mirror": False,                 # Mirror down centre of strip
                                                   "reverse_roll": False,           # Reverse movement of gradient roll
                                                   "flip_lr":False},                # Flip output left-right
                                     "Gradient":  {"color_mode":"Spectral",         # Colour gradient to display
                                                   "roll_speed": 0,                 # How fast (if at all) to cycle colour colours across strip
                                                   "mirror": False,                 # Mirror gradient down central axis
                                                   "reverse": False},               # Reverse movement of gradient
                                     "Fade":      {"color_mode":"Spectral",         # Colour gradient to fade through
                                                   "roll_speed": 1,                 # How fast (if at all) to fade through colours
                                                   "reverse": False},               # Reverse "direction" of fade (r->g->b or r<-g<-b)
                                     "Calibration":{"r": 100,
                                                    "g": 100,
                                                    "b": 100}
                                     }
                                  }
              },

    # Collection of different colours in RGB format
    "colors":{"Red":(255,0,0),
              "Orange":(255,40,0),
              "Yellow":(255,255,0),
              "Green":(0,255,0),
              "Blue":(0,0,255),
              "Light blue":(1,247,161),
              "Purple":(80,5,252),
              "Pink":(255,0,178),
              "White":(255,255,255)},

    # Multicolour gradients. Colours must be in list above
    "gradients":{"Spectral"  : ["Red", "Orange", "Yellow", "Green", "Light blue", "Blue", "Purple", "Pink"],
                 "Dancefloor": ["Red", "Pink", "Purple", "Blue"],
                 "Sunset"    : ["Red", "Orange", "Yellow"],
                 "Ocean"     : ["Green", "Light blue", "Blue"],
                 "Jungle"    : ["Green", "Red", "Orange"],
                 "Sunny"     : ["Yellow", "Light blue", "Orange", "Blue"],
                 "Fruity"    : ["Orange", "Blue"],
                 "Peach"     : ["Orange", "Pink"],
                 "Rust"      : ["Orange", "Red"]
                 }

}

device_req_config = {"Stripless"   : None, # duh
                     "BlinkStick"  : None,
                     "DotStar"     : None,
                     "ESP8266"     : {"AUTO_DETECT": ["Auto Detect",
                                                      "Automatically detect device on network using MAC address",
                                                      "checkbox",
                                                      True],
                                      "MAC_ADDR"   : ["Mac Address",
                                                      "Hardware address of device, used for auto-detection",
                                                      "textbox",
                                                      "aa-bb-cc-dd-ee-ff"],
                                      "UDP_IP"     : ["IP Address",
                                                      "IP address of device, used if auto-detection isn't active",
                                                      "textbox",
                                                      "xxx.xxx.xxx.xxx"],
                                      "UDP_PORT"   : ["Port",
                                                      "Port used to communicate with device",
                                                      "textbox",
                                                      "7778"]},
                     "RaspberryPi" : {"LED_PIN"    : ["LED Pin",
                                                      "GPIO pin connected to the LED strip RaspberryPi (must support PWM)",
                                                      "textbox",
                                                      "10"],
                                      "LED_FREQ_HZ": ["LED Frequency",
                                                      "LED signal frequency in Hz",
                                                      "textbox",
                                                      "800000"],
                                      "LED_DMA"    : ["DMA Channel",
                                                      "DMA channel used for generating PWM signal",
                                                      "textbox",
                                                      "5"],
                                      "LED_INVERT" : ["Invert LEDs",
                                                      "Set True if using an inverting logic level converter",
                                                      "checkbox",
                                                      True]},
                     "Fadecandy"   : {"SERVER"     : ["Server Address",
                                                      "Address of Fadecandy server",
                                                      "textbox",
                                                      "localhost:7890"]}
                     }

"""
    ~~ NOTES ~~

[use_defaults]

For any dicts in this file (config.py), you can add them into the use_defaults
dict to force the program to use these values over any stored in settings.ini
that you would have set using the GUI. At runtime, settings.ini is used to update
the above dicts with custom set values. 

If you're running a headless RPi, you may want to edit settings in this file, then
specify to use the dict you wrote, rather than have the program overwrite from 
settings.ini at runtime. You could also run the program with the gui, set the 
settings that you want, then disable the gui and the custom settings will still
be loaded. Basically it works as you would expect it to.

[DEVICE TYPE]

Device used to control LED strip.

'ESP8266' means that you are using an ESP8266 module to control the LED strip
and commands will be sent to the ESP8266 over WiFi. You can have as many of 
these as your computer is able to handle.

'RaspberryPi' means that you are using a Raspberry Pi as a standalone unit to process
audio input and control the LED strip directly.

'BlinkStick' means that a BlinkstickPro is connected to this PC which will be used
to control the leds connected to it.

'Fadecandy' means that a Fadecandy server is running on your computer and is connected
via usb to a Fadecandy board connected to LEDs

'DotStar' creates an APA102-based output device. LMK if you have any success 
getting this to work becuase i have no clue if it will.

'Stripless' means that the program will run without sending data to a strip.
Useful for development etc, but doesn't look half as good ;)

[REQUIRED CONFIGURATION KEYS]

===== 'ESP8266'
 "AUTO_DETECT"            # Set this true if you're using windows hotspot to connect (see below for more info)
 "MAC_ADDR"               # MAC address of the ESP8266. Only used if AUTO_DETECT is True
 "UDP_IP"                 # IP address of the ESP8266. Must match IP in ws2812_controller.ino
 "UDP_PORT"               # Port number used for socket communication between Python and ESP8266
===== 'RaspberryPi'
 "LED_PIN"                # GPIO pin connected to the LED strip pixels (must support PWM)
 "LED_FREQ_HZ"            # LED signal frequency in Hz (usually 800kHz)
 "LED_DMA"                # DMA channel used for generating PWM signal (try 5)
 "BRIGHTNESS"             # Brightness of LED strip between 0 and 255
 "LED_INVERT"             # Set True if using an inverting logic level converter
===== 'BlinkStick'
 No required configuration keys
===== 'Fadecandy'
 "SERVER"                 # Address of Fadecandy server. (usually 'localhost:7890')
===== 'DotStar'
 No required configuration keys
===== 'Stripless'
 No required configuration keys (heh)

[AUTO_DETECT]

Set to true if the ip address of the device changes. This is the case if it's connecting
through windows hotspot, for instance. If so, give the mac address of the device. This 
allows windows to look for the device's IP using "arp -a" and finding the matching
mac address. I haven't tested this on Linux or macOS.

[FPS]

FPS indicates the desired refresh rate, or frames-per-second, of the audio
visualization. The actual refresh rate may be lower if the computer cannot keep
up with desired FPS value.

Higher framerates improve "responsiveness" and reduce the latency of the
visualization but are more computationally expensive.

Low framerates are less computationally expensive, but the visualization may
appear "sluggish" or out of sync with the audio being played if it is too low.

The FPS should not exceed the maximum refresh rate of the LED strip, which
depends on how long the LED strip is.

[N_FFT_BINS]

Fast Fourier transforms are used to transform time-domain audio data to the
frequency domain. The frequencies present in the audio signal are assigned
to their respective frequency bins. This value indicates the number of
frequency bins to use.

A small number of bins reduces the frequency resolution of the visualization
but improves amplitude resolution. The opposite is true when using a large
number of bins. More bins is not always better!

There is no point using more bins than there are pixels on the LED strip.
"""

for board in settings["devices"]:
    if settings["devices"][board]["configuration"]["TYPE"] == 'ESP8266':
        settings["devices"][board]["configuration"]["SOFTWARE_GAMMA_CORRECTION"] = False
        # Set to False because the firmware handles gamma correction + dither
    elif settings["devices"][board]["configuration"]["TYPE"] == 'RaspberryPi':
        settings["devices"][board]["configuration"]["SOFTWARE_GAMMA_CORRECTION"] = True
        # Set to True because Raspberry Pi doesn't use hardware dithering
    elif settings["devices"][board]["configuration"]["TYPE"] == 'BlinkStick':
        settings["devices"][board]["configuration"]["SOFTWARE_GAMMA_CORRECTION"] = True
    elif settings["devices"][board]["configuration"]["TYPE"] == 'DotStar':
        settings["devices"][board]["configuration"]["SOFTWARE_GAMMA_CORRECTION"] = False
    elif settings["devices"][board]["configuration"]["TYPE"] == 'Fadecandy':
        settings["devices"][board]["configuration"]["SOFTWARE_GAMMA_CORRECTION"] = False
    elif settings["devices"][board]["configuration"]["TYPE"] == 'Stripless':
        settings["devices"][board]["configuration"]["SOFTWARE_GAMMA_CORRECTION"] = False
    else:
        raise ValueError("Invalid device selected. Device {} not known.".format(settings["devices"][board]["configuration"]["TYPE"]))
    settings["devices"][board]["effect_opts"]["Power"]["s_count"] =  settings["devices"][board]["configuration"]["N_PIXELS"]//6
    # Cheeky lil fix in case the user sets an odd number of LEDs
    if settings["devices"][board]["configuration"]["N_PIXELS"] % 2:
        settings["devices"][board]["configuration"]["N_PIXELS"] -= 1

# Ignore these
# settings["configuration"]['_max_led_FPS'] = int(((settings["configuration"]["N_PIXELS"] * 30e-6) + 50e-6)**-1.0)

These where the only 2 files i edited.

nullTakuro commented 6 years ago

I will try the baud rate trick as you explained but i had the same baud rate selected as the code for the controller specifies = 115200

vincentadamthefirst commented 6 years ago

@nullTakuro I don't know if that is the final solution but you should first match the LED count in your firmware and config. Currently you have set the amount of LEDs on the ESP to 250 (is this correct?) and in the config (see N_PIXELS) to 300.

nullTakuro commented 6 years ago

Oh yeah i had missed that. This still doesn't affect the issue I'm having with the ESP as it still does not connect to the wireless network and spits out the backwards "?". I have tried selecting different baud rates both in the code and then monitor and vice versa no luck. I've also tried with the 2 other ESPs that i have and no luck either. They all work with the audio-reactive-led-strip-master by scottlawsonbc, so im puzzled why they don't work here

blassbasti commented 5 years ago

did you download the esp library for the arduino ide?