This is the official Arduino library for N2CMU (Neural Network Coprocessing Microcontroller Unit).
Getting Started
To start using n2cmu-arduino
library in your Arduino projects, follow these simple steps:
- Open your Library Manager on Arduino IDE.
- Type
n2cmu-arduino
and click "Install."
Alternatively, you can follow the steps below:
- Download the
n2cmu-arduino
library from the GitHub repository.
- Extract the downloaded archive and rename the folder to
n2cmu-arduino
.
- Move the
n2cmu-arduino
folder to the Arduino libraries directory on your computer.
- Windows:
Documents\Arduino\libraries\
- MacOS:
~/Documents/Arduino/libraries/
- Linux:
~/Arduino/libraries/
- Launch the Arduino IDE.
Example Usage
Below is an example usage of N2CMU Arduino library that demonstrates an example training for NAND gate training and inference.
void setup() {
Serial.begin(9600);
while(!Serial);
Serial.println(F("Co-processor initialized!"));
else {
Serial.println(F("Something went wrong. Halting..."));
while(true);
}
Serial.println(F("CPU Reset!"));
else {
Serial.println(F("Something went wrong. Halting..."));
while(true);
}
Serial.println(F("Initializing neural network..."));
float dataset[][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
float output[][1] = {{1}, {1}, {1}, {0}};
Serial.println(F("Starting network training..."));
if(coprocessor.
train((
float*) dataset, (
float*) output, 4, 1.0f))
Serial.println(F("Training done!"));
else {
Serial.println(F("Something went wrong. Halting..."));
while(true);
}
Serial.println(F("Attempting inferences..."));
for(uint8_t i = 0; i < 4; i++) {
float output[1];
if(coprocessor.
infer(dataset[i], output)) {
Serial.print(F("\t["));
Serial.print(dataset[i][0]);
Serial.print(F(", "));
Serial.print(dataset[i][1]);
Serial.print(F("]: "));
Serial.println(output[0]);
}
else Serial.println(F("Inference attempt failed."));
}
Serial.println(F("Inference done, resetting network."));
}
void loop() {
delay(1000);
}
Class representing the N2CMU device.
Definition: n2cmu.h:47
bool infer(float *input, float *output)
Make inference with the neural network using provided input data.
Definition: n2cmu.cpp:146
void createNetwork(uint8_t inputCount, uint8_t hiddenCount, uint8_t outputCount)
Create a neural network with specified input, hidden, and output neuron counts.
Definition: n2cmu.cpp:104
bool train(float *data, float *output, uint16_t len, float learningRate)
Train the neural network with provided data and output.
Definition: n2cmu.cpp:119
bool cpuReset()
Reset the CPU of the N2CMU device.
Definition: n2cmu.cpp:97
bool begin()
Initialize the N2CMU device.
Definition: n2cmu.cpp:86
void setEpochCount(uint16_t epoch)
Set the epoch count for training.
Definition: n2cmu.cpp:206
void resetNetwork()
Reset the neural network parameters.
Definition: n2cmu.cpp:160
Header file for N2CMU (Neural Network Coprocessing Microcontroller Unit).
PCB Schematic Diagram
License
Copyright (c) 2024 Nathanne Isip
n2cmu-arduino
is distributed under the GNU General Public License v3.0. For further details, refer to the LICENSE file.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.