Smart Bathroom Project Error [Solved]

Hi friends,

I’m following the tutorial here (https://learn.adafruit.com/smart-bathroom-app/web-app) for the smart bathroom light. I have my photon connected to the app/internet but I’m getting the following errors:

[code]smartbathroom.cpp:15:3: error: stray ‘\342’ in program
int doorStatus = 0;
^

smartbathroom.cpp:15:3: error: stray ‘\200’ in program
smartbathroom.cpp:15:3: error: stray ‘\234’ in program
smartbathroom.cpp:15:31: warning: missing terminating " character [enabled by default]
int doorStatus = 0;
^
smartbathroom.cpp:15:3: error: missing terminating " character
int doorStatus = 0;
^

smartbathroom.cpp: In function ‘void setup()’:
smartbathroom.cpp:15:3: warning: ‘Spark’ is deprecated (declared at …/wiring/inc/spark_wiring_cloud.h:357): Spark is now Particle. [-Wdeprecated-declarations]
smartbathroom.cpp:16:1: error: expected ‘)’ before ‘}’ token

^

smartbathroom.cpp:16:1: error: expected ‘;’ before ‘}’ token
smartbathroom.cpp: In function ‘void loop()’:
smartbathroom.cpp:6:21: error: expected ‘)’ before ‘;’ token
void doorClosed();
^

smartbathroom.cpp:20:28: note: in expansion of macro 'sensorPin’
strip.begin();
^
smartbathroom.cpp:20:37: error: expected primary-expression before ‘)’ token
strip.begin();
^

smartbathroom.cpp:20:37: error: expected ‘;’ before ‘)’ token
smartbathroom.cpp:21:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
strip.show(); // Initialize all pixels to ‘off’
^
make[1]: *** […/build/target/user/platform-6smartbathroom.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.[/code]

The Photon is something entirely new to me so I don’t know where to begin. The only thing I could imagine is that the original code was scripted for the Spark not the Photon, but I don’t know what changes I need to make.

This is the code I’m uploading via the web IDE:

[code]#include “neopixel/neopixel.h”

#define PIXEL_PIN D2
#define PIXEL_COUNT 12
#define PIXEL_TYPE WS2812B
#define sensorPin D1;
int sensorData = 0;
int doorStatus = 0;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off’
Spark.variable(“doorStatus", &doorStatus, INT);
}

void loop() {

sensorData = digitalRead(sensorPin);
if (sensorData = 1)
{
doorStatus = 1;
doorClosed();
}
else
{
doorStatus = 0;
doorOpen();
}
}

void doorOpen() {
strip.setPixelColor(0, 0, 0, 0);
strip.setPixelColor(1, 0, 0, 0);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 0, 0, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.setPixelColor(12, 0, 0, 0);
strip.setPixelColor(13, 0, 0, 0);
strip.setPixelColor(14, 0, 0, 0);
strip.setPixelColor(15, 0, 0, 0);
strip.setPixelColor(16, 0, 0, 0);
strip.setPixelColor(17, 0, 0, 0);
strip.setPixelColor(18, 0, 0, 0);
strip.setPixelColor(19, 0, 0, 0);
strip.setPixelColor(20, 0, 0, 0);
strip.setPixelColor(21, 0, 0, 0);
strip.setPixelColor(22, 27, 167, 46);
strip.setPixelColor(23, 0, 0, 0);
strip.setPixelColor(24, 0, 0, 0);
strip.setPixelColor(25, 0, 0, 0);
strip.setPixelColor(26, 0, 0, 0);
strip.setPixelColor(27, 0, 0, 0);
strip.setPixelColor(28, 0, 0, 0);
strip.setPixelColor(29, 27, 167, 46);
strip.setPixelColor(30, 0, 0, 0);
strip.setPixelColor(31, 0, 0, 0);
strip.setPixelColor(32, 0, 0, 0);
strip.setPixelColor(33, 0, 0, 0);
strip.setPixelColor(34, 0, 0, 0);
strip.setPixelColor(35, 0, 0, 0);
strip.setPixelColor(36, 27, 167, 46);
strip.setPixelColor(37, 0, 0, 0);
strip.setPixelColor(38, 0, 0, 0);
strip.setPixelColor(39, 0, 0, 0);
strip.setPixelColor(40, 0, 0, 0);
strip.setPixelColor(41, 27, 167, 46);
strip.setPixelColor(42, 0, 0, 0);
strip.setPixelColor(43, 27, 167, 46);
strip.setPixelColor(44, 0, 0, 0);
strip.setPixelColor(45, 0, 0, 0);
strip.setPixelColor(46, 0, 0, 0);
strip.setPixelColor(47, 0, 0, 0);
strip.setPixelColor(48, 0, 0, 0);
strip.setPixelColor(49, 0, 0, 0);
strip.setPixelColor(50, 27, 167, 46);
strip.setPixelColor(51, 0, 0, 0);
strip.setPixelColor(52, 0, 0, 0);
strip.setPixelColor(53, 0, 0, 0);
strip.setPixelColor(54, 0, 0, 0);
strip.setPixelColor(55, 0, 0, 0);
strip.setPixelColor(56, 0, 0, 0);
strip.setPixelColor(57, 0, 0, 0);
strip.setPixelColor(58, 0, 0, 0);
strip.setPixelColor(59, 0, 0, 0);
strip.setPixelColor(60, 0, 0, 0);
strip.setPixelColor(61, 0, 0, 0);
strip.setPixelColor(62, 0, 0, 0);
strip.setPixelColor(63, 0, 0, 0);
strip.setBrightness(30);
strip.show();
}

void doorClosed() {
strip.setPixelColor(0, 0, 0, 0);
strip.setPixelColor(1, 0, 0, 0);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.setPixelColor(5, 0, 0, 0);
strip.setPixelColor(6, 0, 0, 0);
strip.setPixelColor(7, 0, 0, 0);
strip.setPixelColor(8, 0, 0, 0);
strip.setPixelColor(9, 185, 30, 0);
strip.setPixelColor(10, 0, 0, 0);
strip.setPixelColor(11, 0, 0, 0);
strip.setPixelColor(12, 0, 0, 0);
strip.setPixelColor(13, 0, 0, 0);
strip.setPixelColor(14, 185, 30, 0);
strip.setPixelColor(15, 0, 0, 0);
strip.setPixelColor(16, 0, 0, 0);
strip.setPixelColor(17, 0, 0, 0);
strip.setPixelColor(18, 185, 30, 0);
strip.setPixelColor(19, 0, 0, 0);
strip.setPixelColor(20, 0, 0, 0);
strip.setPixelColor(21, 185, 30, 0);
strip.setPixelColor(22, 0, 0, 0);
strip.setPixelColor(23, 0, 0, 0);
strip.setPixelColor(24, 0, 0, 0);
strip.setPixelColor(25, 0, 0, 0);
strip.setPixelColor(26, 0, 0, 0);
strip.setPixelColor(27, 185, 30, 0);
strip.setPixelColor(28, 185, 30, 0);
strip.setPixelColor(29, 0, 0, 0);
strip.setPixelColor(30, 0, 0, 0);
strip.setPixelColor(31, 0, 0, 0);
strip.setPixelColor(32, 0, 0, 0);
strip.setPixelColor(33, 0, 0, 0);
strip.setPixelColor(34, 0, 0, 0);
strip.setPixelColor(35, 185, 30, 0);
strip.setPixelColor(36, 185, 30, 0);
strip.setPixelColor(37, 0, 0, 0);
strip.setPixelColor(38, 0, 0, 0);
strip.setPixelColor(39, 0, 0, 0);
strip.setPixelColor(40, 0, 0, 0);
strip.setPixelColor(41, 0, 0, 0);
strip.setPixelColor(42, 185, 30, 0);
strip.setPixelColor(43, 0, 0, 0);
strip.setPixelColor(44, 0, 0, 0);
strip.setPixelColor(45, 185, 30, 0);
strip.setPixelColor(46, 0, 0, 0);
strip.setPixelColor(47, 0, 0, 0);
strip.setPixelColor(48, 0, 0, 0);
strip.setPixelColor(49, 185, 30, 0);
strip.setPixelColor(50, 0, 0, 0);
strip.setPixelColor(51, 0, 0, 0);
strip.setPixelColor(52, 0, 0, 0);
strip.setPixelColor(53, 0, 0, 0);
strip.setPixelColor(54, 185, 30, 0);
strip.setPixelColor(55, 0, 0, 0);
strip.setPixelColor(56, 0, 0, 0);
strip.setPixelColor(57, 0, 0, 0);
strip.setPixelColor(58, 0, 0, 0);
strip.setPixelColor(59, 0, 0, 0);
strip.setPixelColor(60, 0, 0, 0);
strip.setPixelColor(61, 0, 0, 0);
strip.setPixelColor(62, 0, 0, 0);
strip.setPixelColor(63, 0, 0, 0);
strip.setBrightness(30);
strip.show();
}

[/code]

Any help is greatly appreciated!
Josh

I think you have some unprintable codes in your source (possibly caused when you cut/paste) - the \342, \200 \234 look like errors where the compiler barfs at weird characters.

If you have a hex editor you may be able to find them.

Ok, I pasted the code with a PC instead and solved the character issue, but I still get the following errors:

smartbathroom.cpp: In function 'void loop()':

   
 smartbathroom.cpp:6:21: error: expected ')' before ';' token
 void doorClosed();
                     ^
   
smartbathroom.cpp:20:28: note: in expansion of macro 'sensorPin'
   strip.begin();
                            ^

   
 smartbathroom.cpp:20:37: error: expected primary-expression before ')' token
   strip.begin();
                                     ^
   
smartbathroom.cpp:20:37: error: expected ';' before ')' token
smartbathroom.cpp:21:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   strip.show(); // Initialize all pixels to 'off'
                     ^
make[1]: *** [../build/target/user/platform-6smartbathroom.o] Error 1
make: *** [user] Error 2

     Error: Could not compile. Please review your code.

Take the setup and loop routines and place them at the bottom of your code - there does not appear to be a forward reference to the routines used in loop - this is a quick and dirty fix - let me know how your go!

Also - remove the ; at the end of the define sensorpin - you musnt have a semi colon at the end of a define!

ALso just noticed - the if statements are incorrect tests for equality - for equality you need == (not a single =)

Removing that damn semicolon solved the whole thing! Amazing what one tiny blip can cause.

Thanks for your help Stan!

I did have a look at the project (from your link) and to my eye there are a few issues with the code as posted;

The semi colon at the end of the define is one issue (as you have found out).

The test for equality using just a single = sign instead of 2 is another.

I have put some feedback to adafruit.

As an FYI - you are using the adafruit neopixel library - you may also wish to look at the fastled library which works great with neopixels!

Stan

Hey Stan! Thanks for the response! I’m now stuck in a pickle where the code flashes properly, but I get no response via the NeoPixels. I also switched over to include the FastLED library instead, but I still don’t get any feedback.

Here is my updated code:

// This #include statement was automatically added by the Particle IDE.
#include "FastLED/FastLED.h"

#include "neopixel/neopixel.h"

#define PIXEL_PIN D2
#define PIXEL_COUNT 12
#define PIXEL_TYPE WS2812B
#define sensorPin D1
int sensorData = 0;
int doorStatus = 0;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);


