Common.h

Hello there!
I'm a beginner with Arduinos and I'm trying to recreate a project by Nerdforge, which is an LED-lamp setup that reacts to sounds and music. However, in his line of code he provided, he has a line, as such: "#include "reactive_common.h". When I upload the code to the Arduino, it says: "reactive_common.h: No such file or directory". I assume that a common is some sort of personal library or something like that, but I really don't know what I should do to get this code up and running. Are there any tips anyone could give me? Also, if anyone thinks they could take a peek at the code and help me understand it, I would really appreciate it and I'll send the code to you guys. Thanks in advance!

It would probably be helpful if you provided a click-able link to this project. We can't see it or your code.

Sorry about that...

This is the code for the lamps

This is the code for the controller/microphone

It took but a single Bing search to find Natural-Nerd/SoundReactive2/reactive_common.h on Github ( github.com ). Google probably would have worked as well.

Please read three of the four locked topics at the top of this forum (and the links that they point to, etc.) to learn how to post code properly.

Post your code here, using the autoformat function of the IDE (CTRL-T on a PC), and using code tags.

In short, to post code and/or error messages:

  1. Use CTRL-T in the Arduino IDE to autoformat your complete code.
  2. Paste the complete autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.
    3) Paste the complete error message between code tags (the </> button)
    ~~ so that we can easily see and deal with your messages.~~
    4) If you already posted without code tags, you may add the code tags by
    ~~ editing your post. Do not change your existing posts in any other way.~~
    ~~ You may make additional posts as needed.~~
  3. Please provide links to any libraries that are used
    (look for statements in your code that look like #include ). Many libraries
    are named the same but have different contents.
#define FASTLED_INTERRUPT_RETRY_COUNT 0
#define FASTLED_ALLOW_INTERRUPTS 0
#include <FastLED.h>
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#include "reactive_common.h"

#define LED_PIN 2
#define NUM_LEDS 144

#define MIC_LOW 0
#define MIC_HIGH 644

#define SAMPLE_SIZE 20
#define LONG_TERM_SAMPLES 250
#define BUFFER_DEVIATION 400
#define BUFFER_SIZE 3

#define LAMP_ID 1
WiFiUDP UDP;

const char *ssid = "sound_reactive"; // The SSID (name) of the Wi-Fi network you want to connect to
const char *password = "123456789";  // The password of the Wi-Fi network

CRGB leds[NUM_LEDS];

struct averageCounter *samples;
struct averageCounter *longTermSamples;
struct averageCounter* sanityBuffer;

float globalHue;
float globalBrightness = 255;
int hueOffset = 120;
float fadeScale = 1.3;
float hueIncrement = 0.7;

struct led_command {
  uint8_t opmode;
  uint32_t data;
};

unsigned long lastReceived = 0;
unsigned long lastHeartBeatSent;
const int heartBeatInterval = 100;
bool fade = false;

struct led_command cmd;
void connectToWifi();

void setup()
{
  globalHue = 0;
  samples = new averageCounter(SAMPLE_SIZE);
  longTermSamples = new averageCounter(LONG_TERM_SAMPLES);
  sanityBuffer    = new averageCounter(BUFFER_SIZE);

  while (sanityBuffer->setSample(250) == true) {}
  while (longTermSamples->setSample(200) == true) {}

  FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);

  Serial.begin(115200); // Start the Serial communication to send messages to the computer
  delay(10);
  Serial.println('\n');

  WiFi.begin(ssid, password); // Connect to the network
  Serial.print("Connecting to ");
  Serial.print(ssid);
  Serial.println(" ...");

  connectToWifi();
  sendHeartBeat();
  UDP.begin(7001);
}

void sendHeartBeat() {
  struct heartbeat_message hbm;
  hbm.client_id = LAMP_ID;
  hbm.chk = 77777;
  Serial.println("Sending heartbeat");
  IPAddress ip(192, 168, 4, 1);
  UDP.beginPacket(ip, 7171);
  int ret = UDP.write((char*)&hbm, sizeof(hbm));
  printf("Returned: %d, also sizeof hbm: %d \n", ret, sizeof(hbm));
  UDP.endPacket();
  lastHeartBeatSent = millis();
}

void loop()
{
  if (millis() - lastHeartBeatSent > heartBeatInterval) {
    sendHeartBeat();
  }



  int packetSize = UDP.parsePacket();
  if (packetSize)
  {
    UDP.read((char *)&cmd, sizeof(struct led_command));
    lastReceived = millis();
  }

  if (millis() - lastReceived >= 5000)
  {
    connectToWifi();
  }

  int opMode = cmd.opmode;
  int analogRaw = cmd.data;

  switch (opMode) {
    case 1:
      fade = false;
      soundReactive(analogRaw);
      break;

    case 2:
      fade = false;
      allWhite();
      break;

    case 3:
      chillFade();
      break;
  }

}

