Last active
July 3, 2021 17:00
-
-
Save brocksprogramming/d5a1d8195a358b529895d354a7ef7ecb to your computer and use it in GitHub Desktop.
Arduino serial script to be sent over to pythonserialmlgloves
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This software was made in hopes of pioneering machine learning gloves. The main application is for typing on any hard surface without a keyboard. | |
// Copyright (C) 2020 Brock Sterling Lynch | |
/* | |
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, either version 3 of the License, or | |
(at your option) any later version. | |
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 <https://www.gnu.org/licenses/>. | |
You may reach the author of this software at brocksprogramming@gmail.com | |
*/ | |
//HC-06 (RED) | |
#include <math.h> | |
void setup() { | |
// I'm not sure if the baud rate changed, but we'll have to keep it at 9600 to work | |
Serial.begin(9600); | |
// Change to a lower BAUD | |
Serial.print("AT+BAUD1"); | |
} | |
// Smooth the input to eliminate random values from machine learning model | |
int AverageFilter(int aNum) | |
{ | |
float AverageAnalogValue = 0; | |
int MeasurementsToAverage = 16; | |
for(int i = 0; i < MeasurementsToAverage; ++i) | |
{ | |
AverageAnalogValue += analogRead(aNum); | |
delay(1); | |
} | |
AverageAnalogValue /= MeasurementsToAverage; | |
return TakeFraction(.10,AverageAnalogValue); | |
} | |
int TakeFraction(float FractionAmount,int AveragedAnalogValue) | |
{ | |
return round(AveragedAnalogValue * FractionAmount); | |
} | |
void loop() { | |
// It won't work with the I2C while loop for some reason. Perhaps it is getting stuck up on it | |
// 16 BYTES all together | |
// Create a block to synchronize the data | |
// Removed DEC from serial.print, because it was sending over as a 2-byte integer | |
// Appar | |
// Probably counts lowByte at 3 character bytes | |
Serial.print("A"); | |
Serial.print("0"); | |
Serial.print(lowByte(AverageFilter(0))); // Read the local analog signal | |
// Added delay in case there is a conflict from the analog sensors | |
delay(5); | |
Serial.print("A"); | |
Serial.print("1"); | |
Serial.print(lowByte(AverageFilter(1))); // Read the local analog signal | |
delay(5); | |
Serial.print("A"); | |
Serial.print("2"); | |
Serial.print(lowByte(AverageFilter(2))); // Read the local analog signal | |
delay(5); | |
Serial.print("A"); | |
Serial.print("3"); | |
Serial.print(lowByte(AverageFilter(3))); // Read the local analog signal | |
delay(5); | |
Serial.print("A"); | |
Serial.print("4"); | |
Serial.print(lowByte(AverageFilter(4))); | |
Serial.print("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment