This commit is contained in:
unknown 2024-10-19 05:05:34 +03:00
parent 62f1861de0
commit e6ab6ef45f
2 changed files with 126 additions and 12 deletions

77
README.md Normal file
View File

@ -0,0 +1,77 @@
# Arduino CLI Installation Instructions
## Windows
To install Arduino CLI on Windows using Scoop:
```
scoop install arduino-cli
```
## Linux
To install Arduino CLI on Linux:
```
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
```
## Usage
After installation, you can use Arduino CLI to compile and upload sketches to your Arduino board. For example:
```
arduino-cli compile --fqbn arduino:avr:nano:cpu=atmega328old your_sketch.ino
arduino-cli upload -p COMx --fqbn arduino:avr:nano:cpu=atmega328old your_sketch.ino
```
Replace `COMx` with the appropriate port for your Arduino board (e.g., COM20).
# Project Goal
The goal of this project is to create a system that generates and applies stimulation patterns based on MNIST handwritten digits to a special sample of nano fibers. These nano fibers act as a reservoir, essentially functioning as a small "mind" or computing system. This setup aims to explore the potential of reservoir computing using nano fibers for pattern recognition and information processing.
The project workflow is as follows:
1. Generate a stimulation pattern from MNIST data (gen_stimulat.py)
2. Upload this pattern to an Arduino board (using Arduino CLI)
3. The Arduino applies the stimulation pattern to the nano fiber sample (apply_stimulation.ino)
4. Receive and decode the response data from the nano fiber reservoir (decode_serial_digit.py)
5. Visualize the received data to interpret the reservoir's response (visualize_digit.py)
This setup allows for experimenting with how nano fiber reservoirs can process and potentially recognize complex patterns like handwritten digits, exploring the intersection of materials science and neuromorphic computing.
# Python Scripts
This project includes several Python scripts for working with MNIST digit data and Arduino communication. Here's a brief overview of each script:
## decode_serial_digit.py
This script reads data from a serial port (default: COM20), expecting to receive response values from the nano fiber reservoir after stimulation. It then plots the received data using matplotlib.
Usage:
```
python decode_serial_digit.py
```
## gen_stimulat.py
This script generates a stimulation pattern from the MNIST dataset. It reads the training images and labels, selects the first occurrence of the digit '9', and converts its pixel values to a stimulation pattern. The pattern is then written to a C header file (stimulation_pattern.h) for use with Arduino.
Usage:
```
python gen_stimulat.py
```
## list_all_nines.py
This script reads the MNIST training labels and identifies all occurrences of the digit '9'. It prints the total count of '9's in the training set and the first 10 indices where '9' appears.
Usage:
```
python list_all_nines.py
```
## visualize_digit.py
This script provides a function to visualize a digit pattern using ASCII characters. It can be used to visualize both input stimulation patterns and the reservoir's response.
Usage:
```
python visualize_digit.py
```
These scripts work together to process MNIST data, generate stimulation patterns, and visualize the results of the nano fiber reservoir's computations. They are designed to be used in conjunction with the Arduino sketch for controlling the stimulation of the nano fiber sample.

View File

@ -4,12 +4,20 @@
const bool DEBUG = true; // Set to true to enable serial output const bool DEBUG = true; // Set to true to enable serial output
const bool USE_DIGITAL = true; // Set to false to use analog output const bool USE_DIGITAL = true; // Set to false to use analog output
const int stimulationPin = 5; // PWM-capable pin const int stimulationPin = 5; // PWM-capable pin
const unsigned long delayBetweenStimulations = 1000; // microseconds (1ms delay for more stable serial transmission) const int buttonPin = 2; // Digital pin for button input
const unsigned long delayBetweenEpochs = 1000; // microseconds (1ms delay for more stable serial transmission)
const int threshold = 50; // Threshold for converting analog to digital const int threshold = 50; // Threshold for converting analog to digital
const unsigned long debounceDelay = 50; // Debounce time in milliseconds
int lastButtonState = HIGH; // Assuming a pull-up resistor is used
unsigned long lastDebounceTime = 0;
void setup() { void setup() {
pinMode(stimulationPin, OUTPUT); pinMode(stimulationPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
if (DEBUG) {
Serial.begin(115200); // Increased baud rate for faster output Serial.begin(115200); // Increased baud rate for faster output
}
} }
// Function to convert analog value to digital // Function to convert analog value to digital
@ -26,21 +34,50 @@ void writeOutput(uint8_t value) {
} }
} }
void loop() { // Function to send one complete epoch
void sendEpoch() {
unsigned long startTime = micros();
for (uint16_t i = 0; i < PATTERN_SIZE; i++) { for (uint16_t i = 0; i < PATTERN_SIZE; i++) {
uint8_t stimulationValue = pgm_read_byte(&stimulation_pattern[i]); uint8_t epochValue = pgm_read_byte(&stimulation_pattern[i]);
writeOutput(stimulationValue); writeOutput(epochValue);
// Print the value based on the mode // Print the value based on the mode, only if DEBUG is true
if (DEBUG) {
if (USE_DIGITAL) { if (USE_DIGITAL) {
Serial.println(analogToDigital(stimulationValue) ? 255 : 0); Serial.println(analogToDigital(epochValue) ? 255 : 0);
} else { } else {
Serial.println(stimulationValue); Serial.println(epochValue);
}
} }
delayMicroseconds(delayBetweenStimulations); delayMicroseconds(delayBetweenEpochs);
} }
// Remove the long delay at the end to continuously send data if (DEBUG) {
unsigned long endTime = micros();
Serial.print("Epoch complete. Duration (ms): ");
Serial.println((endTime - startTime) / 1000.0);
}
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading == LOW) { // Button is pressed (assuming pull-up resistor)
sendEpoch();
// Wait for button release
while (digitalRead(buttonPin) == LOW) {
delay(10);
}
}
}
lastButtonState = reading;
} }