void doorOpen() {
    strip.setPixelColor(0, 255, 0, 0);
    strip.setPixelColor(1, 255, 0, 0);
    strip.setPixelColor(2, 255, 0, 0);
    strip.setPixelColor(3, 255, 0, 0);
    strip.setPixelColor(4, 255, 0, 0);
    strip.setPixelColor(5, 255, 0, 0);
    strip.setPixelColor(6, 255, 0, 0);
    strip.setPixelColor(7, 255, 0, 0);
    strip.setPixelColor(8, 255, 0, 0);
    strip.setPixelColor(9, 255, 0, 0);
    strip.setPixelColor(10, 255, 0, 0);
    strip.setPixelColor(11, 255, 0, 0);
    strip.setPixelColor(12, 255, 0, 0);
    strip.setBrightness(100);
    strip.show();
}

void doorClosed() {
    strip.setPixelColor(0, 255, 0, 0);
    strip.setPixelColor(1, 255, 0, 0);
    strip.setPixelColor(2, 255, 0, 0);
    strip.setPixelColor(3, 255, 0, 0);
    strip.setPixelColor(4, 255, 0, 0);
    strip.setPixelColor(5, 255, 0, 0);
    strip.setPixelColor(6, 255, 0, 0);
    strip.setPixelColor(7, 255, 0, 0);
    strip.setPixelColor(8, 255, 0, 0);
    strip.setPixelColor(9, 255, 0, 0);
    strip.setPixelColor(10, 255, 0, 0);
    strip.setPixelColor(11, 255, 0, 0);
    strip.setPixelColor(12, 255, 0, 0);
    strip.setBrightness(100);
    strip.show();
}

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
 Particle.variable("doorStatus", &doorStatus, INT);
}

void loop() {

  sensorData == digitalRead(sensorPin);
  if (sensorData == 1)
  {
    doorStatus == 1;
    doorClosed();
  }
  else
  {
    doorStatus == 0;
    doorOpen();
  }
}

The assignment operator is a single = - you have two (==)

Stan

Hi Stan,