void allWhite() {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB(255, 255, 235);
  }
  delay(5);
  FastLED.show();
}

void chillFade() {
  static int fadeVal = 0;
  static int counter = 0;
  static int from[3] = {0, 234, 255};
  static int to[3]   = {255, 0, 214};
  static int i, j;
  static double dsteps = 500.0;
  static double s1, s2, s3, tmp1, tmp2, tmp3;
  static bool reverse = false;
  if (fade == false) {
    for (int i = 0; i < NUM_LEDS; i++) {
      leds[i] = CRGB(from[0], from[1], from[2]);
    }
    s1 = double((to[0] - from[0])) / dsteps;
    s2 = double((to[1] - from[1])) / dsteps;
    s3 = double((to[2] - from[2])) / dsteps;
    tmp1 = from[0], tmp2 = from[1], tmp3 = from[2];
    fade = true;
  }

  if (!reverse)
  {
    tmp1 += s1;
    tmp2 += s2;
    tmp3 += s3;
  }
  else
  {
    tmp1 -= s1;
    tmp2 -= s2;
    tmp3 -= s3;
  }

  for (j = 0; j < NUM_LEDS; j++)
    leds[j] = CRGB((int)round(tmp1), (int)round(tmp2), (int)round(tmp3));
  FastLED.show();
  delay(5);

  counter++;
  if (counter == (int)dsteps) {
    reverse = !reverse;
    tmp1 = to[0], tmp2 = to[1], tmp3 = to[2];
    counter = 0;
  }
}

void soundReactive(int analogRaw) {

  int sanityValue = sanityBuffer->computeAverage();
  if (!(abs(analogRaw - sanityValue) > BUFFER_DEVIATION)) {
    sanityBuffer->setSample(analogRaw);
  }
  analogRaw = fscale(MIC_LOW, MIC_HIGH, MIC_LOW, MIC_HIGH, analogRaw, 0.4);

  if (samples->setSample(analogRaw))
    return;

  uint16_t longTermAverage = longTermSamples->computeAverage();
  uint16_t useVal = samples->computeAverage();
  longTermSamples->setSample(useVal);

  int diff = (useVal - longTermAverage);
  if (diff > 5)
  {
    if (globalHue < 235)
    {
      globalHue += hueIncrement;
    }
  }
  else if (diff < -5)
  {
    if (globalHue > 2)
    {
      globalHue -= hueIncrement;
    }
  }


  int curshow = fscale(MIC_LOW, MIC_HIGH, 0.0, (float)NUM_LEDS, (float)useVal, 0);
  //int curshow = map(useVal, MIC_LOW, MIC_HIGH, 0, NUM_LEDS)

  for (int i = 0; i < NUM_LEDS; i++)
  {
    if (i < curshow)
    {
      leds[i] = CHSV(globalHue + hueOffset + (i * 2), 255, 255);
    }
    else
    {
      leds[i] = CRGB(leds[i].r / fadeScale, leds[i].g / fadeScale, leds[i].b / fadeScale);
    }

  }
  delay(5);
  FastLED.show();
}

void connectToWifi() {
  WiFi.mode(WIFI_STA);
  for (int i = 0; i < NUM_LEDS; i++)
  {
    leds[i] = CHSV(0, 0, 0);
  }
  leds[0] = CRGB(0, 255, 0);
  FastLED.show();

  int i = 0;
  while (WiFi.status() != WL_CONNECTED)
  { // Wait for the Wi-Fi to connect
    delay(1000);
    Serial.print(++i);
    Serial.print(' ');
  }
  Serial.println('\n');
  Serial.println("Connection established!");
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
  leds[0] = CRGB(0, 0, 255);
  FastLED.show();
  lastReceived = millis();
}
float fscale(float originalMin, float originalMax, float newBegin, float newEnd, float inputValue, float curve)
{

  float OriginalRange = 0;
  float NewRange = 0;
  float zeroRefCurVal = 0;
  float normalizedCurVal = 0;
  float rangedValue = 0;
  boolean invFlag = 0;

  // condition curve parameter
  // limit range

  if (curve > 10)
    curve = 10;
  if (curve < -10)
    curve = -10;

  curve = (curve * -.1);  // - invert and scale - this seems more intuitive - postive numbers give more weight to high end on output
  curve = pow(10, curve); // convert linear scale into lograthimic exponent for other pow function

  // Check for out of range inputValues
  if (inputValue < originalMin)
  {
    inputValue = originalMin;
  }
  if (inputValue > originalMax)
  {
    inputValue = originalMax;
  }

  // Zero Refference the values
  OriginalRange = originalMax - originalMin;

  if (newEnd > newBegin)
  {
    NewRange = newEnd - newBegin;
  }
  else
  {
    NewRange = newBegin - newEnd;
    invFlag = 1;
  }

  zeroRefCurVal = inputValue - originalMin;
  normalizedCurVal = zeroRefCurVal / OriginalRange; // normalize to 0 - 1 float

  // Check for originalMin > originalMax  - the math for all other cases i.e. negative numbers seems to work out fine
  if (originalMin > originalMax)
  {
    return 0;
  }

  if (invFlag == 0)
  {
    rangedValue = (pow(normalizedCurVal, curve) * NewRange) + newBegin;
  }
  else // invert the ranges
  {
    rangedValue = newBegin - (pow(normalizedCurVal, curve) * NewRange);
  }

  return rangedValue;
}

