Metro M4 Airlift Lite won't boot Arduino program

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
bgoolsby
 
Posts: 2
Joined: Wed Jan 25, 2012 2:37 pm

Metro M4 Airlift Lite won't boot Arduino program

Post by bgoolsby »

How can I make the Metro M4 boot into an Arduino program on power-up? I don't want to use CircuitPython. My programs work when I compile and download using the Arduino IDE, but when I simply plug in a 5V micro-USB power supply the program does not run.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Metro M4 Airlift Lite won't boot Arduino program

Post by mikeysklar »

Can you post a program you are running on the Arduino side? It might be waiting for a serial console. Several of the Adafruit examples use that.

User avatar
bgoolsby
 
Posts: 2
Joined: Wed Jan 25, 2012 2:37 pm

Re: Metro M4 Airlift Lite won't boot Arduino program

Post by bgoolsby »

Here is the code. It does wait for Serial to open - I will delete that part tonight and try it.

Code: Select all

// 10/18/22 - Working.  Adafruit IO feed is "analog" and dashboard is "Analog in".
// 10/28 - Added BME280 to send humidity.  Using Adafruit library example bme280test.ino.
// 10/30 - Added separate temp and humidity feeds.  This works and feeds to Dashboard
//   Crawlspace.  Works when compiled and downloaded from Arduino, but does not work
//   when plugged into a 5V PS.

// Adafruit IO Analog In Example
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-analog-input
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.

/********************* Adafruit IO Configuration ****************************/
// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ Example Starts Here *******************************/

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

Adafruit_BME280 bme; // I2C mode


// analog pin 0
#define PHOTOCELL_PIN A0

// feed states
float new_h = 0;
float last_h    = -1;
float new_t = 0;
float last_t    = -1;

// set up the feeds
AdafruitIO_Feed *feed_temp  = io.feed("cs_temp");
AdafruitIO_Feed *feed_humid = io.feed("cs_humid");

void setup() {
	pinMode(LED_BUILTIN, OUTPUT); //the LED marked "L"
	// start the serial connection
	Serial.begin(115200);

	// wait for serial monitor to open
	while(! Serial);

	// connect to io.adafruit.com
	Serial.print("Connecting to Adafruit IO");
	io.connect();

	// wait for a connection
	while(io.status() < AIO_CONNECTED) {
		Serial.println(io.statusText());
		digitalWrite(LED_BUILTIN, HIGH);	 // turn the LED on (HIGH is the voltage level)
		delay(250);											 // wait for a second
		digitalWrite(LED_BUILTIN, LOW);		// turn the LED off by making the voltage LOW
		delay(250); 
	}

	// we are connected
	Serial.println();
	Serial.println(io.statusText());

	// BME280 setup - default settings
	unsigned status = bme.begin();  
	// You can also pass in a Wire library object like &Wire2
	// status = bme.begin(0x76, &Wire2)
	if (!status) {
		Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
		Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
		Serial.print("		ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
		Serial.print("		ID of 0x56-0x58 represents a BMP 280,\n");
		Serial.print("		ID of 0x60 represents a BME 280.\n");
		Serial.print("		ID of 0x61 represents a BME 680.\n");
		while (1) delay(1000);
	}
}


void loop() {
	// io.run(); is required for all sketches.
	// it should always be present at the top of your loop
	// function. it keeps the client connected to
	// io.adafruit.com, and processes any incoming data.
	io.run();

	float h = bme.readHumidity();
	h = float(int(h*2.0-0.5)) / 2.0; //round to 1/2 percent
	new_h = h;

	float t = bme.readTemperature();
	t = t*1.8 + 32; // to F
	t = float(int(t*2.0-0.5)) / 2.0; //round to 1/2 degree
	new_t = t;
	
	if(new_h != last_h) {
		// save the new_h state to the analog feed
		Serial.print("Sending H ->  ");
		Serial.print(new_h);
		Serial.println(" %");
		feed_humid->save(new_h);
	}
	if(new_t != last_t) {
		// save the new_t state to the analog feed
		Serial.print("Sending T ->  ");
		Serial.print(new_t);
		Serial.println(" deg");
		feed_temp->save(new_t);
	}

	// save last state
	last_h = new_h;
	last_t = new_t;

	// wait - free IO account limits updates to 30/minute
	// 2 feeds count as 2 separate updates
	delay(4000);

}


User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Metro M4 Airlift Lite won't boot Arduino program

Post by mikeysklar »

Code: Select all

 	// wait for serial monitor to open
	while(! Serial);
This is pretty common. As you suggest comment it out or run with the a serial console monitor open.

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”