OPEnSLab-OSU / Loom

Arduino library for Internet of Things Rapid Prototyping in environmental sensing
GNU General Public License v3.0
26 stars 3 forks source link

Test Loom_Neopixel - Winnie #149

Closed winniiew closed 3 years ago

winniiew commented 3 years ago

Neopixel is able to flash one color but will not alternate even when using the same function

winniiew commented 3 years ago
///////////////////////////////////////////////////////////////////////////////

// This is simple example that is used to change the color of a 
// Neopixel to red, yellow, and green with a 2 second delay for each color

// This was wired through the A2 pin

///////////////////////////////////////////////////////////////////////////////

#include <Loom.h>

// Include configuration
const char* json_config = 
#include "config.h"
;

// In Tools menu, set:
// Internet  > Disabled
// Sensors   > Enabled
// Radios    > Disabled
// Actuators > Enabled
// Max       > Disabled

using namespace Loom;

Loom::Manager Feather{};

void setup() 
{ 

  pinMode(5, OUTPUT);
  digitalWrite(5, LOW); // Sets pin 5, the pin with the 3.3V rail, to output and enables the rail
  pinMode(6, OUTPUT);
  digitalWrite(6, HIGH); // Sets pin 6, the pin with the 5V rail, to output and enables the rail

  pinMode(A2, OUTPUT);

  Feather.begin_serial(true);
  Feather.parse_config(json_config);
  Feather.print_config();

  LPrintln("\n ** Setup Complete ** ");
}

void loop() 
{
  getNeopixel(Feather).set_color(2, 0, 200, 0, 0);
  delay(2000);
  getNeopixel(Feather).set_color(2, 0, 0, 0, 0);
  delay(2000);

  getNeopixel(Feather).set_color(2, 0, 200, 200, 0);
  delay(2000);
  getNeopixel(Feather).set_color(2, 0, 0, 0, 0);
  delay(2000);

  getNeopixel(Feather).set_color(2, 0, 0, 200, 0);
  delay(2000);
  getNeopixel(Feather).set_color(2, 0, 0, 0, 0);
  delay(2000);

  Feather.measure();
  Feather.package();
  Feather.display_data();
  Feather.pause();
}
winniiew commented 3 years ago
"{\
  'general':\
  {\
    'name':'Device',\
    'instance':1,\
    'interval':2000\
  },\
  'components':[\
    {\
      'name':'NeoPixel',\
      'params':'default'\
    }\
  ]\
}"
winniiew commented 3 years ago

Fault! Cause: HARDFAULT Fault during recording: No Line: 117 File: Neopixel.cpp Failures since upload: 13 Initialized Serial!

[Device] deserializeJson() failed: IncompleteInput [Device] Config: Device Name : Device Instance Number : 1 Device Type : Node Interval : 1000 [Device] Modules:

Setup Complete

lukegoertzen commented 3 years ago

Was a different config used for the case the caused the fault? It looks like a config that was only partially parsed, which resulted in no Neopixel being instantiated, trying to command it in that case causes a segfault.

winniiew commented 3 years ago

Was a different config used for the case the caused the fault? It looks like a config that was only partially parsed, which resulted in no Neopixel being instantiated, trying to command it in that case causes a segfault.

I used played around with different sketches with Bryson and that was the last sketch file I used which had the neopixel flashing green but no other color

winniiew commented 3 years ago

Initialized Serial!

[Device] deserializeJson() failed: InvalidInput [Device] Config: Device Name : Device Instance Number : 1 Device Type : Node Interval : 1000 [Device] Modules:

Setup Complete

lucasballr commented 3 years ago

Seems like it was unable to finish setting up the modules. You might want to alter the config.h to see if anything fixes it.

winniiew commented 3 years ago

Tested it w/o Hypnos board

Fault! Cause: HARDFAULT Fault during recording: No Line: 117 File: Neopixel.cpp Failures since upload: 13 Initialized Serial!

[Device] deserializeJson() failed: InvalidInput [Device] Config: Device Name : Device Instance Number : 1 Device Type : Node Interval : 1000 [Device] Modules:

Setup Complete

lucasballr commented 3 years ago

Could you post the config.h file?

winniiew commented 3 years ago

Updated config.h

"{\
 'general':\
 {\
    'name':'Device',\
    'instance':1,\
    'interval':500\
  },\
  'components':[\
    {\
      'name':'Digital',\
      'params':'default'\
    },\
    {\
      'name':'Neopixel',\
      'params':'default'\
    }\
  ]\
}"
rcpeene commented 3 years ago

There was a problem with the Config file; missing a comma. BUT upon solving that, the issue returned to the original problem. Featherfault identified a hard fault in Neopixel.cpp, Line 117.

When running the code, the first call to Neopixel::set_color() will run and complete. And then the sketch continues to run in loop(). However, any subsequent Neopixel method calls including set_color(), enable_pin(), print_state(), print_config() will not run and the code will seemingly halt before any of those functions are run.

Could this be that the Neopixel somehow gets uninitialized after its use? I don't see any other possible reasons the code would halt but only when Neopixel methods are called.

lukegoertzen commented 3 years ago

I mentioned it in one of the meetings, but getNeopixel(Feather) (and similar functions) might warrant investigation. Those functions look a bit suspicious to me and are one of the changes introduced in v3, which might explain regular hanging being seen in v3. The implementation is: Loom::Neopixel getNeopixel(Loom::Manager feather) {return *(feather.get<Loom::Neopixel>());} I would expect either a reference or pointer to be returned here (or ideally just use feather.get() directly to avoid duplicate functions). Could be wrong there though, especially if you are seeing the same behavior switching how the Neopixel is accessed. I don't have Neopixels on hand, but switching in feather.get<X>() in the OLED example fixed hard faults. Presumably something to do with shallow copies of the modules being returned in the getX(Feather) functions.

winniiew commented 3 years ago

updated sketch

///////////////////////////////////////////////////////////////////////////////

// This is simple example that is used to change the color of a 
// Neopixel to red, yellow, and green with a 2 second delay for each color

// This was wired through the A2 pin

///////////////////////////////////////////////////////////////////////////////

#include <Loom.h>

// Include configuration
const char* json_config = 
#include "config.h"
;

// In Tools menu, set:
// Internet  > Disabled
// Sensors   > Enabled
// Radios    > Disabled
// Actuators > Enabled
// Max       > Disabled

using namespace Loom;

Loom::Manager Feather{};

void setup() 
{ 

  pinMode(5, OUTPUT);
  digitalWrite(5, LOW); // Sets pin 5, the pin with the 3.3V rail, to output and enables the rail
  pinMode(6, OUTPUT);
  digitalWrite(6, HIGH); // Sets pin 6, the pin with the 5V rail, to output and enables the rail

Feather.begin_serial(true);
Feather.parse_config(json_config);
Feather.print_config();

  LPrintln("\n ** Setup Complete ** ");
}

void loop() 
{

  //Neopixel->set_Color(2, 0, 200, 0, 0);     // Sets color to red
  Feather.get<Loom::Neopixel>()->set_color(2, 0, 200, 0, 0);
  delay(2000);

  //Neopixel->set_Color(2, 0, 200, 200, 0);   // Sets color to yellow
  Feather.get<Loom::Neopixel>()->set_color(2, 0, 200, 200, 0);
  delay(2000);

  //Neopixel->set_Color(2, 0, 0, 200, 0);     // Sets color to green
  Feather.get<Loom::Neopixel>()->set_color(2, 0, 0, 200, 0);
  delay(2000);

  Feather.measure();
  Feather.package();
  Feather.display_data();
  Feather.pause();
}