Note* In my version of this code I made sure to change the ssid and password to fit my internet connection requirements.

You only needed to look in the folder that contained the sketches on GitHub to find the missing file:

It's unfortunate that Natural-Nerd didn't structure their repository in a way that would make it easier for people to use their code.

You can download reactive_common.h here
https://raw.githubusercontent.com/hansjny/Natural-Nerd/master/SoundReactive2/reactive_common.h
You can either save that file into the folder with each of the sketches, or install it as a library.

take a peek at the code and help me understand it

Do you want understanding of a specific line or the whole thing?

It would be nice to get some info on everything, bur I understand it’s quite a bit of code to look through. I would appreciate any kind if help!
PS: Thank you for those very handy links and for your research, I appreciate it :slight_smile:

Hey guys,
Super new to this, I don't understand anything, I've never programmed before- so bare with me.

I am doing this exact project and having this exact issue, although I can't figure it out.

I see that PERT posted a link to the reactive_common.h download there but it is just a link to raw code. I don't see a way to download it and have it in the correct format and file location.

I am unable to include this library using the normal method (sketch-include libraries-manage libraries).

Any direction will help for me, I appreciate anyone who takes the time!

BP

Do this:

Woah, thank's for the lightning response my friend! This worked, but of course, now I'm stuck at another issue. I'm getting the error code :

fork/exec /Users/BrandonPost/Library/Arduino15/packages/esp8266/tools/python3/3.7.2-post1/python3: no such file or directory
Error compiling for board WeMos D1 R1.

yesterday I was able to select the correct port but today the port is not listed. I cannot get the port to show itself, no matter what I try. I found some people had issues with other programs (like my Suunto watch program 'MovesCount' - which I quit out of yesterday and the Com Port just showed up. Today it isn't working, I've run through the CH43r Driver youtube walkthrough's but nothing seems to work.

I would absolutely be willing to 'buy you a coffee' or anything for specific help, as I really appreciate your time.

Macbook pro running Catalina. I also can switch to an old ACER with microsoft, but it's painful to use that computer compared to my mac.

And again, I apologize for my lack of knowledge. I may have bit off more than I can chew with these types of projects, but I love learning new things, and I try not to get frustrated easily.

I recently rebuild my Toyota 4runner's engine with absolutely zero knowledge of mechanics. So I can definitely figure stuff out, but man, this stuff can be difficult.

snowypeaks543:
fork/exec /Users/BrandonPost/Library/Arduino15/packages/esp8266/tools/python3/3.7.2-post1/python3: no such file or directory

When running on macOS, the ESP8266 boards package assumes that you already have Python 3 installed and that it's located at /usr/local/bin/python3. /Users/BrandonPost/Library/Arduino15/packages/esp8266/tools/python3/3.7.2-post1/python3 is just a symlink to /usr/local/bin/python3. The error might be because you don't have Python 3 installed, or because it's not installed at /usr/local/bin/python3 (it sounds like it's often installed at /usr/bin/python3 instead). There is discussion on the problem and solutions starting at this point in this bug report:

snowypeaks543:
yesterday I was able to select the correct port but today the port is not listed.

This is unrelated to the issue with reactive_common.h or Python 3.

Make sure the USB cable is fully plugged in to your ESP8266 board and the computer.

Make sure the ESP8266 board isn't sitting on anything conductive that could be shorting the pins.

Try a different USB cable. The one you're using might be damaged, defective, or charge-only.

Try disconnecting all external wiring/shields/modules/etc. from your ESP8266 board. After doing that and plugging the USB cable into your computer, does the port now appear?

You're pretty good my friend. I do not have python 3 installed at all. I'll delve into this, although it looks like, from the forum, there are many issues here as well. Ill try to find the cleanest way to download it to the correct location. Any tips?

