Maker.io main logo

Detecting Unstable Electrical Grid with TinyML

21

2022-08-19 | By Alex Miller

License: Attribution Dust / Particle Microcontrollers

Things used in this project:

Hardware components
Particle Argon×1

Software apps and online services
Neuton Tiny ML
Particle Build Web IDE

Story

 

image

Solution

Copy Code
static float* on_dataset_sample(float* inputs)
{
if (neuton_model_set_inputs(inputs) == 0)
{
uint16_t index;
float* outputs;

uint64_t start = micros();
if (neuton_model_run_inference(&index, &outputs) == 0)
{
uint64_t stop = micros();

uint64_t inference_time = stop - start;
if (inference_time > max_time)
max_time = inference_time;
if (inference_time < min_time)
min_time = inference_time;

static uint64_t nInferences = 0;
if (nInferences++ == 0)
{
avg_time = inference_time;
}

else
{
avg_time = (avg_time * nInferences + inference_time) / (nInferences + 1);
}

RGB.control(true);

RGB.color(255, 255, 255); // white

switch (index)
{
case 0:
Particle.publish("Prediction: Stable Grid", String(index));
RGB.color(0, 255, 0);
break;

case 1:
Particle.publish("Prediction: Unstable Grid", String(index));
RGB.color(255, 0, 0);
break;

default:
break;
}

return outputs;
}
}

return NULL;
}
Copy Code
# For Ubuntu
$ sudo apt install libuv1-dev gengetopt
# For macOS
$ brew install libuv gengetopt
Copy Code
$ git clone https://github.com/Neuton-tinyML/dataset-uploader.git
$ cd dataset-uploader
Copy Code
$ make

Once it’s done, you can send the CSV file over USB.

Copy Code
$./uploader -s /dev/ttyACM0 -b 230400 -d /home/vil/Desktop/electric_grid_test.csv

Image

The prediction is printed on the Particle IoT cloud.

Image

Monitoring the stability of the electrical grid helps to reveal “unreliable” energy sources and avoid serious damage. The best strategy for such AI+IoT projects is not only making predictions but also collecting and reporting data in order to improve models for future devices like Particle and make OTA updates easier.

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.