I’m using my new particle Electron to monitor the temperature in a car and alert me when the temp gets too high…
I am using a control everything MCP9808 and i2c shield. At first I tried using the CLI, I could open it and log in, but as soon as I said yes to “do you want to use this electron?” the CLI would close. I couldn’t hit prtscreen fast enough to catch the error message.
So I tried OTA firmware push. The first time I flashed it it worked! unfortunately the program only has a 500 delay so it repeats rapidly. I was debugging for a while before finding out that console.particle.io was crashing and not refreshing on windows edge browser. when I pulled up the console on my phone I saw the published temperatures… but this took ten mins that apparently the thing was happily firing away…
So I went to modify the code to slow it down to 10000 delay, trying to only get a reading every second or so. I tried five times or so But every time the flash would fail. I can’t get slower firmware on it, and every time i power it up it starts firing off temps every second.
frustrating, probably should have started with a photon so at least data wouldn’t be a factor.
Code i’m attempting to flash:
// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// MCP9808
// This code is designed to work with the MCP9808_I2CS I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Temperature?sku=MCP9808_I2CS#tabs-0-product_tabset-2
#include <application.h>
#include <spark_wiring_i2c.h>
// MCP9808 I2C address is 0x18(24)
#define Addr 0x18
double cTemp = 0.0, fTemp = 0.0;
void setup()
{
// Set variable
Particle.variable("i2cdevice", "MCP9808");
Particle.variable("cTemp", cTemp);
// Initialise I2C communication as MASTER
Wire.begin();
// Initialise Serial Communication, set baud rate = 9600
Serial.begin(9600);
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select configuration register
Wire.write(0x01);
// Continuous conversion mode, Power-up default
Wire.write(0x00);
Wire.write(0x00);
// Stop I2C Transmission
Wire.endTransmission();
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select resolution rgister
Wire.write(0x08);
// Resolution = +0.0625 / C
Wire.write(0x03);
// Stop I2C Transmission
Wire.endTransmission();
delay(300);
}
void loop()
{
unsigned int data[2];
// Starts I2C communication
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x05);
// Stop I2C transmission
Wire.endTransmission();
// Request 2 bytes of data
Wire.requestFrom(Addr, 2);
// Read 2 bytes of data
// temp msb, temp lsb
if(Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
delay(300);
// Convert the data to 13-bits
int temp = ((data[0] & 0x1F) * 256 + data[1]);
if(temp > 4095)
{
temp -= 8192;
}
cTemp = temp * 0.0625;
fTemp = cTemp * 1.8 + 32;
// Output data to dashboard
// Particle.publish("Temperature in Celsius : ", String(cTemp));
Particle.publish("Temperature in Fahrenheit : ", String(fTemp));
delay(10000);
}
In your current app in the IDE, use the cloud icon with the down arrow. Compile and download the firmware to your computer. Locate it on your system. Open up a command window or power shell window. It looks like you have the Particle CLI working?
If the firmware downloaded is say “program.bin”, then when you are in that directory you are ready to try. The name will likely be different.
On the Electron hold the “Setup” button for a couple seconds. It should start flashing “Blue”. It is ready to be flashed over USB serial.
C:\SomeDirectory> particle flash --serial program.bin
! PROTIP: Hold the SETUP button on your device until it blinks blue!
? Press ENTER when your device is blinking BLUE
If all goes well, the new program should be on your Electron. This will save consuming data over OTA.
Using Windows? I think there is a two step process to have the CLI work in Windows. You need to install the CLI, but there are separate drivers to get things working over USB/serial. Did you do this step? Installing the CLI – specifically “Installing the Particle Driver”. Windows Driver. That might be why the CLI is suddenly exiting.
Other things to check? Are you logged in? Can you see the Electron in the list.
> particle login
> particle list
Are you able to put the Electron into the flashing blue mode?
I installed Node.js. when i click that driver link it tells me drivers are not needed with windows 10…BUT i can use that software to remove the drivers if I like.
If the drivers are in place you can try to use DFU mode to flash. Press RESET and MODE/SETUP. Release RESET but keep holding MODE/SETUP. The light will be a flashing yellow this time.
That happened to me. I was using Speckcode and just assumed it was flashing over USB, but it was actually going through the air and I burned thru my free meg in a couple of days.
Speckcode now lets you flash over USB.
If you were on a Mac I’d say use Speckcode, well worth the dollar a month.
Maybe. Try this first, maybe some things are little out of date?
$ npm update -g particle-cli
If that doesn't help, I would uninstall everything and instead of installing node.js and then partcile-cli, start with the Windows CLI installer which will install node.js for you.
You can use the official Particle Windows CLI Installer to automatically install node.js, the particle-cli, and dfu-util instead of using the manual installation instructions below.
The first time I flashed to my particle it took the firmware fine… But now The IDE cannot change that code by any means I’ve tried. When I click flash OTA it claims ready but the breathing blue never goes magenta and the program doesn’t change… The CLI is complaining about billing so it will not connect to the electron. And I can’t figure out the DFU, I keep getting errors trying to flash the firmware under DFU. I don’t know how to move forward with this thing and i’m wreaking my data with all the failed OTA firmware attempts.