Ok, I think I understand what I need to do, but I’m still having the issue of it not showing anything on the LEDs.

Did I adjust the correct = sign? I also changed the individual coloring to colorWipe.

// This #include statement was automatically added by the Particle IDE.
#include "FastLED/FastLED.h"

#include "neopixel/neopixel.h"

#define PIXEL_PIN D2
#define PIXEL_COUNT 12
#define PIXEL_TYPE WS2812B
#define sensorPin D1
int sensorData = 0;
int doorStatus = 0;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
 Spark.variable("doorStatus", &doorStatus, INT);
}

void loop() {

  sensorData = digitalRead(sensorPin);
  if (sensorData == 1)
  {
    doorStatus = 1;
    doorClosed();
  }
  else
  {
    doorStatus = 0;
    doorOpen();
  }
}


void doorOpen() {
    colorWipe(strip.Color(255, 0, 0), 50); // Red
    strip.show();
}

void doorClosed() {
    colorWipe(strip.Color(0, 255, 0), 50); // Green
    strip.show();
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

Now you are getting into debugging…

Firstly - take out the #include of fasted.h *It doesn’t do anything) - To use fastled instead of neopixel to drive neopixels needs a lot more than a include.

  1. Are your pixels working? - Are they wired up ok - download from adafruit a simple example and test them.
  2. Have you looked at the particle (spark) variable - is it reflecting the button state?

Stan

Yup, these LEDs were running fine via an Adafruit Flora. I have the VBAT connected to the PWR on the NeoPixels. Should I use the 3V3 instead? The Particle Variable seems to be switching back and forth between 0 and 1 even when the reed switch is open.

@joshstern, VBAT is an INPUT for a back up battery. You should use Vin which will supply approx. 5v to the neopixels.:wink:

Woo! We have light! Now, I have an issue where the LED’s are cycling through red and green as if someone is opening and closing the door rapidly. Should the reed switch be connected to the D1 port and the 3V3 or D1 and GND?

You need to set D1 (in setup) to input.

@peekay123 can you assist me here - This will set the pin with a pulldown? resister. You would wire the switch between 3.3 and D1. When the switch is closed 3.3v will flow to D1 setting it HIGH. When the switch is open the internal pulldown will pull D1 to a LOW value.

Help me @peekay123 - you are my only hope :slight_smile:

I have #define sensorPin D1 in my sketch. Will wait to see what @peekay123 says.

You have to in setup explicitly say what the pin is being used for - see the doco for pinmode here

Hmm, ok, now I’m getting into territory I’m not familiar with. I understand I need to define what the pin is used for, but I’m not sure where I need to add that bit of code or rather what code to use.

If you are in that state, I would suggest you archive your code at the moment and write a simple program that will do the following (if you do this correct you should be able to leave all your hardware in place).

In setup set a pin to input with input pulldown.
In loop check the pin
if high set internal LED on
if low set internal LED off

Get this to work and it will teach you a huge amount.

(You may wish to get a blink example and hack that - I am fairly sure that there is a blink for the photon - all you will be doing is modifying it to set the LED on or Off)

BTW - I am a firm believer in learning by doing - you need to do this yourself - find out how to use the console and log ‘debug’ messages there (lookup serial usage in doc).

Stan

@Stan (aka young padestan) and @joshstern, to use a pin for input or output you first need to set that pin’s mode with pinMode(pin, mode). This needs to be done only once in setup(). Based on the logic:

  if (sensorData == 1)
  {
    doorStatus = 1;
    doorClosed();
  }
  else
  {
    doorStatus = 0;
    doorOpen();
  }

it seems that a door open condition is when sensorData has a value of 1. You can change the statement to be simply if(sensorData) since a) the pin returns a value of HIGH or LOW so anything non-zero acts as a HIGH. The logic says “when sensorPin D1 is low, open the door”. So to do that, the button needs to send a LOW when pushed. This can be done by wiring one side to GND and the other side to pin D1. Then set the pinMode (as @Stan pointed out already) to pinMode(sensorPin, INPUT_PULLUP); which will put a 40K ohm pullup (to 3V3) resistor on pin D1 so when the button is not pushed, a HIGH will be returned. When it is pushed, a LOW will be returned.

You will notice however that as soon as you release the button, the pin will go HIGH and the door will immediately close again! So the logic you need is not complete.

As @Stan pointed out, perhaps walking before running is best here. Also searching the forum for “push button” or “garage door” might give you some ideas. :smiley:

1 Like

Awesome @peekay123 and @Stan! Thanks so much for your help!