-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTM32_Inference_Arduino.ino
More file actions
64 lines (51 loc) · 1.67 KB
/
STM32_Inference_Arduino.ino
File metadata and controls
64 lines (51 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// UART ///////////////////////////////////////////////////////////////////////
#define MY_STM32C0116_DK // using the dev board?
#ifdef MY_STM32C0116_DK
const int _RX = PA10_R;
const int _TX = PA9_R;
#else // custom circuit
const int _TX = PA14;
const int _RX = PA13;
#endif
// I2C ////////////////////////////////////////////////////////////////////////
const int _SDA = PB7;
const int _SCL = PB6;
// LED ////////////////////////////////////////////////////////////////////////
#ifdef MY_STM32C0116_DK
// TODO: change pin: LED and SCL are on the same pin!
const int led = PB6;
static bool LED_ON = LOW; // inverted logic
#else // custom circuit
const int led = PA8; // TODO: confirm! (can also be PA9_R or PA11)
static bool LED_ON = HIGH;
#endif
#include <EloquentTinyML.h>
#include <eloquent_tinyml/tensorflow.h>
// copy the printed code from tinymlgen into this file
#include "SineNN.h"
void setup() {
Serial.begin(115200);
while (!sineNN.begin()) {
Serial.print("Error in NN initialization: ");
Serial.println(sineNN.getErrorMessage());
}
}
void loop() {
for (int i = 0; i < 20; i++) {
// pick x from 0 to PI
float x = 3.14f * i / 20.0f;
// even if the input vector is made of a single value
// you ALWAYS need to create an array
float input[1] = { x };
float y_true = sin(x);
// to run the network, call `predict()`
float y_pred = sineNN.predict(input);
Serial.print("sin(");
Serial.print(x);
Serial.print(") = ");
Serial.print(y_true);
Serial.print("\t predicted: ");
Serial.println(y_pred);
delay(1000);
}
}