Basic sketch on Electron not working - [SOLVED] but still puzzled

Hi all, new to Electron and Particle. I’m just trying to get a ‘hello world’ app running and can’t seem to get it working. I’m uploading the code below via USB, which appears to be working. When I use the CLI to open a serial monitor, I can see it working before it connects to the cloud. Then once the on-board status LED starts breathing cyan, the serial port doesn’t read anything.

Also, the LED I’ve specified is not responding and I’ve triple checked the wiring. Am I missing something basic about setting up pins and/or Serial?

int button = D1;
int led = D2;
int prevState = 0;


void setup() {
  pinMode(led, OUTPUT); 
  pinMode(button, INPUT);  
  
  Serial.begin(9600);
  Serial.println("hello");
  
  digitalWrite(led, LOW);
}

void loop() {
  
  int currState = digitalRead(button);
  Serial.println(currState);
  
  if (currState == 0 && prevState == 1) {
      digitalWrite(led, HIGH);
      delay(500);
      digitalWrite(led, LOW);
  }
  
  prevState = currState;
}

You have a pull-up resistor on the button pin?

If not change this:

  pinMode(button, INPUT); 

To this

pinMode(button, INPUT_PULLUP); 

@BulldogLowell good suggestion. I have not wired the button to be a pullup type, however. It is the standard configuration as found here.

Also, that would not explain the serial data not showing up.

I found some lines in an example sketch I used a while back and when I put these at the top everything worked fine. No idea why.

PRODUCT_ID(3109);
PRODUCT_VERSION(1);

With these lines you made your Electron a product of someone else - unless you have created a product and got 3109 as your product number.

Thanks for the explanation, @ScruffR. That is my product number. Still not sure how this helped things, or perhaps along the way I changed some small thing that made a difference. Frustrating not knowing what it was exactly, but with things working now I"m just going to move on…

Since you made the device a product already it’s possible (intended) that only “legitimate” code sticks to prevent someone else from using your product and flash their own non-product code to it.

But to be certain other possible reasons would need to be tested and more details be known how things were done in the past (when setting the product ID) and how exactly you built and flashed and other things.