I also was using a 'charge only' cable - which I was unaware of.
The table I am using is metal. bleh.

Two new com ports actually showed up; usbserial1420 and wchusbserial1420

And seriously, do you have a Venmo?

Thanks again for everything, especially your patience haha.
BP

I think I got it actually. Python 3 was pretty simple to dl/install. I think it's working, as it is not coming up with any error messages, although there is still a ton of orange code in the message box near the bottom.

Despite the length of orange messages, it did say 'done compiling' which leaves me hopeful. I'm going to hardwire everything now and see where I'm at.

snowypeaks543:
Two new com ports actually showed up; usbserial1420 and wchusbserial1420

Yay! Those charge-only cables cause so many headaches.

snowypeaks543:
And seriously, do you have a Venmo?

Thanks so much for the offer, but it's not at all necessary. My job is helping people here on the forum. Having success in getting you back to having fun with Arduino is reward enough for me. If you ever want to go beyond that, you could pay it forward one day by helping someone with their Arduino project or just spreading the word about how awesome Arduino is.

snowypeaks543:
I think I got it actually. Python 3 was pretty simple to dl/install.

I'm glad to hear it went well. I have Windows, Linux, and Raspberry Pi, but don't own a Mac, so I have trouble providing Mac-specific assistance.

snowypeaks543:
I'm going to hardwire everything now and see where I'm at.

I'm keeping my fingers crossed!

Well heck yeah, thanks again.

Also, I know I probably am asking all these questions in the wrong place/forum/etc so, again sorry.

I got the code to upload, but there is still this message in orange below;


In file included from /Users/BrandonPost/Documents/Arduino/Sound_Reactive_Lamp_Slave/Sound_Reactive_Lamp_Slave.ino:4:0:
/Users/BrandonPost/Documents/Arduino/libraries/FastLED/FastLED.h:14:21: note: #pragma message: FastLED version 3.003.002

pragma message "FastLED version 3.003.002"

^
In file included from /Users/BrandonPost/Documents/Arduino/libraries/FastLED/FastLED.h:65:0,
from /Users/BrandonPost/Documents/Arduino/Sound_Reactive_Lamp_Slave/Sound_Reactive_Lamp_Slave.ino:4:
/Users/BrandonPost/Documents/Arduino/libraries/FastLED/fastspi.h:130:23: note: #pragma message: No hardware SPI pins defined. All SPI access will default to bitbanged output

pragma message "No hardware SPI pins defined. All SPI access will default to bitbanged output"

^
Executable segment sizes:
IROM : 252968 - code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 27800 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs...)
DATA : 1292 ) - initialized variables (global, static) in RAM/HEAP
RODATA : 948 ) / 81920 - constants (global, static) in RAM/HEAP
BSS : 25368 ) - zeroed variables (global, static) in RAM/HEAP
Sketch uses 283008 bytes (27%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27608 bytes (33%) of dynamic memory, leaving 54312 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.8
Serial port /dev/cu.wchusbserial1420
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: bc:dd:c2:63:e6:46
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 287168 bytes to 209088...

Writing at 0x00000000... (7 %)
Writing at 0x00004000... (15 %)
Writing at 0x00008000... (23 %)
Writing at 0x0000c000... (30 %)
Writing at 0x00010000... (38 %)
Writing at 0x00014000... (46 %)
Writing at 0x00018000... (53 %)
Writing at 0x0001c000... (61 %)
Writing at 0x00020000... (69 %)
Writing at 0x00024000... (76 %)
Writing at 0x00028000... (84 %)
Writing at 0x0002c000... (92 %)
Writing at 0x00030000... (100 %)
Wrote 287168 bytes (209088 compressed) at 0x00000000 in 5.0 seconds (effective 458.5 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...


after hardwiring my project I'm still not getting anything. One LED is lighting up on one of the strings, but it seems like a malfunction. I'm having trouble deciphering the schematics on NerdForge's project. The push button part specifically doesn't make any sense. There are 4 connectors on the pin (he uses the exact button I have ) but the schematic doesn't show A in B out and C in and D out.

https://drive.google.com/file/d/1PRDaSGIENCrb3MHXDk6Qwi3e8gnxunyV/edi

That's the schematic.

Also, it's really confusing because in both schematics he shows the wemos board (mini) having things it doesn't. Meaning he calls for the charger module to connect to the VIN pin on the wemos - there isn't one. There is one on the Wemos d1, but not the mini which he calls for.

So I'm not even sure what I'm asking for or need specifically. Just generally frustrated.

Thanks for being awesome, I appreciate your time.
BP