From 135e6a18a6da28c96ddc25a6c36fd5bb5c0ad847 Mon Sep 17 00:00:00 2001 From: Mac D Date: Tue, 15 Mar 2022 14:34:13 +0100 Subject: [PATCH 01/48] Create branch for next project version --- src/Filter.h | 90 ------------------------ src/FilterTest.cpp | 47 ------------- src/config.h | 18 +++++ src/flexsensorClass.cpp | 37 ---------- src/readFingers.h | 31 -------- src/sensorClass.cpp | 43 +++++++++++ src/{flexsensorClass.h => sensorClass.h} | 18 +++-- src/talkyBoi.h | 10 +-- 8 files changed, 75 insertions(+), 219 deletions(-) delete mode 100644 src/Filter.h delete mode 100644 src/FilterTest.cpp create mode 100644 src/config.h delete mode 100644 src/flexsensorClass.cpp delete mode 100644 src/readFingers.h create mode 100644 src/sensorClass.cpp rename src/{flexsensorClass.h => sensorClass.h} (61%) diff --git a/src/Filter.h b/src/Filter.h deleted file mode 100644 index ef36fbf..0000000 --- a/src/Filter.h +++ /dev/null @@ -1,90 +0,0 @@ -#include -#include -#include "MedianFilter.h" - -// Create median filter objects, once for each sensor -MedianFilter mf0; -MedianFilter mf1; -//MedianFilter mf2; -//MedianFilter mf3; -//MedianFilter mf4; -//MedianFilter mf5; -//MedianFilter mf6; -//MedianFilter mf7; -//MedianFilter mf8; -//MedianFilter mf9; - -float getFilteredAngle(float fingerAngles,int i){ - - //thumbIP_angle, - if (i == 0){ - mf0.addSample(fingerAngles); - float FilterAngle0 = mf0.getMedian(); - return FilterAngle0; - } - - // thumbMCP_angle - else if (i == 1){ - mf1.addSample(fingerAngles); - float FilterAngle1 = mf1.getMedian(); - return FilterAngle1; - } - - /* - // f1PIP_angle - else if (i == 2){ - mf1.addSample(fingerAngles); - float FilterAngle2 = mf1.getMedian(); - return FilterAngle2; - } - - // f1MCP_angle - else if (i == 3){ - mf1.addSample(fingerAngles); - float FilterAngle1 = mf1.getMedian(); - return FilterAngle1; - } - - // f2PIP_angle - else if (i == 4){ - mf1.addSample(fingerAngles); - float FilterAngle1 = mf1.getMedian(); - return FilterAngle1; - } - - // f2MCP_angle - else if (i == 5){ - mf1.addSample(fingerAngles); - float FilterAngle1 = mf1.getMedian(); - return FilterAngle1; - } - - // f3PIP_angle - else if (i == 6){ - mf1.addSample(fingerAngles); - float FilterAngle1 = mf1.getMedian(); - return FilterAngle1; - } - - // f3MCP_angle - else if (i == 7){ - mf1.addSample(fingerAngles); - float FilterAngle1 = mf1.getMedian(); - return FilterAngle1; - } - - // f4PIP_angle - else if (i == 8){ - mf1.addSample(fingerAngles); - float FilterAngle1 = mf1.getMedian(); - return FilterAngle1; - } - - // f4MCP_angle - else if (i == 9){ - mf1.addSample(fingerAngles); - float FilterAngle1 = mf1.getMedian(); - return FilterAngle1; - } - */ -} \ No newline at end of file diff --git a/src/FilterTest.cpp b/src/FilterTest.cpp deleted file mode 100644 index c83c842..0000000 --- a/src/FilterTest.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include "Filter.h" - - -const int flexPin1 = 4; // Pin connected to voltage divider output -const int flexPin2 = 0; // Pin connected to voltage divider output -float fingerAngles[2] = {0,0}; -float fingerAnglesFiltered[2] = {0,0}; -const int sizeList = 2; - -// Change these constants according to your project's design -const float VCC = 5; // voltage at Ardunio 5V line -const float R_DIV = 10000.0; // resistor used to create a voltage divider - -void setup() { - Serial.begin(115200); - pinMode(flexPin1, INPUT); - pinMode(flexPin2, INPUT); -} - - -void loop() { - - // Calculate angle of fingers - int ADCflex0 = analogRead(flexPin1); - int ADCflex1 = analogRead(flexPin2); - - float Vflex0 = ADCflex0 * VCC / 4095.0; //1023.0 - float Vflex1 = ADCflex1 * VCC / 4095.0; //1023.0 - - float Rflex0 = R_DIV * (VCC / Vflex0 - 1.0); - float Rflex1 = R_DIV * (VCC / Vflex1 - 1.0); - - float angle0 = Rflex0 * 2.6716/1000 - 30.2045 -20; - float angle1 = Rflex1 * 2.6716/1000 - 30.2045 -20; - - fingerAngles[0] = angle0; - fingerAngles[1] = angle1; - - - //Läser alla sensorer och lägger i en lista som sedan filtreras - for(int i = 0; i -#include -#include - -// Defining breakout board, multiplexter -#define CS 5 -ADS1118 ads1118(CS); - -// Change these constants according to your project's design -const float VCC = 3.3; // voltage at Ardunio 5V line -const float R_DIV = 100000.0; // resistor used to create a voltage divider - -float readResistance(int pin, int type){ // 0<=type<6 -> on esp board, 6= on multiplexer - float Vflex = 0; - if(type < 6){ - int ADCflex = analogRead(pin); - Vflex = ADCflex * VCC / 4095.0; // 12 bit gives 4095 values - } - else if (type >= 6){ - Vflex = ads1118.getMilliVolts(pin) / 1000.0; - } - - float Rflex = R_DIV * (VCC / Vflex - 1.0); - return Rflex; -} - -float getAngle(int pin, int type){ - float angle = readResistance(pin, type) * 2.6716/1000 - 30.2045 - 60; //From Matlab calibration - return angle; -} - diff --git a/src/sensorClass.cpp b/src/sensorClass.cpp new file mode 100644 index 0000000..9675ffd --- /dev/null +++ b/src/sensorClass.cpp @@ -0,0 +1,43 @@ +/* + This class file is used to create flex sensor objects that handle all reading + and filtering of each sensor signal. +*/ +#include "sensorClass.h" +#include +#include +#include +#include "config.h" + +/* + Constructor +*/ +// 0<=type<6 -> on esp board, 6= on multiplexer +sensor::sensor(int pin, ADS1118 ads){ + m_pin = pin; + ads1118 = ads; +} + +/* + Performs a measurement of the sensor and adds it to the median filter. + Returns the median sensor reading value. +*/ +float sensor::getAngle(){ + float angle = getResistance(m_pin) * 2.6716/1000 - 30.2045 - 60; //From Matlab calibration + + m_f.addSample(angle); + + return m_f.getMedian(); +} + +/* + Helper method for getAngle(). +*/ +float sensor::getResistance(int pin){ + float Vflex; + + Vflex = ads1118.getMilliVolts(pin) / 1000.0; + + float Rflex = R_DIV * (VCC / Vflex - 1.0); + return Rflex; +} + diff --git a/src/flexsensorClass.h b/src/sensorClass.h similarity index 61% rename from src/flexsensorClass.h rename to src/sensorClass.h index 2e951e4..2bc6f62 100644 --- a/src/flexsensorClass.h +++ b/src/sensorClass.h @@ -5,25 +5,23 @@ #pragma once #include +#include #include "config.h" #include "MedianFilter.h" /* Main class */ -class flexsensor{ - // Variables +class sensor{ private: + // Variables and objects int m_pin; - String m_location; + ADS1118 ads1118(int); MedianFilter m_f; - + // Methods + float getResistance(int); public: - flexsensor(int pin, String location){}; + sensor(int pin, ADS1118 ads){}; // Methods - // ... Gets - float getMedian(); - String getlocation(); - // ... Sets - void read(); + float getAngle(); }; \ No newline at end of file diff --git a/src/talkyBoi.h b/src/talkyBoi.h index 6a4bfdc..7a8a4b3 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -1,6 +1,7 @@ #include #include #include +#include "config.h" //uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress till den svarta uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; //MAC-adress till den silver @@ -65,7 +66,6 @@ void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { Serial.print(recID); Serial.print(","); Serial.println(recID); - } void getMACAdress(){ @@ -73,7 +73,7 @@ void getMACAdress(){ Serial.println(WiFi.macAddress()); } -void init_wifi (){ +void init_wifi(){ WiFi.mode(WIFI_STA); if (esp_now_init() != ESP_OK) { Serial.println("Error initializing ESP-NOW"); @@ -95,7 +95,7 @@ void init_wifi (){ esp_now_register_recv_cb(OnDataRecv); } -void send (float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP){ +void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP){ uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; msg_to_send.sendID = sendID; msg_to_send.thumbIP = thumbIP; @@ -111,12 +111,14 @@ void send (float sendID, float thumbIP, float thumbMCP, float finger1PIP, float esp_err_t result = esp_now_send(broadcastAdress, (uint8_t *) &msg_to_send, sizeof(msg_to_send)); } + void sendToModel(int sendID, float thumbIP, float thumbMCP){ Serial.println("Send to model : "); uint8_t broadcastAdress[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; msg_to_send.sendID = sendID; esp_err_t result = esp_now_send(broadcastAdress,(uint8_t *) &msg_to_send, sizeof(msg_to_send)); } -void recieve () { + +void recieve() { } \ No newline at end of file From 104cf860afcbed8a30f4467595e0fe35af3cc481 Mon Sep 17 00:00:00 2001 From: Mac D Date: Wed, 16 Mar 2022 09:09:24 +0100 Subject: [PATCH 02/48] Change formatting --- src/config.h | 8 ++++---- src/sensorClass.cpp | 15 ++++++++------- src/sensorClass.h | 9 +++++---- src/talkyBoi.h | 7 ++++++- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/config.h b/src/config.h index ee2f247..43669f7 100644 --- a/src/config.h +++ b/src/config.h @@ -1,6 +1,6 @@ -/* - Configuration file for the entire project. - Define and change all constant variables here. +/** + * Configuration file for the entire project. + * Define and change all constant variables here! */ #pragma once @@ -15,4 +15,4 @@ const float R_DIV = 100000.0; // Resistor used to create a voltage divider const int SAMPLES = 20; // Pin to the push button that turns the controller on -#define interuptPin 16 \ No newline at end of file +#define INTERUPT_PIN 16 \ No newline at end of file diff --git a/src/sensorClass.cpp b/src/sensorClass.cpp index 9675ffd..f80ee5a 100644 --- a/src/sensorClass.cpp +++ b/src/sensorClass.cpp @@ -1,17 +1,17 @@ -/* - This class file is used to create flex sensor objects that handle all reading - and filtering of each sensor signal. +/** + * This class file is used to create flex sensor objects that handle all reading + * and filtering of each sensor signal. */ -#include "sensorClass.h" #include #include #include -#include "config.h" +#include "SensorClass.h" +#include "Config.h" + /* Constructor */ -// 0<=type<6 -> on esp board, 6= on multiplexer sensor::sensor(int pin, ADS1118 ads){ m_pin = pin; ads1118 = ads; @@ -19,7 +19,7 @@ sensor::sensor(int pin, ADS1118 ads){ /* Performs a measurement of the sensor and adds it to the median filter. - Returns the median sensor reading value. + Returns the median angle value. */ float sensor::getAngle(){ float angle = getResistance(m_pin) * 2.6716/1000 - 30.2045 - 60; //From Matlab calibration @@ -31,6 +31,7 @@ float sensor::getAngle(){ /* Helper method for getAngle(). + Takes a reading at the voltage divider and returns a resistance. */ float sensor::getResistance(int pin){ float Vflex; diff --git a/src/sensorClass.h b/src/sensorClass.h index 2bc6f62..00cf161 100644 --- a/src/sensorClass.h +++ b/src/sensorClass.h @@ -1,12 +1,12 @@ -/* - This class file is used to create flex sensor objects that handle all reading - and filtering of each sensor signal. +/** + * This class file is used to create flex sensor objects that handle all reading + * and filtering of each sensor signal. */ #pragma once #include #include -#include "config.h" +#include "Config.h" #include "MedianFilter.h" /* @@ -17,6 +17,7 @@ class sensor{ // Variables and objects int m_pin; ADS1118 ads1118(int); + // Number of samples are defined in config.h MedianFilter m_f; // Methods float getResistance(int); diff --git a/src/talkyBoi.h b/src/talkyBoi.h index 7a8a4b3..c3c4a2d 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -1,7 +1,12 @@ +/** + * + */ +#pragma once + #include #include #include -#include "config.h" +#include "Config.h" //uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress till den svarta uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; //MAC-adress till den silver From 3992ed2e88b17e6001c99d06d65a5da71c6eb961 Mon Sep 17 00:00:00 2001 From: Mac D Date: Wed, 16 Mar 2022 09:17:12 +0100 Subject: [PATCH 03/48] Add comment blocks --- src/main.cpp | 73 +++++++++++++++++++-------------------------- src/sensorClass.cpp | 12 +++++--- src/talkyBoi.h | 2 +- 3 files changed, 40 insertions(+), 47 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d816d39..8a5da30 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,20 +1,17 @@ #include -#include -#include - -#define interuptPin 17 +#include "TalkyBoi.h" // Pin connected to voltage divider output. used for analogRead to get resistance of the flexsensors -const int thumbIP_Pin = 36; -const int thumbMCP_Pin = 39; -const int f1PIP_Pin = 32; -const int f1MCP_Pin = 33; -const int f2PIP_Pin = 34; -const int f2MCP_Pin = 35; -const int f3PIP_Pin = ads1118.AIN_2; -const int f3MCP_Pin = ads1118.AIN_3; -const int f4PIP_Pin = ads1118.AIN_0; -const int f4MCP_Pin = ads1118.AIN_1; +const uint8_t thumbIP_Pin = ads1118.AIN_0; +const uint8_t thumbMCP_Pin = ads1118.AIN_1; +const uint8_t f1PIP_Pin = ads1118.AIN_2; +const uint8_t f1MCP_Pin = ads1118.AIN_3; +const int f2PIP_Pin = 36; +const int f2MCP_Pin = 39; +const int f3PIP_Pin = 32; +const int f3MCP_Pin = 33; +const int f4PIP_Pin = 34; +const int f4MCP_Pin = 35; const int pinList[] = {thumbIP_Pin, thumbMCP_Pin, f1PIP_Pin, f1MCP_Pin, f2PIP_Pin, f2MCP_Pin, f3PIP_Pin, f3MCP_Pin, f4PIP_Pin, f4MCP_Pin}; const int sizeList = sizeof(pinList)/sizeof(int); float fingerAngles[10] = {0,0,0,0,0,0,0,0,0,0}; @@ -24,6 +21,9 @@ int o = 0; int buttonRun = 0; int state = 0; +/* + +*/ void initBoard(){ ads1118.begin(); // Initialize board ads1118.setSamplingRate(ads1118.RATE_860SPS); // highest sampling rate possible @@ -31,13 +31,12 @@ void initBoard(){ } void initAnalogPin(){ - pinMode(thumbIP_Pin, INPUT); // change later! - pinMode(thumbMCP_Pin, INPUT); - pinMode(f1PIP_Pin, INPUT); - pinMode(f1MCP_Pin, INPUT); - pinMode(f2PIP_Pin, INPUT); - pinMode(f2MCP_Pin, INPUT); - + pinMode(f2PIP_Pin, INPUT); // maybe change later! + pinMode(f2MCP_Pin, INPUT); + pinMode(f3PIP_Pin, INPUT); + pinMode(f3MCP_Pin, INPUT); + pinMode(f4PIP_Pin, INPUT); + pinMode(f4MCP_Pin, INPUT); } void interuptFunc(){ @@ -60,39 +59,29 @@ void interuptFunc(){ void setup() { Serial.begin(115200); delay(100); - getMACAdress(); //MAC adress är vad som körs för att WIFI ska funkar, den ANDRA bärands MAC adress ska skrivas in i denna koden och tvärtom. + getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. init_wifi(); // Initiate ESP_NOW initBoard(); // Initiate breakout board - initAnalogPin(); - // attachInterrupt(17, interuptFunc, HIGH); // interupt för start/stopp knapp + initAnalogPin(); // Initiate analog pins on ESP + //attachInterrupt(17, interuptFunc, HIGH); // interupt for start/stop button } void loop() { - //while(!state){} //Ta bort kommentar för att ha en knapp som låser/öppnar programmet när det körs. Behöver en debounce för knappen innan det funkar. - - for(int i = 0; i>>>>>> de77f9514885061b4545c7e60c6282d2ad28d74c + /* sendID++; send(sendID, fingerAngles[0], fingerAngles[1], fingerAngles[2], fingerAngles[3], fingerAngles[4], fingerAngles[5], fingerAngles[6], fingerAngles[7], fingerAngles[8], fingerAngles[9]); -<<<<<<< HEAD - sendToModel(o,1.0,1.0); - o++; - delay(1000); - -======= - delay(10); - delay(10); ->>>>>>> de77f9514885061b4545c7e60c6282d2ad28d74c + */ + delay(100); } diff --git a/src/sensorClass.cpp b/src/sensorClass.cpp index f80ee5a..b3b20e9 100644 --- a/src/sensorClass.cpp +++ b/src/sensorClass.cpp @@ -9,17 +9,19 @@ #include "Config.h" -/* +/** Constructor + @param pin the pin to which the flex sensor is connected to. + @param ads the ADC breakout board object which the flexsensor is connected to. */ sensor::sensor(int pin, ADS1118 ads){ m_pin = pin; ads1118 = ads; } -/* +/** Performs a measurement of the sensor and adds it to the median filter. - Returns the median angle value. + @return a float with the median angle value. */ float sensor::getAngle(){ float angle = getResistance(m_pin) * 2.6716/1000 - 30.2045 - 60; //From Matlab calibration @@ -29,9 +31,11 @@ float sensor::getAngle(){ return m_f.getMedian(); } -/* +/** Helper method for getAngle(). Takes a reading at the voltage divider and returns a resistance. + @param pin the pin to take a reading from. + @return a float with the resistance of the flex sensor. */ float sensor::getResistance(int pin){ float Vflex; diff --git a/src/talkyBoi.h b/src/talkyBoi.h index c3c4a2d..aab13c7 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -1,5 +1,5 @@ /** - * + * Lägg till kommentarer här om vad talky boi gör :) */ #pragma once From 2ef0b826e5deaa9cffad5ed78abc282a932e4466 Mon Sep 17 00:00:00 2001 From: Mac D Date: Wed, 16 Mar 2022 09:30:59 +0100 Subject: [PATCH 04/48] Clean comments and code --- src/main.cpp | 30 ++++++------------------------ src/sensorClass.cpp | 18 +++++++++--------- src/sensorClass.h | 4 ++-- 3 files changed, 17 insertions(+), 35 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8a5da30..51c0b8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,13 +16,12 @@ const int pinList[] = {thumbIP_Pin, thumbMCP_Pin, f1PIP_Pin, f1MCP_Pin, f2PIP_Pi const int sizeList = sizeof(pinList)/sizeof(int); float fingerAngles[10] = {0,0,0,0,0,0,0,0,0,0}; int sendID = 0; -int o = 0; int buttonRun = 0; int state = 0; -/* - +/** + * Initiates the ADC breakout board. */ void initBoard(){ ads1118.begin(); // Initialize board @@ -30,15 +29,9 @@ void initBoard(){ ads1118.setFullScaleRange(ads1118.FSR_4096); // 12 bit } -void initAnalogPin(){ - pinMode(f2PIP_Pin, INPUT); // maybe change later! - pinMode(f2MCP_Pin, INPUT); - pinMode(f3PIP_Pin, INPUT); - pinMode(f3MCP_Pin, INPUT); - pinMode(f4PIP_Pin, INPUT); - pinMode(f4MCP_Pin, INPUT); -} - +/** + * Toggles the state of the microcontroller. +*/ void interuptFunc(){ static unsigned long last_interuptTime = 0; unsigned long interupt_time = millis(); @@ -55,31 +48,20 @@ void interuptFunc(){ } - void setup() { Serial.begin(115200); delay(100); getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. init_wifi(); // Initiate ESP_NOW - initBoard(); // Initiate breakout board - initAnalogPin(); // Initiate analog pins on ESP + initBoard(); // Initiate breakout board //attachInterrupt(17, interuptFunc, HIGH); // interupt for start/stop button } void loop() { - //while(!state){} //Remove this comment to have a butten that locks/unlocks the program when it is run. Needs a debounce for the button before it works. - - for(int i = 0; i Date: Thu, 24 Mar 2022 13:23:30 +0100 Subject: [PATCH 05/48] New_board --- src/main.cpp | 85 ++++++++++++++++++++++++++++++++++++++++----- src/sensorClass.cpp | 9 ++++- 2 files changed, 84 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 51c0b8e..b08edff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,17 @@ #include +#include #include "TalkyBoi.h" // Pin connected to voltage divider output. used for analogRead to get resistance of the flexsensors +const int s0 = 36; +const int s1 = 39; +const int s2 = 32; +const int s3 = 33; +const int SIG_pin = 34; +/* const uint8_t thumbIP_Pin = ads1118.AIN_0; -const uint8_t thumbMCP_Pin = ads1118.AIN_1; -const uint8_t f1PIP_Pin = ads1118.AIN_2; +const uint8_t thumbMCP_Pin = ads1118.AIN_1; +const uint8_t f1PIP_Pin = ads1118.AIN_2; const uint8_t f1MCP_Pin = ads1118.AIN_3; const int f2PIP_Pin = 36; const int f2MCP_Pin = 39; @@ -16,18 +23,70 @@ const int pinList[] = {thumbIP_Pin, thumbMCP_Pin, f1PIP_Pin, f1MCP_Pin, f2PIP_Pi const int sizeList = sizeof(pinList)/sizeof(int); float fingerAngles[10] = {0,0,0,0,0,0,0,0,0,0}; int sendID = 0; +*/ int buttonRun = 0; int state = 0; -/** - * Initiates the ADC breakout board. -*/ -void initBoard(){ + + // Initiates the ADC breakout board. +/* +void initBoard2(){ ads1118.begin(); // Initialize board ads1118.setSamplingRate(ads1118.RATE_860SPS); // highest sampling rate possible ads1118.setFullScaleRange(ads1118.FSR_4096); // 12 bit } +*/ + +void initBoard(){ + + + pinMode(s0, OUTPUT); + pinMode(s1, OUTPUT); + pinMode(s2, OUTPUT); + pinMode(s3, OUTPUT); + + digitalWrite(s0, LOW); + digitalWrite(s1, LOW); + digitalWrite(s2, LOW); + digitalWrite(s3, LOW); +} + +int readMux(int channel){ + int controlPin[] = {s0, s1, s2, s3}; + + int muxChannel[16][4]={ + {0,0,0,0}, //channel 0 + {1,0,0,0}, //channel 1 + {0,1,0,0}, //channel 2 + {1,1,0,0}, //channel 3 + {0,0,1,0}, //channel 4 + {1,0,1,0}, //channel 5 + {0,1,1,0}, //channel 6 + {1,1,1,0}, //channel 7 + {0,0,0,1}, //channel 8 + {1,0,0,1}, //channel 9 + {0,1,0,1}, //channel 10 + {1,1,0,1}, //channel 11 + {0,0,1,1}, //channel 12 + {1,0,1,1}, //channel 13 + {0,1,1,1}, //channel 14 + {1,1,1,1} //channel 15 + }; + + //loop through the 4 sig + for(int i = 0; i < 4; i ++){ + digitalWrite(controlPin[i], muxChannel[channel][i]); + } + + //read the value at the SIG pin + int val = analogRead(SIG_pin); + + //return the value + return val; +} + + /** * Toggles the state of the microcontroller. @@ -51,8 +110,8 @@ void interuptFunc(){ void setup() { Serial.begin(115200); delay(100); - getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. - init_wifi(); // Initiate ESP_NOW + // getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. + // init_wifi(); // Initiate ESP_NOW initBoard(); // Initiate breakout board //attachInterrupt(17, interuptFunc, HIGH); // interupt for start/stop button } @@ -63,7 +122,15 @@ void loop() { send(sendID, fingerAngles[0], fingerAngles[1], fingerAngles[2], fingerAngles[3], fingerAngles[4], fingerAngles[5], fingerAngles[6], fingerAngles[7], fingerAngles[8], fingerAngles[9]); */ - delay(100); + int val1 = readMux(0); + int val2 = readMux(1); + Serial.print("val 1: "); + Serial.println(val1); + Serial.print("val 2: "); + Serial.println(val2); + + delay(250); + } diff --git a/src/sensorClass.cpp b/src/sensorClass.cpp index 552d5d6..de21a36 100644 --- a/src/sensorClass.cpp +++ b/src/sensorClass.cpp @@ -2,27 +2,31 @@ * This class file is used to create flex sensor objects that handle all reading * and filtering of each sensor signal. */ +/* #include #include #include #include "SensorClass.h" #include "Config.h" - +*/ /** * Constructor * @param pin the pin to which the flex sensor is connected to. * @param ads the ADC breakout board object which the flexsensor is connected to. */ +/* sensor::sensor(int pin, ADS1118 ads){ m_pin = pin; ads1118 = ads; } +*/ /** * Performs a measurement of the sensor and adds it to the median filter. * @return a float with the median angle value. */ +/* float sensor::getAngle(){ float angle = getResistance(m_pin) * 2.6716/1000 - 30.2045 - 60; //From Matlab calibration @@ -30,6 +34,7 @@ float sensor::getAngle(){ return m_f.getMedian(); } +*/ /** * Helper method for getAngle(). @@ -37,6 +42,7 @@ float sensor::getAngle(){ * @param pin the pin to take a reading from. * @return a float with the resistance of the flex sensor. */ +/* float sensor::getResistance(int pin){ float Vflex; @@ -45,4 +51,5 @@ float sensor::getResistance(int pin){ float Rflex = R_DIV * (VCC / Vflex - 1.0); return Rflex; } +*/ From 05730d309fb463ae12d34b58feb039f2877ed58c Mon Sep 17 00:00:00 2001 From: Linneasedin <94436291+Linneasedin@users.noreply.github.com> Date: Thu, 24 Mar 2022 13:40:51 +0100 Subject: [PATCH 06/48] Not_working --- src/main.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b08edff..71827e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,14 +39,12 @@ void initBoard2(){ */ void initBoard(){ - - pinMode(s0, OUTPUT); pinMode(s1, OUTPUT); pinMode(s2, OUTPUT); pinMode(s3, OUTPUT); - digitalWrite(s0, LOW); + digitalWrite(s0, HIGH); digitalWrite(s1, LOW); digitalWrite(s2, LOW); digitalWrite(s3, LOW); @@ -122,10 +120,10 @@ void loop() { send(sendID, fingerAngles[0], fingerAngles[1], fingerAngles[2], fingerAngles[3], fingerAngles[4], fingerAngles[5], fingerAngles[6], fingerAngles[7], fingerAngles[8], fingerAngles[9]); */ - int val1 = readMux(0); + //int val1 = readMux(0); int val2 = readMux(1); - Serial.print("val 1: "); - Serial.println(val1); + //Serial.print("val 1: "); + //Serial.println(val1); Serial.print("val 2: "); Serial.println(val2); From 06bd4841d3f6f2c35b6ca29caef7e1d7c9a908a9 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Fri, 25 Mar 2022 11:23:07 +0100 Subject: [PATCH 07/48] =?UTF-8?q?=C3=84ndrade=20pin:ar=20s=C3=A5=20det=20f?= =?UTF-8?q?ungerar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 71827e4..6209656 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,11 +3,14 @@ #include "TalkyBoi.h" // Pin connected to voltage divider output. used for analogRead to get resistance of the flexsensors -const int s0 = 36; -const int s1 = 39; -const int s2 = 32; -const int s3 = 33; +const int s0 = 25; +const int s1 = 26; +const int s2 = 27; +const int s3 = 14; const int SIG_pin = 34; + + + /* const uint8_t thumbIP_Pin = ads1118.AIN_0; const uint8_t thumbMCP_Pin = ads1118.AIN_1; @@ -44,7 +47,7 @@ void initBoard(){ pinMode(s2, OUTPUT); pinMode(s3, OUTPUT); - digitalWrite(s0, HIGH); + digitalWrite(s0, LOW); digitalWrite(s1, LOW); digitalWrite(s2, LOW); digitalWrite(s3, LOW); @@ -120,11 +123,11 @@ void loop() { send(sendID, fingerAngles[0], fingerAngles[1], fingerAngles[2], fingerAngles[3], fingerAngles[4], fingerAngles[5], fingerAngles[6], fingerAngles[7], fingerAngles[8], fingerAngles[9]); */ - //int val1 = readMux(0); + int val1 = readMux(0); int val2 = readMux(1); - //Serial.print("val 1: "); - //Serial.println(val1); - Serial.print("val 2: "); + Serial.print("val 1: "); + Serial.print(val1); + Serial.print(" val 2: "); Serial.println(val2); delay(250); From b71be8adfa3f962fbacaa743552a12c15d9829c0 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Mon, 28 Mar 2022 10:12:48 +0200 Subject: [PATCH 08/48] Created new flexSensor class --- src/flexSensor.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++ src/flexSensor.h | 28 +++++++++++++++++++++++ src/sensorClass.cpp | 22 +++++++++--------- src/sensorClass.h | 3 +-- 4 files changed, 94 insertions(+), 14 deletions(-) create mode 100644 src/flexSensor.cpp create mode 100644 src/flexSensor.h diff --git a/src/flexSensor.cpp b/src/flexSensor.cpp new file mode 100644 index 0000000..6367610 --- /dev/null +++ b/src/flexSensor.cpp @@ -0,0 +1,55 @@ +/** + * This class file is used to create flex sensor objects that handle all reading + * and filtering of each sensor signal. +*/ + +#include +#include +#include "flexSensor.h" +#include "Config.h" + + +/** + * Constructor + * @param pin the pin to which the flex sensor is connected to. + * @param ads the ADC breakout board object which the flexsensor is connected to. +*/ + +flexSensor::flexSensor(int pin, int minimum_angle, int maximum_angle){ + m_pin = pin; + min_angle = minimum_angle; + max_angle = maximum_angle; +} + + +/** + * Performs a measurement of the sensor and adds it to the median filter. + * @return a float with the median angle value. +*/ + +float flexSensor::getAngle(){ + float angle = getResistance(m_pin) * 2.6716/1000 - 30.2045 - 60; //From Matlab calibration + + m_f.addSample(angle); + + return m_f.getMedian(); +} + + +/** + * Helper method for getAngle(). + * Takes a reading at the voltage divider and returns a resistance. + * @param pin the pin to take a reading from. + * @return a float with the resistance of the flex sensor. +*/ + +float flexSensor::getResistance(int pin){ + float Vflex; + + //Vflex = ads1118.getMilliVolts(pin) / 1000.0; + + float Rflex = R_DIV * (VCC / Vflex - 1.0); + return Rflex; +} + + diff --git a/src/flexSensor.h b/src/flexSensor.h new file mode 100644 index 0000000..7b1222f --- /dev/null +++ b/src/flexSensor.h @@ -0,0 +1,28 @@ +/** + * This class file is used to create flex sensor objects that handle all reading + * and filtering of each sensor signal. +*/ +#pragma once + +#include +#include "Config.h" +#include "MedianFilter.h" + +/** + * Main class +*/ +class flexSensor{ +private: + // Variables and objects + int m_pin; + int min_angle; + int max_angle; + // Number of samples are defined in config.h + MedianFilter m_f; + // Methods + float getResistance(int); +public: + flexSensor(int pin, int minimum_angle, int maximum_angle){}; + // Methods + float getAngle(); +}; \ No newline at end of file diff --git a/src/sensorClass.cpp b/src/sensorClass.cpp index de21a36..2559933 100644 --- a/src/sensorClass.cpp +++ b/src/sensorClass.cpp @@ -2,31 +2,29 @@ * This class file is used to create flex sensor objects that handle all reading * and filtering of each sensor signal. */ -/* + #include -#include #include #include "SensorClass.h" #include "Config.h" -*/ + /** * Constructor * @param pin the pin to which the flex sensor is connected to. * @param ads the ADC breakout board object which the flexsensor is connected to. */ -/* -sensor::sensor(int pin, ADS1118 ads){ + +sensor::sensor(int pin){ m_pin = pin; - ads1118 = ads; } -*/ + /** * Performs a measurement of the sensor and adds it to the median filter. * @return a float with the median angle value. */ -/* + float sensor::getAngle(){ float angle = getResistance(m_pin) * 2.6716/1000 - 30.2045 - 60; //From Matlab calibration @@ -34,7 +32,7 @@ float sensor::getAngle(){ return m_f.getMedian(); } -*/ + /** * Helper method for getAngle(). @@ -42,14 +40,14 @@ float sensor::getAngle(){ * @param pin the pin to take a reading from. * @return a float with the resistance of the flex sensor. */ -/* + float sensor::getResistance(int pin){ float Vflex; - Vflex = ads1118.getMilliVolts(pin) / 1000.0; + //Vflex = ads1118.getMilliVolts(pin) / 1000.0; float Rflex = R_DIV * (VCC / Vflex - 1.0); return Rflex; } -*/ + diff --git a/src/sensorClass.h b/src/sensorClass.h index c3e9a15..52e5aaf 100644 --- a/src/sensorClass.h +++ b/src/sensorClass.h @@ -16,13 +16,12 @@ class sensor{ private: // Variables and objects int m_pin; - ADS1118 ads1118(int); // Number of samples are defined in config.h MedianFilter m_f; // Methods float getResistance(int); public: - sensor(int pin, ADS1118 ads){}; + sensor(int pin){}; // Methods float getAngle(); }; \ No newline at end of file From 04ff01b6f1f0a6cab4d28829eafc201a5ea4c249 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Mon, 28 Mar 2022 10:34:10 +0200 Subject: [PATCH 09/48] improved flexSensor class --- src/flexSensor.cpp | 20 +++++++++----------- src/flexSensor.h | 3 +++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/flexSensor.cpp b/src/flexSensor.cpp index 6367610..d9e6e00 100644 --- a/src/flexSensor.cpp +++ b/src/flexSensor.cpp @@ -28,8 +28,7 @@ flexSensor::flexSensor(int pin, int minimum_angle, int maximum_angle){ */ float flexSensor::getAngle(){ - float angle = getResistance(m_pin) * 2.6716/1000 - 30.2045 - 60; //From Matlab calibration - + float angle = map(angle,calibrateOpen,calibrateClosed,min_angle,max_angle); m_f.addSample(angle); return m_f.getMedian(); @@ -43,13 +42,12 @@ float flexSensor::getAngle(){ * @return a float with the resistance of the flex sensor. */ -float flexSensor::getResistance(int pin){ - float Vflex; - - //Vflex = ads1118.getMilliVolts(pin) / 1000.0; - - float Rflex = R_DIV * (VCC / Vflex - 1.0); - return Rflex; -} - +void flexSensor::calibrate(int calibratedValue, int state){ + if(state == 1){ + calibrateOpen = calibratedValue; + } + if(state == 2){ + calibrateClosed = calibratedValue; + } +} \ No newline at end of file diff --git a/src/flexSensor.h b/src/flexSensor.h index 7b1222f..d738eb5 100644 --- a/src/flexSensor.h +++ b/src/flexSensor.h @@ -17,6 +17,8 @@ class flexSensor{ int m_pin; int min_angle; int max_angle; + int calibrateOpen; + int calibrateClosed; // Number of samples are defined in config.h MedianFilter m_f; // Methods @@ -25,4 +27,5 @@ class flexSensor{ flexSensor(int pin, int minimum_angle, int maximum_angle){}; // Methods float getAngle(); + void calibrate(int calibratedValue, int state); }; \ No newline at end of file From b48e891057bb8d5e472b07e280665b6a33b0bcdc Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Mon, 28 Mar 2022 11:05:03 +0200 Subject: [PATCH 10/48] fixade problem med flexSensor classen --- src/config.h | 5 +++++ src/flexSensor.cpp | 51 +++++++++++++++++++++++++++++++++++++++------- src/flexSensor.h | 4 +++- src/main.cpp | 10 ++------- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/config.h b/src/config.h index 43669f7..8f2d5c5 100644 --- a/src/config.h +++ b/src/config.h @@ -6,6 +6,11 @@ // Connection for CS pin on ADC breakout board #define CS_PIN 17 +#define SIG_PIN 34 +#define s0 25 +#define s1 26 +#define s2 27 +#define s3 14 // Change these constants according to your project's design const float VCC = 5; // Voltage that the sensors are connected to diff --git a/src/flexSensor.cpp b/src/flexSensor.cpp index d9e6e00..cc93bc3 100644 --- a/src/flexSensor.cpp +++ b/src/flexSensor.cpp @@ -1,6 +1,6 @@ /** * This class file is used to create flex sensor objects that handle all reading - * and filtering of each sensor signal. + * and filtering of each sensor signal.cha */ #include @@ -22,15 +22,53 @@ flexSensor::flexSensor(int pin, int minimum_angle, int maximum_angle){ } +int flexSensor::readMux(int channel){ + int controlPin[] = {s0, s1, s2, s3}; + + int muxChannel[16][4]={ + {0,0,0,0}, //channel 0 + {1,0,0,0}, //channel 1 + {0,1,0,0}, //channel 2 + {1,1,0,0}, //channel 3 + {0,0,1,0}, //channel 4 + {1,0,1,0}, //channel 5 + {0,1,1,0}, //channel 6 + {1,1,1,0}, //channel 7 + {0,0,0,1}, //channel 8 + {1,0,0,1}, //channel 9 + {0,1,0,1}, //channel 10 + {1,1,0,1}, //channel 11 + {0,0,1,1}, //channel 12 + {1,0,1,1}, //channel 13 + {0,1,1,1}, //channel 14 + {1,1,1,1} //channel 15 + }; + + //loop through the 4 sig + for(int i = 0; i < 4; i ++){ + digitalWrite(controlPin[i], muxChannel[channel][i]); + } + + //read the value at the SIG pin + int val = analogRead(SIG_PIN); + + //return the value + return val; +} + + /** * Performs a measurement of the sensor and adds it to the median filter. * @return a float with the median angle value. */ +int flexSensor::getValue(){ + return readMux(m_pin); +} + float flexSensor::getAngle(){ - float angle = map(angle,calibrateOpen,calibrateClosed,min_angle,max_angle); + float angle = map(readMux(m_pin),calibrateOpen,calibrateClosed,calibrateOpen,calibrateClosed); m_f.addSample(angle); - return m_f.getMedian(); } @@ -42,12 +80,11 @@ float flexSensor::getAngle(){ * @return a float with the resistance of the flex sensor. */ - -void flexSensor::calibrate(int calibratedValue, int state){ +void flexSensor::calibrate(int state){ if(state == 1){ - calibrateOpen = calibratedValue; + calibrateOpen = readMux(m_pin); } if(state == 2){ - calibrateClosed = calibratedValue; + calibrateClosed = readMux(m_pin); } } \ No newline at end of file diff --git a/src/flexSensor.h b/src/flexSensor.h index d738eb5..dc0388f 100644 --- a/src/flexSensor.h +++ b/src/flexSensor.h @@ -23,9 +23,11 @@ class flexSensor{ MedianFilter m_f; // Methods float getResistance(int); + int readMux(int); public: flexSensor(int pin, int minimum_angle, int maximum_angle){}; // Methods + int getValue(); float getAngle(); - void calibrate(int calibratedValue, int state); + void calibrate(int state); }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 6209656..0aa9105 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,7 @@ #include #include #include "TalkyBoi.h" - -// Pin connected to voltage divider output. used for analogRead to get resistance of the flexsensors -const int s0 = 25; -const int s1 = 26; -const int s2 = 27; -const int s3 = 14; -const int SIG_pin = 34; +#include "config.h" @@ -81,7 +75,7 @@ int readMux(int channel){ } //read the value at the SIG pin - int val = analogRead(SIG_pin); + int val = analogRead(SIG_PIN); //return the value return val; From 381b3323fc1749cb50fc9bfce7dc901b2f5c4528 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Mon, 28 Mar 2022 11:42:37 +0200 Subject: [PATCH 11/48] added potentiometer class and fixed bugs in flexSensor --- src/config.h | 3 +-- src/flexSensor.cpp | 34 +++++++++++++----------------- src/potentiometer.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++ src/potentiometer.h | 33 +++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 22 deletions(-) create mode 100644 src/potentiometer.cpp create mode 100644 src/potentiometer.h diff --git a/src/config.h b/src/config.h index 8f2d5c5..a21f91e 100644 --- a/src/config.h +++ b/src/config.h @@ -4,8 +4,7 @@ */ #pragma once -// Connection for CS pin on ADC breakout board -#define CS_PIN 17 +// Connection for pins on multiplexer #define SIG_PIN 34 #define s0 25 #define s1 26 diff --git a/src/flexSensor.cpp b/src/flexSensor.cpp index cc93bc3..43b089b 100644 --- a/src/flexSensor.cpp +++ b/src/flexSensor.cpp @@ -11,17 +11,18 @@ /** * Constructor - * @param pin the pin to which the flex sensor is connected to. - * @param ads the ADC breakout board object which the flexsensor is connected to. + * @param channel the channel to which the flex sensor is connected to. + * @param minimum_angle the minimum angle of flex sensor. + * @param maximum_angle the maximum angle of flex sensor. */ -flexSensor::flexSensor(int pin, int minimum_angle, int maximum_angle){ - m_pin = pin; +flexSensor::flexSensor(int channel, int minimum_angle, int maximum_angle){ + m_channel = channel; min_angle = minimum_angle; max_angle = maximum_angle; } - +// Changes multiplexer to read from int channel and then returns the read value int flexSensor::readMux(int channel){ int controlPin[] = {s0, s1, s2, s3}; @@ -56,35 +57,28 @@ int flexSensor::readMux(int channel){ return val; } +int flexSensor::getValue(){ + return readMux(m_channel); +} + /** * Performs a measurement of the sensor and adds it to the median filter. * @return a float with the median angle value. */ - -int flexSensor::getValue(){ - return readMux(m_pin); -} - float flexSensor::getAngle(){ - float angle = map(readMux(m_pin),calibrateOpen,calibrateClosed,calibrateOpen,calibrateClosed); + float angle = map(readMux(m_channel),calibrateOpen,calibrateClosed,min_angle,max_angle); m_f.addSample(angle); return m_f.getMedian(); } -/** - * Helper method for getAngle(). - * Takes a reading at the voltage divider and returns a resistance. - * @param pin the pin to take a reading from. - * @return a float with the resistance of the flex sensor. -*/ - +// Calibrates the flex sensor, either the open or closed state depending on input void flexSensor::calibrate(int state){ if(state == 1){ - calibrateOpen = readMux(m_pin); + calibrateOpen = readMux(m_channel); } if(state == 2){ - calibrateClosed = readMux(m_pin); + calibrateClosed = readMux(m_channel); } } \ No newline at end of file diff --git a/src/potentiometer.cpp b/src/potentiometer.cpp new file mode 100644 index 0000000..e6763e2 --- /dev/null +++ b/src/potentiometer.cpp @@ -0,0 +1,49 @@ +/** + * This class file is used to create potentiometer objects that handle all reading + * and filtering of each sensor signal.cha +*/ + +#include +#include +#include "potentiometer.h" +#include "Config.h" + + +/** + * Constructor + * @param channel the channel to which the flex sensor is connected to. + * @param minimum_angle the minimum angle of flex sensor. + * @param maximum_angle the maximum angle of flex sensor. +*/ + +potentiometer::potentiometer(int pin, int minimum_angle, int maximum_angle){ + m_pin = pin; + min_angle = minimum_angle; + max_angle = maximum_angle; +} + +int potentiometer::getValue(){ + return analogRead(m_pin); +} + + +/** + * Performs a measurement of the sensor and adds it to the median filter. + * @return a float with the median angle value. +*/ +float potentiometer::getAngle(){ + float angle = map(analogRead(m_pin), calibrateMin, calibrateMax, min_angle, max_angle); + m_f.addSample(angle); + return m_f.getMedian(); +} + + +// Calibrates the flex sensor, either the open or closed state depending on input +void potentiometer::calibrate(int state){ + if(state == 1){ + calibrateMin = analogRead(m_pin); + } + if(state == 2){ + calibrateMax = analogRead(m_pin); + } +} \ No newline at end of file diff --git a/src/potentiometer.h b/src/potentiometer.h new file mode 100644 index 0000000..c49f525 --- /dev/null +++ b/src/potentiometer.h @@ -0,0 +1,33 @@ +/** + * This class file is used to create flex sensor objects that handle all reading + * and filtering of each sensor signal. +*/ +#pragma once + +#include +#include "Config.h" +#include "MedianFilter.h" + +/** + * Main class +*/ +class potentiometer{ +private: + // Variables and objects + int m_pin; + int min_angle; + int max_angle; + int calibrateMin; + int calibrateMax; + // Number of samples are defined in config.h + MedianFilter m_f; + // Methods + float getResistance(int); + int readMux(int); +public: + potentiometer(int pin, int minimum_angle, int maximum_angle){}; + // Methods + int getValue(); + float getAngle(); + void calibrate(int state); +}; \ No newline at end of file From abc2fbeb1a550f5da591cfce9ab34348331f56d6 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Tue, 29 Mar 2022 13:47:51 +0200 Subject: [PATCH 12/48] kanske klart --- src/flexSensor.cpp | 17 +++++++----- src/flexSensor.h | 7 ++--- src/main.cpp | 8 ++++-- src/potentiometer.cpp | 61 ++++++++++++++++++++++++++++++++++++------- src/potentiometer.h | 7 ++--- src/sensorClass.h | 2 +- 6 files changed, 77 insertions(+), 25 deletions(-) diff --git a/src/flexSensor.cpp b/src/flexSensor.cpp index 43b089b..86e4549 100644 --- a/src/flexSensor.cpp +++ b/src/flexSensor.cpp @@ -5,9 +5,8 @@ #include #include -#include "flexSensor.h" #include "Config.h" - +#include "flexSensor.h" /** * Constructor @@ -19,7 +18,13 @@ flexSensor::flexSensor(int channel, int minimum_angle, int maximum_angle){ m_channel = channel; min_angle = minimum_angle; - max_angle = maximum_angle; + //max_angle = maximum_angle; +} + +flexSensor::flexSensor(int channel){ + m_channel = channel; + min_angle = 0; + max_angle = 90; } // Changes multiplexer to read from int channel and then returns the read value @@ -74,11 +79,11 @@ float flexSensor::getAngle(){ // Calibrates the flex sensor, either the open or closed state depending on input -void flexSensor::calibrate(int state){ - if(state == 1){ +void flexSensor::calibrate(bool state){ + if(state == false){ calibrateOpen = readMux(m_channel); } - if(state == 2){ + if(state == true){ calibrateClosed = readMux(m_channel); } } \ No newline at end of file diff --git a/src/flexSensor.h b/src/flexSensor.h index dc0388f..29960a8 100644 --- a/src/flexSensor.h +++ b/src/flexSensor.h @@ -14,7 +14,7 @@ class flexSensor{ private: // Variables and objects - int m_pin; + int m_channel; int min_angle; int max_angle; int calibrateOpen; @@ -25,9 +25,10 @@ class flexSensor{ float getResistance(int); int readMux(int); public: - flexSensor(int pin, int minimum_angle, int maximum_angle){}; + flexSensor(int channel, int minimum_angle, int maximum_angle); + flexSensor(int channel); // Methods int getValue(); float getAngle(); - void calibrate(int state); + void calibrate(bool state); }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0aa9105..3e0799f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,8 @@ #include -#include #include "TalkyBoi.h" #include "config.h" - +#include "flexSensor.h" +#include "potentiometer.h" /* @@ -22,9 +22,11 @@ float fingerAngles[10] = {0,0,0,0,0,0,0,0,0,0}; int sendID = 0; */ + int buttonRun = 0; int state = 0; +flexSensor hej123 = flexSensor(0); // Initiates the ADC breakout board. /* @@ -123,6 +125,8 @@ void loop() { Serial.print(val1); Serial.print(" val 2: "); Serial.println(val2); + + Serial.print(hej123.getValue()); delay(250); diff --git a/src/potentiometer.cpp b/src/potentiometer.cpp index e6763e2..2dedeaa 100644 --- a/src/potentiometer.cpp +++ b/src/potentiometer.cpp @@ -16,14 +16,55 @@ * @param maximum_angle the maximum angle of flex sensor. */ -potentiometer::potentiometer(int pin, int minimum_angle, int maximum_angle){ - m_pin = pin; +potentiometer::potentiometer(int channel, int minimum_angle, int maximum_angle){ + m_channel = channel; min_angle = minimum_angle; max_angle = maximum_angle; } +potentiometer::potentiometer(int channel){ + m_channel = channel; + min_angle = -15; + max_angle = 15; +} + +// Changes multiplexer to read from int channel and then returns the read value +int potentiometer::readMux(int channel){ + int controlPin[] = {s0, s1, s2, s3}; + + int muxChannel[16][4]={ + {0,0,0,0}, //channel 0 + {1,0,0,0}, //channel 1 + {0,1,0,0}, //channel 2 + {1,1,0,0}, //channel 3 + {0,0,1,0}, //channel 4 + {1,0,1,0}, //channel 5 + {0,1,1,0}, //channel 6 + {1,1,1,0}, //channel 7 + {0,0,0,1}, //channel 8 + {1,0,0,1}, //channel 9 + {0,1,0,1}, //channel 10 + {1,1,0,1}, //channel 11 + {0,0,1,1}, //channel 12 + {1,0,1,1}, //channel 13 + {0,1,1,1}, //channel 14 + {1,1,1,1} //channel 15 + }; + + //loop through the 4 sig + for(int i = 0; i < 4; i ++){ + digitalWrite(controlPin[i], muxChannel[channel][i]); + } + + //read the value at the SIG pin + int val = analogRead(SIG_PIN); + + //return the value + return val; +} + int potentiometer::getValue(){ - return analogRead(m_pin); + return readMux(m_channel); } @@ -32,18 +73,18 @@ int potentiometer::getValue(){ * @return a float with the median angle value. */ float potentiometer::getAngle(){ - float angle = map(analogRead(m_pin), calibrateMin, calibrateMax, min_angle, max_angle); + float angle = map(readMux(m_channel), calibrateMin, calibrateMax, min_angle, max_angle); m_f.addSample(angle); return m_f.getMedian(); } -// Calibrates the flex sensor, either the open or closed state depending on input -void potentiometer::calibrate(int state){ - if(state == 1){ - calibrateMin = analogRead(m_pin); +// Calibrates the flex sensor, either the minimum or maximum angle state depending on input +void potentiometer::calibrate(bool state){ + if(state == false){ + calibrateMin = readMux(m_channel); } - if(state == 2){ - calibrateMax = analogRead(m_pin); + if(state == true){ + calibrateMax = readMux(m_channel); } } \ No newline at end of file diff --git a/src/potentiometer.h b/src/potentiometer.h index c49f525..0ef4021 100644 --- a/src/potentiometer.h +++ b/src/potentiometer.h @@ -14,7 +14,7 @@ class potentiometer{ private: // Variables and objects - int m_pin; + int m_channel; int min_angle; int max_angle; int calibrateMin; @@ -25,9 +25,10 @@ class potentiometer{ float getResistance(int); int readMux(int); public: - potentiometer(int pin, int minimum_angle, int maximum_angle){}; + potentiometer(int channel, int minimum_angle, int maximum_angle); + potentiometer(int channel); // Methods int getValue(); float getAngle(); - void calibrate(int state); + void calibrate(bool state); }; \ No newline at end of file diff --git a/src/sensorClass.h b/src/sensorClass.h index 52e5aaf..eb24068 100644 --- a/src/sensorClass.h +++ b/src/sensorClass.h @@ -21,7 +21,7 @@ class sensor{ // Methods float getResistance(int); public: - sensor(int pin){}; + sensor(int pin); // Methods float getAngle(); }; \ No newline at end of file From 97a92060ee96606d98b3d89c260ebbcf02525d6f Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Tue, 29 Mar 2022 15:19:58 +0200 Subject: [PATCH 13/48] FIXED calibration issues --- src/flexSensor.cpp | 30 +++++++++++++++++++++++------- src/flexSensor.h | 2 ++ src/main.cpp | 21 +++++++++++++++++---- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/flexSensor.cpp b/src/flexSensor.cpp index 86e4549..3b67da6 100644 --- a/src/flexSensor.cpp +++ b/src/flexSensor.cpp @@ -18,7 +18,7 @@ flexSensor::flexSensor(int channel, int minimum_angle, int maximum_angle){ m_channel = channel; min_angle = minimum_angle; - //max_angle = maximum_angle; + max_angle = maximum_angle; } flexSensor::flexSensor(int channel){ @@ -80,10 +80,26 @@ float flexSensor::getAngle(){ // Calibrates the flex sensor, either the open or closed state depending on input void flexSensor::calibrate(bool state){ - if(state == false){ - calibrateOpen = readMux(m_channel); - } - if(state == true){ - calibrateClosed = readMux(m_channel); - } + + for(int i = 0; i < 2*SAMPLES; i++){ + m_f.addSample(readMux(m_channel)); + delay(20); + } + + if(!state){ + calibrateOpen = m_f.getMedian(); + } + + else{ + calibrateClosed = m_f.getMedian(); + } + +} + +int flexSensor::getCalibrateClosed(){ + return calibrateClosed; +} + +int flexSensor::getCalibrateOpen(){ + return calibrateOpen; } \ No newline at end of file diff --git a/src/flexSensor.h b/src/flexSensor.h index 29960a8..4b33ec0 100644 --- a/src/flexSensor.h +++ b/src/flexSensor.h @@ -31,4 +31,6 @@ class flexSensor{ int getValue(); float getAngle(); void calibrate(bool state); + int getCalibrateOpen(); + int getCalibrateClosed(); }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 3e0799f..ea54f18 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -111,6 +111,14 @@ void setup() { // init_wifi(); // Initiate ESP_NOW initBoard(); // Initiate breakout board //attachInterrupt(17, interuptFunc, HIGH); // interupt for start/stop button + Serial.println("calibration 1"); + hej123.calibrate(false); + delay(2000); + Serial.println("calibration 2"); + delay(2000); + hej123.calibrate(true); + delay(2000); + Serial.println("done"); } void loop() { @@ -119,16 +127,21 @@ void loop() { send(sendID, fingerAngles[0], fingerAngles[1], fingerAngles[2], fingerAngles[3], fingerAngles[4], fingerAngles[5], fingerAngles[6], fingerAngles[7], fingerAngles[8], fingerAngles[9]); */ - int val1 = readMux(0); + /*int val1 = readMux(0); int val2 = readMux(1); Serial.print("val 1: "); Serial.print(val1); Serial.print(" val 2: "); - Serial.println(val2); + Serial.println(val2);*/ Serial.print(hej123.getValue()); - - delay(250); + Serial.print(" // "); + Serial.print(hej123.getAngle()); + Serial.print(" // "); + Serial.print(hej123.getCalibrateOpen()); + Serial.print(" // "); + Serial.println(hej123.getCalibrateClosed()); + delay(100); } From 73866abe72aa3be213d0691ab3777286f6b7531b Mon Sep 17 00:00:00 2001 From: Linneasedin <94436291+Linneasedin@users.noreply.github.com> Date: Tue, 29 Mar 2022 15:29:09 +0200 Subject: [PATCH 14/48] New_list_of_fingers --- src/main.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ea54f18..55baa30 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,20 @@ int sendID = 0; int buttonRun = 0; int state = 0; -flexSensor hej123 = flexSensor(0); +flexSensor thumbIP = flexSensor(0); +flexSensor thumbMCP = flexSensor(1); +flexSensor f1PIP = flexSensor(2); +flexSensor f1MCP = flexSensor(3); +flexSensor f2PIP = flexSensor(4); +flexSensor f2MCP = flexSensor(5); +flexSensor f3PIP = flexSensor(6); +flexSensor f3MCP = flexSensor(7); +flexSensor f4PIP = flexSensor(8); +flexSensor f4MCP = flexSensor(9); + +flexSensor pinList[] = {thumbIP, thumbMCP, f1PIP, f1MCP, f2PIP, f2MCP, f3PIP, f3MCP, f4PIP, f4MCP}; +const int sizeList = sizeof(pinList)/sizeof(int); +float fingerAngles[10] = {0,0,0,0,0,0,0,0,0,0}; // Initiates the ADC breakout board. /* From c5ee6c1b4965404f0cbcb9e6b0550df462e6e082 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Tue, 29 Mar 2022 15:29:52 +0200 Subject: [PATCH 15/48] updated potentiometer class --- src/potentiometer.cpp | 30 ++++++++++++++++++++++++------ src/potentiometer.h | 2 ++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/potentiometer.cpp b/src/potentiometer.cpp index 2dedeaa..69d4309 100644 --- a/src/potentiometer.cpp +++ b/src/potentiometer.cpp @@ -63,6 +63,7 @@ int potentiometer::readMux(int channel){ return val; } +// Returns value read from multiplexer at given channel (for debugging purposes mainly) int potentiometer::getValue(){ return readMux(m_channel); } @@ -81,10 +82,27 @@ float potentiometer::getAngle(){ // Calibrates the flex sensor, either the minimum or maximum angle state depending on input void potentiometer::calibrate(bool state){ - if(state == false){ - calibrateMin = readMux(m_channel); - } - if(state == true){ - calibrateMax = readMux(m_channel); - } +for(int i = 0; i < 2*SAMPLES; i++){ + m_f.addSample(readMux(m_channel)); + delay(20); + } + + if(!state){ + calibrateMin = m_f.getMedian(); + } + + else{ + calibrateMin = m_f.getMedian(); + } + +} + +// Returns calibrateMax variable +int potentiometer::getCalibrateMax(){ + return calibrateMax; +} + +// Returns calibrateMin variable +int potentiometer::getCalibrateMin(){ + return calibrateMin; } \ No newline at end of file diff --git a/src/potentiometer.h b/src/potentiometer.h index 0ef4021..60b359e 100644 --- a/src/potentiometer.h +++ b/src/potentiometer.h @@ -31,4 +31,6 @@ class potentiometer{ int getValue(); float getAngle(); void calibrate(bool state); + int getCalibrateMin(); + int getCalibrateMax(); }; \ No newline at end of file From dd42fd0e70204f023f56abd9ddb8dac92e278c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Thu, 31 Mar 2022 12:52:02 +0200 Subject: [PATCH 16/48] Added comments --- src/main.cpp | 2 -- src/talkyBoi.h | 56 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6209656..02b2d69 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,8 +9,6 @@ const int s2 = 27; const int s3 = 14; const int SIG_pin = 34; - - /* const uint8_t thumbIP_Pin = ads1118.AIN_0; const uint8_t thumbMCP_Pin = ads1118.AIN_1; diff --git a/src/talkyBoi.h b/src/talkyBoi.h index aab13c7..9c16f81 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -1,5 +1,13 @@ /** - * Lägg till kommentarer här om vad talky boi gör :) + * This h file contains the funkction callbacks from ESPNOW + * that is used for WIFI communication peer to peer with the mechatronic hand. + * Save values into the struct "msg_to_send" with the "send" function which can be + * calld from the main method. + * to add more values to the struct change the structre of "struct message". + * + * The callback "OnDataSent" can be used to get information about the message status, "success" or "failure" on sent. + * The callback "OnDataRecv" can be used to get information on recieve, this can be used to print the strct that is recievd over WIFI. + * "msg_incoming" is the incoming struct that can be used to print the values(angles) or save the values(angles) as variables. */ #pragma once @@ -8,10 +16,10 @@ #include #include "Config.h" -//uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress till den svarta -uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; //MAC-adress till den silver -//uint8_t broadcastAdress[] = {0x7C,0x9E,0xBD,0x60,0xD1,0x8C}; //MAC till den med maskering -//uint8_t broadcastAdressModel[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; //MAC till den med vit tejp +//uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress black tape +uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; //MAC-adress silver tape +//uint8_t broadcastAdress[] = {0x7C,0x9E,0xBD,0x60,0xD1,0x8C}; //MAC masking tape +//uint8_t broadcastAdressModel[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; //MAC white tape int recID = 0; int error = 0; @@ -30,16 +38,16 @@ typedef struct struct_message{ float finger4PIP; float finger4MCP; float thumbOpp; - float test12; - float test13; - float test14; - float test15; + float finger1Pot; + float finger2Po; + float finger3Po; + float finger4Po; }struct_message; struct_message msg_to_send; struct_message msg_incoming; -// Callback when data is sent, triggas när något skickas +// Callback when data is sent, triggerd when message is sent void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { Serial.print("\r\nLast Packet Send Status:\t"); //Serial.write((String)mac_addr)); @@ -62,7 +70,10 @@ void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { } } -// Callback when data is received, triggas när något mottas (används ej) + +/** + * Callback when data is received, triggerd when a message is recievd + */ void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { memcpy(&msg_incoming, incomingData, sizeof(msg_incoming)); recID = msg_incoming.sendID; @@ -72,12 +83,18 @@ void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { Serial.print(","); Serial.println(recID); } - +/** + * Used to print the current ESP's MAC-adress which is used to for peer to peer communication with ESPNOW.' + * This adress is added to the ESP that SENDS data, if you only reciev no MAC-adress is needed + */ void getMACAdress(){ WiFi.mode(WIFI_MODE_STA); Serial.println(WiFi.macAddress()); } - +/** + * Used to print error messages if WIFI is not initializd. + * Also inits the ESPNOW protocol with MAC-adresses and peerInfo. + */ void init_wifi(){ WiFi.mode(WIFI_STA); if (esp_now_init() != ESP_OK) { @@ -100,6 +117,11 @@ void init_wifi(){ esp_now_register_recv_cb(OnDataRecv); } +/** + * This function is used to send data over WIFI, takes arguments sendID(incremented value to keep track of the number of sent packages) + * The rest of the arguments is values in the form of angles(already filterd and proccssed). + * Call this function from main when a message over wifi should be sent. + */ void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP){ uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; msg_to_send.sendID = sendID; @@ -116,14 +138,18 @@ void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float f esp_err_t result = esp_now_send(broadcastAdress, (uint8_t *) &msg_to_send, sizeof(msg_to_send)); } - +/** + * This is not used. + */ void sendToModel(int sendID, float thumbIP, float thumbMCP){ Serial.println("Send to model : "); uint8_t broadcastAdress[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; msg_to_send.sendID = sendID; esp_err_t result = esp_now_send(broadcastAdress,(uint8_t *) &msg_to_send, sizeof(msg_to_send)); } - +/** + * This is not used. + */ void recieve() { } \ No newline at end of file From 8e7052bce2d26f593b836c1efb36251b4e28c28d Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Thu, 31 Mar 2022 13:40:20 +0200 Subject: [PATCH 17/48] Created flexSensor objects and comments in talkyBoi.h --- src/main.cpp | 15 +++++++++++++- src/talkyBoi.h | 56 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ea54f18..55baa30 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,20 @@ int sendID = 0; int buttonRun = 0; int state = 0; -flexSensor hej123 = flexSensor(0); +flexSensor thumbIP = flexSensor(0); +flexSensor thumbMCP = flexSensor(1); +flexSensor f1PIP = flexSensor(2); +flexSensor f1MCP = flexSensor(3); +flexSensor f2PIP = flexSensor(4); +flexSensor f2MCP = flexSensor(5); +flexSensor f3PIP = flexSensor(6); +flexSensor f3MCP = flexSensor(7); +flexSensor f4PIP = flexSensor(8); +flexSensor f4MCP = flexSensor(9); + +flexSensor pinList[] = {thumbIP, thumbMCP, f1PIP, f1MCP, f2PIP, f2MCP, f3PIP, f3MCP, f4PIP, f4MCP}; +const int sizeList = sizeof(pinList)/sizeof(int); +float fingerAngles[10] = {0,0,0,0,0,0,0,0,0,0}; // Initiates the ADC breakout board. /* diff --git a/src/talkyBoi.h b/src/talkyBoi.h index aab13c7..9c16f81 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -1,5 +1,13 @@ /** - * Lägg till kommentarer här om vad talky boi gör :) + * This h file contains the funkction callbacks from ESPNOW + * that is used for WIFI communication peer to peer with the mechatronic hand. + * Save values into the struct "msg_to_send" with the "send" function which can be + * calld from the main method. + * to add more values to the struct change the structre of "struct message". + * + * The callback "OnDataSent" can be used to get information about the message status, "success" or "failure" on sent. + * The callback "OnDataRecv" can be used to get information on recieve, this can be used to print the strct that is recievd over WIFI. + * "msg_incoming" is the incoming struct that can be used to print the values(angles) or save the values(angles) as variables. */ #pragma once @@ -8,10 +16,10 @@ #include #include "Config.h" -//uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress till den svarta -uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; //MAC-adress till den silver -//uint8_t broadcastAdress[] = {0x7C,0x9E,0xBD,0x60,0xD1,0x8C}; //MAC till den med maskering -//uint8_t broadcastAdressModel[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; //MAC till den med vit tejp +//uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress black tape +uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; //MAC-adress silver tape +//uint8_t broadcastAdress[] = {0x7C,0x9E,0xBD,0x60,0xD1,0x8C}; //MAC masking tape +//uint8_t broadcastAdressModel[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; //MAC white tape int recID = 0; int error = 0; @@ -30,16 +38,16 @@ typedef struct struct_message{ float finger4PIP; float finger4MCP; float thumbOpp; - float test12; - float test13; - float test14; - float test15; + float finger1Pot; + float finger2Po; + float finger3Po; + float finger4Po; }struct_message; struct_message msg_to_send; struct_message msg_incoming; -// Callback when data is sent, triggas när något skickas +// Callback when data is sent, triggerd when message is sent void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { Serial.print("\r\nLast Packet Send Status:\t"); //Serial.write((String)mac_addr)); @@ -62,7 +70,10 @@ void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { } } -// Callback when data is received, triggas när något mottas (används ej) + +/** + * Callback when data is received, triggerd when a message is recievd + */ void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { memcpy(&msg_incoming, incomingData, sizeof(msg_incoming)); recID = msg_incoming.sendID; @@ -72,12 +83,18 @@ void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { Serial.print(","); Serial.println(recID); } - +/** + * Used to print the current ESP's MAC-adress which is used to for peer to peer communication with ESPNOW.' + * This adress is added to the ESP that SENDS data, if you only reciev no MAC-adress is needed + */ void getMACAdress(){ WiFi.mode(WIFI_MODE_STA); Serial.println(WiFi.macAddress()); } - +/** + * Used to print error messages if WIFI is not initializd. + * Also inits the ESPNOW protocol with MAC-adresses and peerInfo. + */ void init_wifi(){ WiFi.mode(WIFI_STA); if (esp_now_init() != ESP_OK) { @@ -100,6 +117,11 @@ void init_wifi(){ esp_now_register_recv_cb(OnDataRecv); } +/** + * This function is used to send data over WIFI, takes arguments sendID(incremented value to keep track of the number of sent packages) + * The rest of the arguments is values in the form of angles(already filterd and proccssed). + * Call this function from main when a message over wifi should be sent. + */ void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP){ uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; msg_to_send.sendID = sendID; @@ -116,14 +138,18 @@ void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float f esp_err_t result = esp_now_send(broadcastAdress, (uint8_t *) &msg_to_send, sizeof(msg_to_send)); } - +/** + * This is not used. + */ void sendToModel(int sendID, float thumbIP, float thumbMCP){ Serial.println("Send to model : "); uint8_t broadcastAdress[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; msg_to_send.sendID = sendID; esp_err_t result = esp_now_send(broadcastAdress,(uint8_t *) &msg_to_send, sizeof(msg_to_send)); } - +/** + * This is not used. + */ void recieve() { } \ No newline at end of file From 54d5c89ebb9625e681af1410e725c74bb17cd653 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Thu, 31 Mar 2022 13:45:24 +0200 Subject: [PATCH 18/48] import display.h Imported display.h from esp_with_screen_2 --- src/display.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/display.h diff --git a/src/display.h b/src/display.h new file mode 100644 index 0000000..e69de29 From 0609d497763289810ece25fc910c38a890deeeeb Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Thu, 31 Mar 2022 13:48:33 +0200 Subject: [PATCH 19/48] imported FreeMono12pt7bh.h from ESP_with_screen_2 --- src/FreeMono12pt7bh.h | 247 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 src/FreeMono12pt7bh.h diff --git a/src/FreeMono12pt7bh.h b/src/FreeMono12pt7bh.h new file mode 100644 index 0000000..6583c28 --- /dev/null +++ b/src/FreeMono12pt7bh.h @@ -0,0 +1,247 @@ +#ifndef FreeMono12pt7b_H +#define FreeMono12pt7b_H + +#ifdef __AVR__ +#include +#include +#elif defined(ESP8266) +#include +#undef PROGMEM +#define PROGMEM STORE_ATTR +#elif defined(__IMXRT1052__) || defined(__IMXRT1062__) +// PROGMEM is defefind for T4 to place data in specific memory section +#undef PROGMEM +#define PROGMEM +#else +#define PROGMEM +#endif + +const uint8_t FreeMono12pt7bBitmaps[] PROGMEM = { + 0x00, 0x49, 0x24, 0x92, 0x48, 0x01, 0xF8, 0xE7, 0xE7, 0x67, 0x42, 0x42, + 0x42, 0x42, 0x09, 0x02, 0x41, 0x10, 0x44, 0x11, 0x1F, 0xF1, 0x10, 0x4C, + 0x12, 0x3F, 0xE1, 0x20, 0x48, 0x12, 0x04, 0x81, 0x20, 0x48, 0x04, 0x07, + 0xA2, 0x19, 0x02, 0x40, 0x10, 0x03, 0x80, 0x3C, 0x00, 0x80, 0x10, 0x06, + 0x01, 0xE0, 0xAF, 0xC0, 0x40, 0x10, 0x04, 0x00, 0x3C, 0x19, 0x84, 0x21, + 0x08, 0x66, 0x0F, 0x00, 0x0C, 0x1C, 0x78, 0x01, 0xE0, 0xCC, 0x21, 0x08, + 0x43, 0x30, 0x78, 0x3E, 0x30, 0x10, 0x08, 0x02, 0x03, 0x03, 0x47, 0x14, + 0x8A, 0x43, 0x31, 0x8F, 0x60, 0xFD, 0xA4, 0x90, 0x05, 0x25, 0x24, 0x92, + 0x48, 0x92, 0x24, 0x11, 0x24, 0x89, 0x24, 0x92, 0x92, 0x90, 0x00, 0x04, + 0x02, 0x11, 0x07, 0xF0, 0xC0, 0x50, 0x48, 0x42, 0x00, 0x08, 0x04, 0x02, + 0x01, 0x00, 0x87, 0xFC, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x3B, 0x9C, + 0xCE, 0x62, 0x00, 0xFF, 0xE0, 0xFF, 0x80, 0x00, 0x80, 0xC0, 0x40, 0x20, + 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04, 0x02, 0x02, 0x01, 0x01, 0x00, + 0x80, 0x80, 0x40, 0x00, 0x1C, 0x31, 0x90, 0x58, 0x38, 0x0C, 0x06, 0x03, + 0x01, 0x80, 0xC0, 0x60, 0x38, 0x34, 0x13, 0x18, 0x70, 0x30, 0xE1, 0x44, + 0x81, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x81, 0x1F, 0xC0, 0x1E, 0x10, + 0x90, 0x68, 0x10, 0x08, 0x0C, 0x04, 0x04, 0x04, 0x06, 0x06, 0x06, 0x06, + 0x0E, 0x07, 0xFE, 0x3E, 0x10, 0x40, 0x08, 0x02, 0x00, 0x80, 0x40, 0xE0, + 0x04, 0x00, 0x80, 0x10, 0x04, 0x01, 0x00, 0x98, 0x63, 0xE0, 0x06, 0x0A, + 0x0A, 0x12, 0x22, 0x22, 0x42, 0x42, 0x82, 0x82, 0xFF, 0x02, 0x02, 0x02, + 0x0F, 0x7F, 0x20, 0x10, 0x08, 0x04, 0x02, 0xF1, 0x8C, 0x03, 0x00, 0x80, + 0x40, 0x20, 0x18, 0x16, 0x18, 0xF0, 0x0F, 0x8C, 0x08, 0x08, 0x04, 0x04, + 0x02, 0x79, 0x46, 0xC1, 0xE0, 0x60, 0x28, 0x14, 0x19, 0x18, 0x78, 0xFF, + 0x81, 0x81, 0x03, 0x02, 0x02, 0x02, 0x04, 0x04, 0x04, 0x04, 0x08, 0x08, + 0x08, 0x08, 0x3E, 0x31, 0xA0, 0x70, 0x18, 0x0C, 0x05, 0x8C, 0x38, 0x63, + 0x40, 0x60, 0x30, 0x18, 0x1B, 0x18, 0xF8, 0x3C, 0x31, 0x30, 0x50, 0x28, + 0x0C, 0x0F, 0x06, 0x85, 0x3C, 0x80, 0x40, 0x40, 0x20, 0x20, 0x63, 0xE0, + 0xFF, 0x80, 0x07, 0xFC, 0x39, 0xCE, 0x00, 0x00, 0x06, 0x33, 0x98, 0xC4, + 0x00, 0x00, 0xC0, 0x60, 0x18, 0x0C, 0x06, 0x01, 0x80, 0x0C, 0x00, 0x60, + 0x03, 0x00, 0x30, 0x01, 0x00, 0xFF, 0xF0, 0x00, 0x00, 0x0F, 0xFF, 0xC0, + 0x06, 0x00, 0x30, 0x01, 0x80, 0x18, 0x01, 0x80, 0xC0, 0x30, 0x18, 0x0C, + 0x02, 0x00, 0x00, 0x3E, 0x60, 0xA0, 0x20, 0x10, 0x08, 0x08, 0x18, 0x10, + 0x08, 0x00, 0x00, 0x00, 0x01, 0xC0, 0xE0, 0x1C, 0x31, 0x10, 0x50, 0x28, + 0x14, 0x3A, 0x25, 0x22, 0x91, 0x4C, 0xA3, 0xF0, 0x08, 0x02, 0x01, 0x80, + 0x7C, 0x3F, 0x00, 0x0C, 0x00, 0x48, 0x01, 0x20, 0x04, 0x40, 0x21, 0x00, + 0x84, 0x04, 0x08, 0x1F, 0xE0, 0x40, 0x82, 0x01, 0x08, 0x04, 0x20, 0x13, + 0xE1, 0xF0, 0xFF, 0x08, 0x11, 0x01, 0x20, 0x24, 0x04, 0x81, 0x1F, 0xC2, + 0x06, 0x40, 0x68, 0x05, 0x00, 0xA0, 0x14, 0x05, 0xFF, 0x00, 0x1E, 0x48, + 0x74, 0x05, 0x01, 0x80, 0x20, 0x08, 0x02, 0x00, 0x80, 0x20, 0x04, 0x01, + 0x01, 0x30, 0x87, 0xC0, 0xFE, 0x10, 0x44, 0x09, 0x03, 0x40, 0x50, 0x14, + 0x05, 0x01, 0x40, 0x50, 0x14, 0x0D, 0x02, 0x41, 0x3F, 0x80, 0xFF, 0xC8, + 0x09, 0x01, 0x20, 0x04, 0x00, 0x88, 0x1F, 0x02, 0x20, 0x40, 0x08, 0x01, + 0x00, 0xA0, 0x14, 0x03, 0xFF, 0xC0, 0xFF, 0xE8, 0x05, 0x00, 0xA0, 0x04, + 0x00, 0x88, 0x1F, 0x02, 0x20, 0x40, 0x08, 0x01, 0x00, 0x20, 0x04, 0x01, + 0xF0, 0x00, 0x1F, 0x46, 0x19, 0x01, 0x60, 0x28, 0x01, 0x00, 0x20, 0x04, + 0x00, 0x83, 0xF0, 0x0B, 0x01, 0x20, 0x23, 0x0C, 0x3E, 0x00, 0xE1, 0xD0, + 0x24, 0x09, 0x02, 0x40, 0x90, 0x27, 0xF9, 0x02, 0x40, 0x90, 0x24, 0x09, + 0x02, 0x40, 0xB8, 0x70, 0xFE, 0x20, 0x40, 0x81, 0x02, 0x04, 0x08, 0x10, + 0x20, 0x40, 0x81, 0x1F, 0xC0, 0x0F, 0xE0, 0x10, 0x02, 0x00, 0x40, 0x08, + 0x01, 0x00, 0x20, 0x04, 0x80, 0x90, 0x12, 0x02, 0x40, 0xC6, 0x30, 0x7C, + 0x00, 0xF1, 0xE4, 0x0C, 0x41, 0x04, 0x20, 0x44, 0x04, 0x80, 0x5C, 0x06, + 0x60, 0x43, 0x04, 0x10, 0x40, 0x84, 0x08, 0x40, 0xCF, 0x07, 0xF8, 0x04, + 0x00, 0x80, 0x10, 0x02, 0x00, 0x40, 0x08, 0x01, 0x00, 0x20, 0x04, 0x04, + 0x80, 0x90, 0x12, 0x03, 0xFF, 0xC0, 0xE0, 0x3B, 0x01, 0x94, 0x14, 0xA0, + 0xA4, 0x89, 0x24, 0x49, 0x14, 0x48, 0xA2, 0x45, 0x12, 0x10, 0x90, 0x04, + 0x80, 0x24, 0x01, 0x78, 0x3C, 0xE0, 0xF6, 0x02, 0x50, 0x25, 0x02, 0x48, + 0x24, 0xC2, 0x44, 0x24, 0x22, 0x43, 0x24, 0x12, 0x40, 0xA4, 0x0A, 0x40, + 0x6F, 0x06, 0x0F, 0x03, 0x0C, 0x60, 0x64, 0x02, 0x80, 0x18, 0x01, 0x80, + 0x18, 0x01, 0x80, 0x18, 0x01, 0x40, 0x26, 0x06, 0x30, 0xC0, 0xF0, 0xFF, + 0x10, 0x64, 0x05, 0x01, 0x40, 0x50, 0x34, 0x19, 0xF8, 0x40, 0x10, 0x04, + 0x01, 0x00, 0x40, 0x3E, 0x00, 0x0F, 0x03, 0x0C, 0x60, 0x64, 0x02, 0x80, + 0x18, 0x01, 0x80, 0x18, 0x01, 0x80, 0x18, 0x01, 0x40, 0x26, 0x06, 0x30, + 0xC1, 0xF0, 0x0C, 0x01, 0xF1, 0x30, 0xE0, 0xFF, 0x04, 0x18, 0x40, 0x44, + 0x04, 0x40, 0x44, 0x0C, 0x41, 0x87, 0xE0, 0x43, 0x04, 0x18, 0x40, 0x84, + 0x04, 0x40, 0x4F, 0x03, 0x1F, 0x48, 0x34, 0x05, 0x01, 0x40, 0x08, 0x01, + 0xC0, 0x0E, 0x00, 0x40, 0x18, 0x07, 0x01, 0xE1, 0xA7, 0xC0, 0xFF, 0xF0, + 0x86, 0x10, 0x82, 0x00, 0x40, 0x08, 0x01, 0x00, 0x20, 0x04, 0x00, 0x80, + 0x10, 0x02, 0x00, 0x40, 0x7F, 0x00, 0xF0, 0xF4, 0x02, 0x40, 0x24, 0x02, + 0x40, 0x24, 0x02, 0x40, 0x24, 0x02, 0x40, 0x24, 0x02, 0x40, 0x22, 0x04, + 0x30, 0xC0, 0xF0, 0xF8, 0x7C, 0x80, 0x22, 0x01, 0x04, 0x04, 0x10, 0x20, + 0x40, 0x80, 0x82, 0x02, 0x10, 0x08, 0x40, 0x11, 0x00, 0x48, 0x01, 0xA0, + 0x03, 0x00, 0x0C, 0x00, 0xF8, 0x7C, 0x80, 0x22, 0x00, 0x88, 0xC2, 0x23, + 0x10, 0x8E, 0x42, 0x29, 0x09, 0x24, 0x24, 0x90, 0x91, 0x41, 0x85, 0x06, + 0x14, 0x18, 0x70, 0x60, 0x80, 0xF0, 0xF2, 0x06, 0x30, 0x41, 0x08, 0x09, + 0x80, 0x50, 0x06, 0x00, 0x60, 0x0D, 0x00, 0x88, 0x10, 0xC2, 0x04, 0x60, + 0x2F, 0x0F, 0xF0, 0xF2, 0x02, 0x10, 0x41, 0x04, 0x08, 0x80, 0x50, 0x05, + 0x00, 0x20, 0x02, 0x00, 0x20, 0x02, 0x00, 0x20, 0x02, 0x01, 0xFC, 0xFF, + 0x40, 0xA0, 0x90, 0x40, 0x40, 0x40, 0x20, 0x20, 0x20, 0x10, 0x50, 0x30, + 0x18, 0x0F, 0xFC, 0xF2, 0x49, 0x24, 0x92, 0x49, 0x24, 0x9C, 0x80, 0x60, + 0x10, 0x08, 0x02, 0x01, 0x00, 0x40, 0x20, 0x08, 0x04, 0x01, 0x00, 0x80, + 0x20, 0x10, 0x04, 0x02, 0x00, 0x80, 0x40, 0xE4, 0x92, 0x49, 0x24, 0x92, + 0x49, 0x3C, 0x08, 0x0C, 0x09, 0x0C, 0x4C, 0x14, 0x04, 0xFF, 0xFC, 0x84, + 0x21, 0x3E, 0x00, 0x60, 0x08, 0x02, 0x3F, 0x98, 0x28, 0x0A, 0x02, 0xC3, + 0x9F, 0x30, 0xE0, 0x01, 0x00, 0x08, 0x00, 0x40, 0x02, 0x00, 0x13, 0xE0, + 0xA0, 0x86, 0x02, 0x20, 0x09, 0x00, 0x48, 0x02, 0x40, 0x13, 0x01, 0x14, + 0x13, 0x9F, 0x00, 0x1F, 0x4C, 0x19, 0x01, 0x40, 0x28, 0x01, 0x00, 0x20, + 0x02, 0x00, 0x60, 0x43, 0xF0, 0x00, 0xC0, 0x08, 0x01, 0x00, 0x20, 0x04, + 0x3C, 0x98, 0x52, 0x06, 0x80, 0x50, 0x0A, 0x01, 0x40, 0x24, 0x0C, 0xC2, + 0x87, 0x98, 0x3F, 0x18, 0x68, 0x06, 0x01, 0xFF, 0xE0, 0x08, 0x03, 0x00, + 0x60, 0xC7, 0xC0, 0x0F, 0x98, 0x08, 0x04, 0x02, 0x07, 0xF8, 0x80, 0x40, + 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x03, 0xF8, 0x1E, 0x6C, 0x39, 0x03, + 0x40, 0x28, 0x05, 0x00, 0xA0, 0x12, 0x06, 0x61, 0x43, 0xC8, 0x01, 0x00, + 0x20, 0x08, 0x3E, 0x00, 0xC0, 0x10, 0x04, 0x01, 0x00, 0x40, 0x13, 0x87, + 0x11, 0x82, 0x40, 0x90, 0x24, 0x09, 0x02, 0x40, 0x90, 0x2E, 0x1C, 0x08, + 0x04, 0x02, 0x00, 0x00, 0x03, 0xC0, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, + 0x00, 0x80, 0x43, 0xFE, 0x04, 0x08, 0x10, 0x00, 0x1F, 0xC0, 0x81, 0x02, + 0x04, 0x08, 0x10, 0x20, 0x40, 0x81, 0x02, 0x0B, 0xE0, 0xE0, 0x02, 0x00, + 0x20, 0x02, 0x00, 0x20, 0x02, 0x3C, 0x21, 0x02, 0x60, 0x2C, 0x03, 0x80, + 0x24, 0x02, 0x20, 0x21, 0x02, 0x08, 0xE1, 0xF0, 0x78, 0x04, 0x02, 0x01, + 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x80, 0x43, + 0xFE, 0xDC, 0xE3, 0x39, 0x90, 0x84, 0x84, 0x24, 0x21, 0x21, 0x09, 0x08, + 0x48, 0x42, 0x42, 0x17, 0x18, 0xC0, 0x67, 0x83, 0x84, 0x20, 0x22, 0x02, + 0x20, 0x22, 0x02, 0x20, 0x22, 0x02, 0x20, 0x2F, 0x07, 0x1F, 0x04, 0x11, + 0x01, 0x40, 0x18, 0x03, 0x00, 0x60, 0x0A, 0x02, 0x20, 0x83, 0xE0, 0xCF, + 0x85, 0x06, 0x60, 0x24, 0x01, 0x40, 0x14, 0x01, 0x40, 0x16, 0x02, 0x50, + 0x44, 0xF8, 0x40, 0x04, 0x00, 0x40, 0x0F, 0x00, 0x1E, 0x6C, 0x3B, 0x03, + 0x40, 0x28, 0x05, 0x00, 0xA0, 0x12, 0x06, 0x61, 0x43, 0xC8, 0x01, 0x00, + 0x20, 0x04, 0x03, 0xC0, 0xE3, 0x8B, 0x13, 0x00, 0x80, 0x20, 0x08, 0x02, + 0x00, 0x80, 0x20, 0x3F, 0x80, 0x1F, 0x58, 0x34, 0x05, 0x80, 0x1E, 0x00, + 0x60, 0x06, 0x01, 0xC0, 0xA7, 0xC0, 0x20, 0x04, 0x00, 0x80, 0x10, 0x0F, + 0xF0, 0x40, 0x08, 0x01, 0x00, 0x20, 0x04, 0x00, 0x80, 0x10, 0x03, 0x04, + 0x3F, 0x00, 0xC1, 0xC8, 0x09, 0x01, 0x20, 0x24, 0x04, 0x80, 0x90, 0x12, + 0x02, 0x61, 0xC7, 0xCC, 0xF8, 0xF9, 0x01, 0x08, 0x10, 0x60, 0x81, 0x0C, + 0x08, 0x40, 0x22, 0x01, 0x20, 0x05, 0x00, 0x30, 0x00, 0xF0, 0x7A, 0x01, + 0x10, 0x08, 0x8C, 0x42, 0x62, 0x12, 0x90, 0xA5, 0x05, 0x38, 0x28, 0xC0, + 0x86, 0x00, 0x78, 0xF3, 0x04, 0x18, 0x80, 0xD0, 0x06, 0x00, 0x70, 0x09, + 0x81, 0x0C, 0x20, 0x6F, 0x8F, 0xF0, 0xF2, 0x02, 0x20, 0x41, 0x04, 0x10, + 0x80, 0x88, 0x09, 0x00, 0x50, 0x06, 0x00, 0x20, 0x04, 0x00, 0x40, 0x08, + 0x0F, 0xE0, 0xFF, 0x41, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x40, + 0xBF, 0xC0, 0x19, 0x08, 0x42, 0x10, 0x84, 0x44, 0x18, 0x42, 0x10, 0x84, + 0x20, 0xC0, 0xFF, 0xFF, 0xC0, 0xC1, 0x08, 0x42, 0x10, 0x84, 0x30, 0x4C, + 0x42, 0x10, 0x84, 0x26, 0x00, 0x38, 0x13, 0x38, 0x38 }; + +const GFXglyph FreeMono12pt7bGlyphs[] PROGMEM = { + { 0, 1, 1, 14, 0, 0 }, // 0x20 ' ' + { 1, 3, 15, 14, 6, -14 }, // 0x21 '!' + { 7, 8, 7, 14, 3, -14 }, // 0x22 '"' + { 14, 10, 16, 14, 2, -14 }, // 0x23 '#' + { 34, 10, 17, 14, 2, -14 }, // 0x24 '$' + { 56, 10, 15, 14, 2, -14 }, // 0x25 '%' + { 75, 9, 12, 14, 3, -11 }, // 0x26 '&' + { 89, 3, 7, 14, 5, -14 }, // 0x27 ''' + { 92, 3, 18, 14, 7, -14 }, // 0x28 '(' + { 99, 3, 18, 14, 4, -14 }, // 0x29 ')' + { 106, 9, 9, 14, 3, -14 }, // 0x2A '*' + { 117, 9, 11, 14, 3, -11 }, // 0x2B '+' + { 130, 5, 7, 14, 3, -3 }, // 0x2C ',' + { 135, 11, 1, 14, 2, -6 }, // 0x2D '-' + { 137, 3, 3, 14, 5, -2 }, // 0x2E '.' + { 139, 9, 18, 14, 3, -15 }, // 0x2F '/' + { 160, 9, 15, 14, 3, -14 }, // 0x30 '0' + { 177, 7, 14, 14, 4, -13 }, // 0x31 '1' + { 190, 9, 15, 14, 2, -14 }, // 0x32 '2' + { 207, 10, 15, 14, 2, -14 }, // 0x33 '3' + { 226, 8, 15, 14, 3, -14 }, // 0x34 '4' + { 241, 9, 15, 14, 3, -14 }, // 0x35 '5' + { 258, 9, 15, 14, 3, -14 }, // 0x36 '6' + { 275, 8, 15, 14, 3, -14 }, // 0x37 '7' + { 290, 9, 15, 14, 3, -14 }, // 0x38 '8' + { 307, 9, 15, 14, 3, -14 }, // 0x39 '9' + { 324, 3, 10, 14, 5, -9 }, // 0x3A ':' + { 328, 5, 13, 14, 3, -9 }, // 0x3B ';' + { 337, 11, 11, 14, 2, -11 }, // 0x3C '<' + { 353, 12, 4, 14, 1, -8 }, // 0x3D '=' + { 359, 11, 11, 14, 2, -11 }, // 0x3E '>' + { 375, 9, 14, 14, 3, -13 }, // 0x3F '?' + { 391, 9, 16, 14, 3, -14 }, // 0x40 '@' + { 409, 14, 14, 14, 0, -13 }, // 0x41 'A' + { 434, 11, 14, 14, 2, -13 }, // 0x42 'B' + { 454, 10, 14, 14, 2, -13 }, // 0x43 'C' + { 472, 10, 14, 14, 2, -13 }, // 0x44 'D' + { 490, 11, 14, 14, 2, -13 }, // 0x45 'E' + { 510, 11, 14, 14, 2, -13 }, // 0x46 'F' + { 530, 11, 14, 14, 2, -13 }, // 0x47 'G' + { 550, 10, 14, 14, 2, -13 }, // 0x48 'H' + { 568, 7, 14, 14, 4, -13 }, // 0x49 'I' + { 581, 11, 14, 14, 2, -13 }, // 0x4A 'J' + { 601, 12, 14, 14, 2, -13 }, // 0x4B 'K' + { 622, 11, 14, 14, 2, -13 }, // 0x4C 'L' + { 642, 13, 14, 14, 1, -13 }, // 0x4D 'M' + { 665, 12, 14, 14, 1, -13 }, // 0x4E 'N' + { 686, 12, 14, 14, 1, -13 }, // 0x4F 'O' + { 707, 10, 14, 14, 2, -13 }, // 0x50 'P' + { 725, 12, 17, 14, 1, -13 }, // 0x51 'Q' + { 751, 12, 14, 14, 2, -13 }, // 0x52 'R' + { 772, 10, 14, 14, 2, -13 }, // 0x53 'S' + { 790, 11, 14, 14, 2, -13 }, // 0x54 'T' + { 810, 12, 14, 14, 1, -13 }, // 0x55 'U' + { 831, 14, 14, 14, 0, -13 }, // 0x56 'V' + { 856, 14, 14, 14, 0, -13 }, // 0x57 'W' + { 881, 12, 14, 14, 1, -13 }, // 0x58 'X' + { 902, 12, 14, 14, 1, -13 }, // 0x59 'Y' + { 923, 9, 14, 14, 3, -13 }, // 0x5A 'Z' + { 939, 3, 18, 14, 7, -14 }, // 0x5B '[' + { 946, 9, 18, 14, 3, -15 }, // 0x5C '\' + { 967, 3, 18, 14, 5, -14 }, // 0x5D ']' + { 974, 9, 6, 14, 3, -14 }, // 0x5E '^' + { 981, 14, 1, 14, 0, 3 }, // 0x5F '_' + { 983, 4, 4, 14, 4, -15 }, // 0x60 '`' + { 985, 10, 10, 14, 2, -9 }, // 0x61 'a' + { 998, 13, 15, 14, 0, -14 }, // 0x62 'b' + { 1023, 11, 10, 14, 2, -9 }, // 0x63 'c' + { 1037, 11, 15, 14, 2, -14 }, // 0x64 'd' + { 1058, 10, 10, 14, 2, -9 }, // 0x65 'e' + { 1071, 9, 15, 14, 4, -14 }, // 0x66 'f' + { 1088, 11, 14, 14, 2, -9 }, // 0x67 'g' + { 1108, 10, 15, 14, 2, -14 }, // 0x68 'h' + { 1127, 9, 15, 14, 3, -14 }, // 0x69 'i' + { 1144, 7, 19, 14, 3, -14 }, // 0x6A 'j' + { 1161, 12, 15, 14, 1, -14 }, // 0x6B 'k' + { 1184, 9, 15, 14, 3, -14 }, // 0x6C 'l' + { 1201, 13, 10, 14, 1, -9 }, // 0x6D 'm' + { 1218, 12, 10, 14, 1, -9 }, // 0x6E 'n' + { 1233, 11, 10, 14, 2, -9 }, // 0x6F 'o' + { 1247, 12, 14, 14, 1, -9 }, // 0x70 'p' + { 1268, 11, 14, 14, 2, -9 }, // 0x71 'q' + { 1288, 10, 10, 14, 3, -9 }, // 0x72 'r' + { 1301, 10, 10, 14, 2, -9 }, // 0x73 's' + { 1314, 11, 14, 14, 1, -13 }, // 0x74 't' + { 1334, 11, 10, 14, 2, -9 }, // 0x75 'u' + { 1348, 13, 10, 14, 1, -9 }, // 0x76 'v' + { 1365, 13, 10, 14, 1, -9 }, // 0x77 'w' + { 1382, 12, 10, 14, 1, -9 }, // 0x78 'x' + { 1397, 12, 14, 14, 1, -9 }, // 0x79 'y' + { 1418, 9, 10, 14, 3, -9 }, // 0x7A 'z' + { 1430, 5, 18, 14, 5, -14 }, // 0x7B '{' + { 1442, 1, 18, 14, 7, -14 }, // 0x7C '|' + { 1445, 5, 18, 14, 5, -14 }, // 0x7D '}' + { 1457, 10, 3, 14, 2, -7 } }; // 0x7E '~' + +const GFXfont FreeMono12pt7b PROGMEM = { + (uint8_t *)FreeMono12pt7bBitmaps, + (GFXglyph *)FreeMono12pt7bGlyphs, + 0x20, 0x7E, 24 }; + +// Approx. 2133 bytes + +#endif // FreeMono12pt7b_H From 567b419a3411a1c5ec0ee02297b05690ecff286a Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Thu, 31 Mar 2022 14:18:37 +0200 Subject: [PATCH 20/48] fixed errors with code --- src/{FreeMono12pt7bh.h => FreeMono12pt7b.h} | 3 ++ src/config.h | 6 +-- src/display.h | 52 +++++++++++++++++++++ src/main.cpp | 37 ++------------- src/sensorClass.cpp | 5 +- 5 files changed, 65 insertions(+), 38 deletions(-) rename src/{FreeMono12pt7bh.h => FreeMono12pt7b.h} (99%) diff --git a/src/FreeMono12pt7bh.h b/src/FreeMono12pt7b.h similarity index 99% rename from src/FreeMono12pt7bh.h rename to src/FreeMono12pt7b.h index 6583c28..ccc0150 100644 --- a/src/FreeMono12pt7bh.h +++ b/src/FreeMono12pt7b.h @@ -1,6 +1,9 @@ #ifndef FreeMono12pt7b_H #define FreeMono12pt7b_H +#include +#include + #ifdef __AVR__ #include #include diff --git a/src/config.h b/src/config.h index a21f91e..fb06c3d 100644 --- a/src/config.h +++ b/src/config.h @@ -11,9 +11,9 @@ #define s2 27 #define s3 14 -// Change these constants according to your project's design -const float VCC = 5; // Voltage that the sensors are connected to -const float R_DIV = 100000.0; // Resistor used to create a voltage divider +// Connection for pins on display +#define DISP_RES 32 +#define DISP_DC 33 // Number of samples for the median filter const int SAMPLES = 20; diff --git a/src/display.h b/src/display.h index e69de29..f7aeccc 100644 --- a/src/display.h +++ b/src/display.h @@ -0,0 +1,52 @@ +#include +#include +#include "FreeMono12pt7b.h" +#include "config.h" + +// Screen setup +Arduino_DataBus *bus = new Arduino_ESP32SPI(33 /* DC */, 5 /* CS */, 18 /* SCK */, 23 /* MOSI */, -1 /* MISO */, VSPI /* spi_num */); +//Arduino_DataBus *bus = new Arduino_ESP32SPI(33 /* DC */, 5 /* CS */, 18 /* SCK */, 23 /* MOSI */, 19 /* MISO */); +Arduino_GFX *gfx = new Arduino_ST7789(bus, 7 /* RST */, 0 /* rotation */, true /* IPS */, + 240 /* width */, 240 /* height */, 0 /* col offset 1 */, 0 /* row offset 1 */); + +void disp_initialize(){ + // Screen setup + pinMode(DISP_RES, OUTPUT); + pinMode(DISP_DC, OUTPUT); + digitalWrite(32, HIGH); // Keep reset pin high + digitalWrite(33, HIGH); // Set data mode to "Command" + gfx->begin(); // Start the screen object + gfx->fillScreen(BLACK); // "Clear" the screen + gfx->setCursor(5, 15); // Set print pointer to top left corner + gfx->setFont(&FreeMono12pt7b); // Set font + gfx->setTextColor(RED); // Set color + gfx->println("Hello world!"); + delay(1000); + + gfx->println("bababooba"); +} + +// Clear screen and reset cursor +void disp_clr(){ + gfx->fillScreen(BLACK); // "Clear" the screen + gfx->setCursor(5, 15); // Set print pointer to top left corner +} + +// print line of text on screen +void disp_println(String string){ + gfx->println(string); +} + +// print text on screen +void disp_print(String string){ + gfx->print(string); +} + +// Set cursor location on screen +void disp_setCursor(int16_t x, int16_t y){ + gfx->setCursor(x,y); +} + +void disp_setTextColor(int16_t COLOR){ + gfx->setTextColor(COLOR); +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index d8c996b..73fa553 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,19 +1,10 @@ #include #include "TalkyBoi.h" -<<<<<<< HEAD - -// Pin connected to voltage divider output. used for analogRead to get resistance of the flexsensors -const int s0 = 25; -const int s1 = 26; -const int s2 = 27; -const int s3 = 14; -const int SIG_pin = 34; -======= #include "config.h" #include "flexSensor.h" #include "potentiometer.h" +#include "display.h" ->>>>>>> 73866abe72aa3be213d0691ab3777286f6b7531b /* const uint8_t thumbIP_Pin = ads1118.AIN_0; @@ -132,16 +123,9 @@ void setup() { delay(100); // getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. // init_wifi(); // Initiate ESP_NOW - initBoard(); // Initiate breakout board + initBoard(); // Initiate breakout board + disp_initialize(); //attachInterrupt(17, interuptFunc, HIGH); // interupt for start/stop button - Serial.println("calibration 1"); - hej123.calibrate(false); - delay(2000); - Serial.println("calibration 2"); - delay(2000); - hej123.calibrate(true); - delay(2000); - Serial.println("done"); } void loop() { @@ -150,20 +134,7 @@ void loop() { send(sendID, fingerAngles[0], fingerAngles[1], fingerAngles[2], fingerAngles[3], fingerAngles[4], fingerAngles[5], fingerAngles[6], fingerAngles[7], fingerAngles[8], fingerAngles[9]); */ - /*int val1 = readMux(0); - int val2 = readMux(1); - Serial.print("val 1: "); - Serial.print(val1); - Serial.print(" val 2: "); - Serial.println(val2);*/ - - Serial.print(hej123.getValue()); - Serial.print(" // "); - Serial.print(hej123.getAngle()); - Serial.print(" // "); - Serial.print(hej123.getCalibrateOpen()); - Serial.print(" // "); - Serial.println(hej123.getCalibrateClosed()); + disp_println("123454321"); delay(100); } diff --git a/src/sensorClass.cpp b/src/sensorClass.cpp index 2559933..f4df918 100644 --- a/src/sensorClass.cpp +++ b/src/sensorClass.cpp @@ -42,11 +42,12 @@ float sensor::getAngle(){ */ float sensor::getResistance(int pin){ - float Vflex; + float Vflex = 0.0; //Vflex = ads1118.getMilliVolts(pin) / 1000.0; - float Rflex = R_DIV * (VCC / Vflex - 1.0); + //float Rflex = R_DIV * (VCC / Vflex - 1.0); + float Rflex = 0.0; return Rflex; } From 2acc3a76af1822e1f007b7bfa90859bc1d2dad71 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Thu, 31 Mar 2022 15:44:53 +0200 Subject: [PATCH 21/48] created calibrateFlexSensors() method in main + various small fixes --- src/flexSensor.cpp | 2 ++ src/main.cpp | 31 +++++++++++++++++++++++++++++-- src/potentiometer.cpp | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/flexSensor.cpp b/src/flexSensor.cpp index 3b67da6..94084b3 100644 --- a/src/flexSensor.cpp +++ b/src/flexSensor.cpp @@ -96,10 +96,12 @@ void flexSensor::calibrate(bool state){ } +// returns value of calibrateClosed int flexSensor::getCalibrateClosed(){ return calibrateClosed; } +// returns value of calibrateOpen int flexSensor::getCalibrateOpen(){ return calibrateOpen; } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 73fa553..1cd4ec2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -139,5 +139,32 @@ void loop() { } - - +/*Calibrates all 10 flex sensors for flexion movement. First hold hand open until OK + is printed and then have hand closed until OK is printed again */ +void calibrateFlexSensors(){ + Serial.println("HAND OPEN"); + disp_clr(); + disp_setTextColor(RED); + disp_println("HAND OPEN"); + delay(1000); + for(int i = 0; i<10 ; i++){ + pinList[i].calibrate(false); + } + Serial.println("OK"); + disp_setTextColor(GREEN); + disp_println("OK"); + delay(2000); + Serial.println("HAND CLOSED"); + disp_clr(); + disp_setTextColor(RED); + disp_println("HAND CLOSED"); + delay(1000); + for(int i = 0; i<10 ; i++){ + pinList[i].calibrate(true); + } + Serial.println("OK"); + disp_setTextColor(GREEN); + disp_println("OK"); + delay(2000); + disp_clr(); +} \ No newline at end of file diff --git a/src/potentiometer.cpp b/src/potentiometer.cpp index 69d4309..6524388 100644 --- a/src/potentiometer.cpp +++ b/src/potentiometer.cpp @@ -80,7 +80,7 @@ float potentiometer::getAngle(){ } -// Calibrates the flex sensor, either the minimum or maximum angle state depending on input +// Calibrates the potentiometer, either the minimum or maximum angle state depending on input void potentiometer::calibrate(bool state){ for(int i = 0; i < 2*SAMPLES; i++){ m_f.addSample(readMux(m_channel)); From 89a14a8132d2b0fe4bfcefe7a66d152b3576cc3c Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Thu, 31 Mar 2022 17:06:01 +0200 Subject: [PATCH 22/48] Improved calibrateFlexion() and other small fixes --- src/config.h | 3 ++ src/display.h | 11 ++---- src/flexSensor.cpp | 1 - src/main.cpp | 94 ++++++++++++++++++++++++++++++---------------- 4 files changed, 67 insertions(+), 42 deletions(-) diff --git a/src/config.h b/src/config.h index fb06c3d..0db6fcb 100644 --- a/src/config.h +++ b/src/config.h @@ -14,6 +14,9 @@ // Connection for pins on display #define DISP_RES 32 #define DISP_DC 33 +#define DISP_CS 5 +#define DISP_SCK 18 +#define DISP_MOSI 23 // Number of samples for the median filter const int SAMPLES = 20; diff --git a/src/display.h b/src/display.h index f7aeccc..b896652 100644 --- a/src/display.h +++ b/src/display.h @@ -4,7 +4,7 @@ #include "config.h" // Screen setup -Arduino_DataBus *bus = new Arduino_ESP32SPI(33 /* DC */, 5 /* CS */, 18 /* SCK */, 23 /* MOSI */, -1 /* MISO */, VSPI /* spi_num */); +Arduino_DataBus *bus = new Arduino_ESP32SPI(DISP_DC /* DC */, DISP_CS /* CS */, DISP_SCK /* SCK */, DISP_MOSI /* MOSI */, -1 /* MISO */, VSPI /* spi_num */); //Arduino_DataBus *bus = new Arduino_ESP32SPI(33 /* DC */, 5 /* CS */, 18 /* SCK */, 23 /* MOSI */, 19 /* MISO */); Arduino_GFX *gfx = new Arduino_ST7789(bus, 7 /* RST */, 0 /* rotation */, true /* IPS */, 240 /* width */, 240 /* height */, 0 /* col offset 1 */, 0 /* row offset 1 */); @@ -13,17 +13,12 @@ void disp_initialize(){ // Screen setup pinMode(DISP_RES, OUTPUT); pinMode(DISP_DC, OUTPUT); - digitalWrite(32, HIGH); // Keep reset pin high - digitalWrite(33, HIGH); // Set data mode to "Command" + digitalWrite(DISP_RES, HIGH); // Keep reset pin high + digitalWrite(DISP_RES, HIGH); // Set data mode to "Command" gfx->begin(); // Start the screen object gfx->fillScreen(BLACK); // "Clear" the screen gfx->setCursor(5, 15); // Set print pointer to top left corner gfx->setFont(&FreeMono12pt7b); // Set font - gfx->setTextColor(RED); // Set color - gfx->println("Hello world!"); - delay(1000); - - gfx->println("bababooba"); } // Clear screen and reset cursor diff --git a/src/flexSensor.cpp b/src/flexSensor.cpp index 94084b3..5b8bd20 100644 --- a/src/flexSensor.cpp +++ b/src/flexSensor.cpp @@ -83,7 +83,6 @@ void flexSensor::calibrate(bool state){ for(int i = 0; i < 2*SAMPLES; i++){ m_f.addSample(readMux(m_channel)); - delay(20); } if(!state){ diff --git a/src/main.cpp b/src/main.cpp index 1cd4ec2..55efc82 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,7 @@ int sendID = 0; int buttonRun = 0; int state = 0; +int calibrateState = 0; flexSensor thumbIP = flexSensor(0); flexSensor thumbMCP = flexSensor(1); @@ -97,7 +98,17 @@ int readMux(int channel){ return val; } - +/** + * Interupt function for the initial calibration. +*/ +void interuptCalibrate(){ + static unsigned long last_interuptTime = 0; + unsigned long interupt_time = millis(); + if((interupt_time - last_interuptTime) > 200){ + calibrateState++; + } + last_interuptTime = interupt_time; +} /** * Toggles the state of the microcontroller. @@ -117,6 +128,52 @@ void interuptFunc(){ last_interuptTime = interupt_time; } +/*Calibrates all 10 flex sensors for flexion movement. First hold hand open until OK + is printed and then have hand closed until OK is printed again */ +void calibrateFlexion(){ + attachInterrupt(16,interuptCalibrate,RISING); + Serial.println("Flexion Calibr."); + disp_clr(); + disp_setTextColor(WHITE); + disp_println("Flexion Calibr."); + disp_println("----------------"); + while(calibrateState < 1){delay(10);} + Serial.println("HAND OPEN"); + disp_setTextColor(RED); + disp_print("HAND OPEN"); + delay(1000); + for(int i = 0; i<10 ; i++){ + pinList[i].calibrate(false); + } + Serial.println("OK"); + disp_setTextColor(GREEN); + disp_println(" OK"); + while(calibrateState < 2){delay(10);} + disp_setTextColor(WHITE); + disp_println("-----"); + delay(100); + disp_setTextColor(RED); + Serial.println("HAND CLOSED"); + disp_print("HAND CLOSED"); + for(int i = 0; i<10 ; i++){ + pinList[i].calibrate(true); + } + Serial.println("OK"); + disp_setTextColor(GREEN); + disp_println(" OK"); + delay(100); + disp_setTextColor(WHITE); + disp_println("-----"); + delay(100); + disp_println("CALIBRATION"); + disp_println("COMPLETE"); + while(calibrateState < 3){delay(10);} + calibrateState = 0; + attachInterrupt(17,interuptFunc,HIGH); + disp_clr(); +} + + void setup() { Serial.begin(115200); @@ -125,7 +182,9 @@ void setup() { // init_wifi(); // Initiate ESP_NOW initBoard(); // Initiate breakout board disp_initialize(); - //attachInterrupt(17, interuptFunc, HIGH); // interupt for start/stop button + attachInterrupt(17, interuptFunc, HIGH); // interupt for start/stop button + calibrateFlexion(); + } void loop() { @@ -134,37 +193,6 @@ void loop() { send(sendID, fingerAngles[0], fingerAngles[1], fingerAngles[2], fingerAngles[3], fingerAngles[4], fingerAngles[5], fingerAngles[6], fingerAngles[7], fingerAngles[8], fingerAngles[9]); */ - disp_println("123454321"); - delay(100); } -/*Calibrates all 10 flex sensors for flexion movement. First hold hand open until OK - is printed and then have hand closed until OK is printed again */ -void calibrateFlexSensors(){ - Serial.println("HAND OPEN"); - disp_clr(); - disp_setTextColor(RED); - disp_println("HAND OPEN"); - delay(1000); - for(int i = 0; i<10 ; i++){ - pinList[i].calibrate(false); - } - Serial.println("OK"); - disp_setTextColor(GREEN); - disp_println("OK"); - delay(2000); - Serial.println("HAND CLOSED"); - disp_clr(); - disp_setTextColor(RED); - disp_println("HAND CLOSED"); - delay(1000); - for(int i = 0; i<10 ; i++){ - pinList[i].calibrate(true); - } - Serial.println("OK"); - disp_setTextColor(GREEN); - disp_println("OK"); - delay(2000); - disp_clr(); -} \ No newline at end of file From ad636e47d31be15ca50efbdf83d4914acea8c741 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Fri, 1 Apr 2022 11:19:47 +0200 Subject: [PATCH 23/48] created calibrateAbduction() method --- .vscode/settings.json | 6 ++++ src/display.h | 8 +++++ src/main.cpp | 69 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a71b9a4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "string_view": "cpp", + "regex": "cpp" + } +} \ No newline at end of file diff --git a/src/display.h b/src/display.h index b896652..6f74c64 100644 --- a/src/display.h +++ b/src/display.h @@ -37,6 +37,14 @@ void disp_print(String string){ gfx->print(string); } +void disp_println(int num){ + gfx->println(num); +} + +void disp_print(int num){ + gfx->print(num); +} + // Set cursor location on screen void disp_setCursor(int16_t x, int16_t y){ gfx->setCursor(x,y); diff --git a/src/main.cpp b/src/main.cpp index 55efc82..58aa2b4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,8 +38,13 @@ flexSensor f3PIP = flexSensor(6); flexSensor f3MCP = flexSensor(7); flexSensor f4PIP = flexSensor(8); flexSensor f4MCP = flexSensor(9); +potentiometer f1AD = potentiometer(10); +potentiometer f2AD = potentiometer(11); +potentiometer f3AD = potentiometer(12); +potentiometer f4AD = potentiometer(13); flexSensor pinList[] = {thumbIP, thumbMCP, f1PIP, f1MCP, f2PIP, f2MCP, f3PIP, f3MCP, f4PIP, f4MCP}; +potentiometer potList[4] = {f1AD,f2AD,f3AD,f4AD}; const int sizeList = sizeof(pinList)/sizeof(int); float fingerAngles[10] = {0,0,0,0,0,0,0,0,0,0}; @@ -102,7 +107,7 @@ int readMux(int channel){ * Interupt function for the initial calibration. */ void interuptCalibrate(){ - static unsigned long last_interuptTime = 0; + static unsigned long last_interuptTime = 0; unsigned long interupt_time = millis(); if((interupt_time - last_interuptTime) > 200){ calibrateState++; @@ -137,7 +142,7 @@ void calibrateFlexion(){ disp_setTextColor(WHITE); disp_println("Flexion Calibr."); disp_println("----------------"); - while(calibrateState < 1){delay(10);} + while(calibrateState < 1){delay(50);} Serial.println("HAND OPEN"); disp_setTextColor(RED); disp_print("HAND OPEN"); @@ -148,7 +153,7 @@ void calibrateFlexion(){ Serial.println("OK"); disp_setTextColor(GREEN); disp_println(" OK"); - while(calibrateState < 2){delay(10);} + while(calibrateState < 2){delay(50);} disp_setTextColor(WHITE); disp_println("-----"); delay(100); @@ -167,13 +172,63 @@ void calibrateFlexion(){ delay(100); disp_println("CALIBRATION"); disp_println("COMPLETE"); - while(calibrateState < 3){delay(10);} + while(calibrateState < 3){delay(50);} calibrateState = 0; - attachInterrupt(17,interuptFunc,HIGH); disp_clr(); + attachInterrupt(17,interuptFunc,HIGH); } - +/* Calibrates potentiometers for measuring abduction and adduction of fingers. + Each finger is calibrated individually with instructions printed on the display */ +void calibrateAbduction(){ + attachInterrupt(16,interuptCalibrate,RISING); + for(int i = 0; i < sizeof(potList)/sizeof(potList[i]); i++){ + disp_clr(); + disp_setTextColor(WHITE); + disp_println("Abduct. Calibr."); + disp_println("----------------"); + disp_print("keep F"); + disp_print(i+1); + disp_println(" left"); + Serial.println("Abduct. Calibr."); + Serial.print("keep F"); + Serial.print(i+1); + Serial.println(" left"); + Serial.print(sizeof(potList)); + while(calibrateState < i+1){delay(50);} + + potList[i].calibrate(false); + disp_setTextColor(GREEN); + Serial.println("OK"); + disp_println("OK"); + delay(100); + disp_setTextColor(WHITE); + disp_println("-----"); + disp_print("keep F"); + disp_print(i+1); + disp_println(" right"); + Serial.print("keep F"); + Serial.print(i+1); + Serial.print(" right"); + while(calibrateState < i+2){delay(50);} + + potList[i].calibrate(true); + disp_setTextColor(GREEN); + disp_println("OK"); + Serial.println("OK"); + delay(100); + disp_setTextColor(WHITE); + disp_println("-----"); + delay(500); + } + disp_println("CALIBRATION"); + disp_println("COMPLETE"); + Serial.println("CALIBRATION COMPLETE"); + while(calibrateState < 3){delay(50);} + calibrateState = 0; + disp_clr(); + attachInterrupt(17,interuptFunc,HIGH); +} void setup() { Serial.begin(115200); @@ -183,7 +238,7 @@ void setup() { initBoard(); // Initiate breakout board disp_initialize(); attachInterrupt(17, interuptFunc, HIGH); // interupt for start/stop button - calibrateFlexion(); + calibrateAbduction(); } From a5faec55faf0a629b760f5193c86c0dce27a7149 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Fri, 1 Apr 2022 14:29:34 +0200 Subject: [PATCH 24/48] improved flexSensor and potentiometer flexSensor and potentiometer classes can now be connected to both multiplexer as well as directly to esp32, though not at the same time. This is specified when constructing the object --- src/flexSensor.cpp | 48 ++++++++++++++++++++++++++++++++++++------- src/flexSensor.h | 4 +++- src/main.cpp | 15 +++++++------- src/potentiometer.cpp | 44 ++++++++++++++++++++++++++++----------- src/potentiometer.h | 4 +++- 5 files changed, 86 insertions(+), 29 deletions(-) diff --git a/src/flexSensor.cpp b/src/flexSensor.cpp index 5b8bd20..f1c3d1b 100644 --- a/src/flexSensor.cpp +++ b/src/flexSensor.cpp @@ -13,20 +13,37 @@ * @param channel the channel to which the flex sensor is connected to. * @param minimum_angle the minimum angle of flex sensor. * @param maximum_angle the maximum angle of flex sensor. + * @param multipl boolean that states whether the flex sensor is connected to the multiplexer or directly to the esp32. */ flexSensor::flexSensor(int channel, int minimum_angle, int maximum_angle){ + multipl = true; m_channel = channel; min_angle = minimum_angle; max_angle = maximum_angle; } flexSensor::flexSensor(int channel){ + multipl = true; m_channel = channel; min_angle = 0; max_angle = 90; } +flexSensor::flexSensor(bool multiplexer, int pin, int minimum_angle, int maximum_angle){ + multipl = multiplexer; + m_channel = pin; + min_angle = minimum_angle; + max_angle = maximum_angle; +} + +flexSensor::flexSensor(bool multiplexer, int pin){ + multipl = multiplexer; + m_channel = pin; + min_angle = 0; + max_angle = 90; +} + // Changes multiplexer to read from int channel and then returns the read value int flexSensor::readMux(int channel){ int controlPin[] = {s0, s1, s2, s3}; @@ -63,7 +80,13 @@ int flexSensor::readMux(int channel){ } int flexSensor::getValue(){ + if(multipl){ return readMux(m_channel); + } + else{ + return analogRead(m_channel); + } + } @@ -72,27 +95,38 @@ int flexSensor::getValue(){ * @return a float with the median angle value. */ float flexSensor::getAngle(){ - float angle = map(readMux(m_channel),calibrateOpen,calibrateClosed,min_angle,max_angle); - m_f.addSample(angle); - return m_f.getMedian(); + float angle; + if(multipl){ + angle = map(readMux(m_channel),calibrateOpen,calibrateClosed,min_angle,max_angle); + } + else{ + angle = map(analogRead(m_channel),calibrateOpen,calibrateClosed,min_angle,max_angle); + } + m_f.addSample(angle); + return m_f.getMedian(); } // Calibrates the flex sensor, either the open or closed state depending on input void flexSensor::calibrate(bool state){ - for(int i = 0; i < 2*SAMPLES; i++){ - m_f.addSample(readMux(m_channel)); + if(multipl){ + for(int i = 0; i < 2*SAMPLES; i++){ + m_f.addSample(readMux(m_channel)); + } + } + else{ + for(int i = 0; i < 2*SAMPLES; i++){ + m_f.addSample(analogRead(m_channel)); + } } if(!state){ calibrateOpen = m_f.getMedian(); } - else{ calibrateClosed = m_f.getMedian(); } - } // returns value of calibrateClosed diff --git a/src/flexSensor.h b/src/flexSensor.h index 4b33ec0..134f361 100644 --- a/src/flexSensor.h +++ b/src/flexSensor.h @@ -19,14 +19,16 @@ class flexSensor{ int max_angle; int calibrateOpen; int calibrateClosed; + bool multipl; // Number of samples are defined in config.h MedianFilter m_f; // Methods - float getResistance(int); int readMux(int); public: flexSensor(int channel, int minimum_angle, int maximum_angle); flexSensor(int channel); + flexSensor(bool multiplexer, int pin, int minimum_angle, int maximum_angle); + flexSensor(bool multiplexer, int pin); // Methods int getValue(); float getAngle(); diff --git a/src/main.cpp b/src/main.cpp index 58aa2b4..9b85c06 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,7 +46,7 @@ potentiometer f4AD = potentiometer(13); flexSensor pinList[] = {thumbIP, thumbMCP, f1PIP, f1MCP, f2PIP, f2MCP, f3PIP, f3MCP, f4PIP, f4MCP}; potentiometer potList[4] = {f1AD,f2AD,f3AD,f4AD}; const int sizeList = sizeof(pinList)/sizeof(int); -float fingerAngles[10] = {0,0,0,0,0,0,0,0,0,0}; +float fingerAngles[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // Initiates the ADC breakout board. /* @@ -142,24 +142,23 @@ void calibrateFlexion(){ disp_setTextColor(WHITE); disp_println("Flexion Calibr."); disp_println("----------------"); - while(calibrateState < 1){delay(50);} Serial.println("HAND OPEN"); disp_setTextColor(RED); disp_print("HAND OPEN"); - delay(1000); + while(calibrateState < 1){delay(50);} for(int i = 0; i<10 ; i++){ pinList[i].calibrate(false); } Serial.println("OK"); disp_setTextColor(GREEN); disp_println(" OK"); - while(calibrateState < 2){delay(50);} + delay(100); disp_setTextColor(WHITE); disp_println("-----"); - delay(100); disp_setTextColor(RED); Serial.println("HAND CLOSED"); disp_print("HAND CLOSED"); + while(calibrateState < 2){delay(50);} for(int i = 0; i<10 ; i++){ pinList[i].calibrate(true); } @@ -236,10 +235,10 @@ void setup() { // getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. // init_wifi(); // Initiate ESP_NOW initBoard(); // Initiate breakout board - disp_initialize(); + disp_initialize(); // Initialise display attachInterrupt(17, interuptFunc, HIGH); // interupt for start/stop button - calibrateAbduction(); - + calibrateFlexion(); // Calibrate flextion movement of fingers + calibrateAbduction(); // Calibrate abduction and adduction movement of fingers } void loop() { diff --git a/src/potentiometer.cpp b/src/potentiometer.cpp index 6524388..9d184c2 100644 --- a/src/potentiometer.cpp +++ b/src/potentiometer.cpp @@ -14,18 +14,21 @@ * @param channel the channel to which the flex sensor is connected to. * @param minimum_angle the minimum angle of flex sensor. * @param maximum_angle the maximum angle of flex sensor. + * @param multipl boolean that states whether the potentiometer is connected to the multiplexer or directly to the esp32. */ potentiometer::potentiometer(int channel, int minimum_angle, int maximum_angle){ - m_channel = channel; - min_angle = minimum_angle; - max_angle = maximum_angle; + multipl = true; + m_channel = channel; + min_angle = minimum_angle; + max_angle = maximum_angle; } potentiometer::potentiometer(int channel){ - m_channel = channel; - min_angle = -15; - max_angle = 15; + multipl = true; + m_channel = channel; + min_angle = -15; + max_angle = 15; } // Changes multiplexer to read from int channel and then returns the read value @@ -65,7 +68,12 @@ int potentiometer::readMux(int channel){ // Returns value read from multiplexer at given channel (for debugging purposes mainly) int potentiometer::getValue(){ + if(multipl){ return readMux(m_channel); + } + else{ + return analogRead(m_channel); + } } @@ -74,17 +82,29 @@ int potentiometer::getValue(){ * @return a float with the median angle value. */ float potentiometer::getAngle(){ - float angle = map(readMux(m_channel), calibrateMin, calibrateMax, min_angle, max_angle); - m_f.addSample(angle); - return m_f.getMedian(); + float angle; + if(multipl){ + angle = map(readMux(m_channel), calibrateMin, calibrateMax, min_angle, max_angle); + } + else{ + angle = map(analogRead(m_channel), calibrateMin, calibrateMax, min_angle, max_angle); + } + m_f.addSample(angle); + return m_f.getMedian(); } // Calibrates the potentiometer, either the minimum or maximum angle state depending on input void potentiometer::calibrate(bool state){ -for(int i = 0; i < 2*SAMPLES; i++){ - m_f.addSample(readMux(m_channel)); - delay(20); + if(multipl){ + for(int i = 0; i < 2*SAMPLES; i++){ + m_f.addSample(readMux(m_channel)); + } + } + else{ + for(int i = 0; i < 2*SAMPLES; i++){ + m_f.addSample(analogRead(m_channel)); + } } if(!state){ diff --git a/src/potentiometer.h b/src/potentiometer.h index 60b359e..923d22e 100644 --- a/src/potentiometer.h +++ b/src/potentiometer.h @@ -19,14 +19,16 @@ class potentiometer{ int max_angle; int calibrateMin; int calibrateMax; + bool multipl; // Number of samples are defined in config.h MedianFilter m_f; // Methods - float getResistance(int); int readMux(int); public: potentiometer(int channel, int minimum_angle, int maximum_angle); potentiometer(int channel); + potentiometer(bool multiplexer, int pin, int minimum_angle, int maximum_angle); + potentiometer(bool multuplexer, int pin); // Methods int getValue(); float getAngle(); From aa6633fd4b55768458601ada9c8c4015b88a4767 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Fri, 1 Apr 2022 15:37:39 +0200 Subject: [PATCH 25/48] various small fixes and improvements --- src/display.h | 22 +++++++++++----------- src/main.cpp | 22 +++++++++++----------- src/potentiometer.cpp | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/display.h b/src/display.h index 6f74c64..4a206c7 100644 --- a/src/display.h +++ b/src/display.h @@ -9,8 +9,9 @@ Arduino_DataBus *bus = new Arduino_ESP32SPI(DISP_DC /* DC */, DISP_CS /* CS */, Arduino_GFX *gfx = new Arduino_ST7789(bus, 7 /* RST */, 0 /* rotation */, true /* IPS */, 240 /* width */, 240 /* height */, 0 /* col offset 1 */, 0 /* row offset 1 */); +// Initialises the display, must be called before using other methods. void disp_initialize(){ - // Screen setup + // Display setup pinMode(DISP_RES, OUTPUT); pinMode(DISP_DC, OUTPUT); digitalWrite(DISP_RES, HIGH); // Keep reset pin high @@ -21,35 +22,34 @@ void disp_initialize(){ gfx->setFont(&FreeMono12pt7b); // Set font } -// Clear screen and reset cursor +// Clear display and reset cursor void disp_clr(){ - gfx->fillScreen(BLACK); // "Clear" the screen + gfx->fillScreen(BLACK); // "Clear" the display gfx->setCursor(5, 15); // Set print pointer to top left corner } -// print line of text on screen +// Print line of text on display void disp_println(String string){ gfx->println(string); } - -// print text on screen -void disp_print(String string){ - gfx->print(string); -} - void disp_println(int num){ gfx->println(num); } +// Print text on display +void disp_print(String string){ + gfx->print(string); +} void disp_print(int num){ gfx->print(num); } -// Set cursor location on screen +// Set cursor location on display void disp_setCursor(int16_t x, int16_t y){ gfx->setCursor(x,y); } +// Set colour of text on display void disp_setTextColor(int16_t COLOR){ gfx->setTextColor(COLOR); } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 9b85c06..a790c49 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,15 +48,7 @@ potentiometer potList[4] = {f1AD,f2AD,f3AD,f4AD}; const int sizeList = sizeof(pinList)/sizeof(int); float fingerAngles[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - // Initiates the ADC breakout board. -/* -void initBoard2(){ - ads1118.begin(); // Initialize board - ads1118.setSamplingRate(ads1118.RATE_860SPS); // highest sampling rate possible - ads1118.setFullScaleRange(ads1118.FSR_4096); // 12 bit -} -*/ - + // Initiates the multiplexer. void initBoard(){ pinMode(s0, OUTPUT); pinMode(s1, OUTPUT); @@ -133,6 +125,15 @@ void interuptFunc(){ last_interuptTime = interupt_time; } +void display_angle(potentiometer sensor){ + disp_setTextColor(WHITE); + disp_println(sensor.getAngle()); +} +void display_angle(flexSensor sensor){ + disp_setTextColor(WHITE); + disp_println(sensor.getAngle()); +} + /*Calibrates all 10 flex sensors for flexion movement. First hold hand open until OK is printed and then have hand closed until OK is printed again */ void calibrateFlexion(){ @@ -143,7 +144,6 @@ void calibrateFlexion(){ disp_println("Flexion Calibr."); disp_println("----------------"); Serial.println("HAND OPEN"); - disp_setTextColor(RED); disp_print("HAND OPEN"); while(calibrateState < 1){delay(50);} for(int i = 0; i<10 ; i++){ @@ -155,7 +155,6 @@ void calibrateFlexion(){ delay(100); disp_setTextColor(WHITE); disp_println("-----"); - disp_setTextColor(RED); Serial.println("HAND CLOSED"); disp_print("HAND CLOSED"); while(calibrateState < 2){delay(50);} @@ -242,6 +241,7 @@ void setup() { } void loop() { + /* sendID++; diff --git a/src/potentiometer.cpp b/src/potentiometer.cpp index 9d184c2..230b16e 100644 --- a/src/potentiometer.cpp +++ b/src/potentiometer.cpp @@ -31,6 +31,20 @@ potentiometer::potentiometer(int channel){ max_angle = 15; } +potentiometer::potentiometer(bool multiplexer, int pin, int minimum_angle, int maximum_angle){ + multipl = multiplexer; + m_channel = pin; + min_angle = minimum_angle; + max_angle = maximum_angle; +} + +potentiometer::potentiometer(bool multiplexer, int pin){ + multipl = multiplexer; + m_channel = pin; + min_angle = -15; + max_angle = 15; +} + // Changes multiplexer to read from int channel and then returns the read value int potentiometer::readMux(int channel){ int controlPin[] = {s0, s1, s2, s3}; From 7943dc88b356b4f11ee4b3fbd7fc68d9cfba747b Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Mon, 4 Apr 2022 11:42:54 +0200 Subject: [PATCH 26/48] added and improved comments in flexsensor and freemono12pt7b and main --- src/FreeMono12pt7b.h | 3 +++ src/flexSensor.cpp | 25 ++++++++++++++----------- src/main.cpp | 25 ++++++++----------------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/FreeMono12pt7b.h b/src/FreeMono12pt7b.h index ccc0150..2fd6b2e 100644 --- a/src/FreeMono12pt7b.h +++ b/src/FreeMono12pt7b.h @@ -1,3 +1,6 @@ +/* + * THIS FILE + */ #ifndef FreeMono12pt7b_H #define FreeMono12pt7b_H diff --git a/src/flexSensor.cpp b/src/flexSensor.cpp index f1c3d1b..bc7eec4 100644 --- a/src/flexSensor.cpp +++ b/src/flexSensor.cpp @@ -15,36 +15,34 @@ * @param maximum_angle the maximum angle of flex sensor. * @param multipl boolean that states whether the flex sensor is connected to the multiplexer or directly to the esp32. */ - flexSensor::flexSensor(int channel, int minimum_angle, int maximum_angle){ multipl = true; m_channel = channel; min_angle = minimum_angle; max_angle = maximum_angle; } - flexSensor::flexSensor(int channel){ multipl = true; m_channel = channel; min_angle = 0; max_angle = 90; } - flexSensor::flexSensor(bool multiplexer, int pin, int minimum_angle, int maximum_angle){ multipl = multiplexer; m_channel = pin; min_angle = minimum_angle; max_angle = maximum_angle; } - flexSensor::flexSensor(bool multiplexer, int pin){ multipl = multiplexer; m_channel = pin; min_angle = 0; max_angle = 90; } - -// Changes multiplexer to read from int channel and then returns the read value +/** + * Changes multiplexer to read from int channel and then returns the read value. + * @return analog reading from multiplexer in input channel. +*/ int flexSensor::readMux(int channel){ int controlPin[] = {s0, s1, s2, s3}; @@ -106,8 +104,10 @@ float flexSensor::getAngle(){ return m_f.getMedian(); } - -// Calibrates the flex sensor, either the open or closed state depending on input +/** + * Calibrates the flex sensor, either the open or closed state depending on input + * @return void +*/ void flexSensor::calibrate(bool state){ if(multipl){ @@ -128,13 +128,16 @@ void flexSensor::calibrate(bool state){ calibrateClosed = m_f.getMedian(); } } - -// returns value of calibrateClosed +/** + * @returns value of calibrateClosed +*/ int flexSensor::getCalibrateClosed(){ return calibrateClosed; } -// returns value of calibrateOpen +/** + * @returns value of calibrateOpen +*/ int flexSensor::getCalibrateOpen(){ return calibrateOpen; } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index a790c49..15e7154 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,29 +5,13 @@ #include "potentiometer.h" #include "display.h" - -/* -const uint8_t thumbIP_Pin = ads1118.AIN_0; -const uint8_t thumbMCP_Pin = ads1118.AIN_1; -const uint8_t f1PIP_Pin = ads1118.AIN_2; -const uint8_t f1MCP_Pin = ads1118.AIN_3; -const int f2PIP_Pin = 36; -const int f2MCP_Pin = 39; -const int f3PIP_Pin = 32; -const int f3MCP_Pin = 33; -const int f4PIP_Pin = 34; -const int f4MCP_Pin = 35; -const int pinList[] = {thumbIP_Pin, thumbMCP_Pin, f1PIP_Pin, f1MCP_Pin, f2PIP_Pin, f2MCP_Pin, f3PIP_Pin, f3MCP_Pin, f4PIP_Pin, f4MCP_Pin}; -const int sizeList = sizeof(pinList)/sizeof(int); -float fingerAngles[10] = {0,0,0,0,0,0,0,0,0,0}; int sendID = 0; -*/ - int buttonRun = 0; int state = 0; int calibrateState = 0; +// Declaring all flexSensor objects flexSensor thumbIP = flexSensor(0); flexSensor thumbMCP = flexSensor(1); flexSensor f1PIP = flexSensor(2); @@ -38,14 +22,18 @@ flexSensor f3PIP = flexSensor(6); flexSensor f3MCP = flexSensor(7); flexSensor f4PIP = flexSensor(8); flexSensor f4MCP = flexSensor(9); + +// Declaring all potentiometer objects potentiometer f1AD = potentiometer(10); potentiometer f2AD = potentiometer(11); potentiometer f3AD = potentiometer(12); potentiometer f4AD = potentiometer(13); +// Creating list of flexSensor and list of potetiometer objects flexSensor pinList[] = {thumbIP, thumbMCP, f1PIP, f1MCP, f2PIP, f2MCP, f3PIP, f3MCP, f4PIP, f4MCP}; potentiometer potList[4] = {f1AD,f2AD,f3AD,f4AD}; const int sizeList = sizeof(pinList)/sizeof(int); +// List of angles of all joints in fingers float fingerAngles[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // Initiates the multiplexer. @@ -61,6 +49,9 @@ void initBoard(){ digitalWrite(s3, LOW); } +/* + * Takes in a given channel number and outputs a multiplexer reading from that given channel. + */ int readMux(int channel){ int controlPin[] = {s0, s1, s2, s3}; From 0da18fd87aed36a7f634ca40788d6b888dfd0565 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Mon, 4 Apr 2022 14:15:47 +0200 Subject: [PATCH 27/48] improved and added comments to potentiometer.cpp --- src/potentiometer.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/potentiometer.cpp b/src/potentiometer.cpp index 230b16e..023a8ae 100644 --- a/src/potentiometer.cpp +++ b/src/potentiometer.cpp @@ -16,28 +16,24 @@ * @param maximum_angle the maximum angle of flex sensor. * @param multipl boolean that states whether the potentiometer is connected to the multiplexer or directly to the esp32. */ - potentiometer::potentiometer(int channel, int minimum_angle, int maximum_angle){ multipl = true; m_channel = channel; min_angle = minimum_angle; max_angle = maximum_angle; } - potentiometer::potentiometer(int channel){ multipl = true; m_channel = channel; min_angle = -15; max_angle = 15; } - potentiometer::potentiometer(bool multiplexer, int pin, int minimum_angle, int maximum_angle){ multipl = multiplexer; m_channel = pin; min_angle = minimum_angle; max_angle = maximum_angle; } - potentiometer::potentiometer(bool multiplexer, int pin){ multipl = multiplexer; m_channel = pin; @@ -45,7 +41,10 @@ potentiometer::potentiometer(bool multiplexer, int pin){ max_angle = 15; } -// Changes multiplexer to read from int channel and then returns the read value +/** + * Changes multiplexer to read from int channel and then returns the read value. + * @return analog reading from multiplexer in input channel. +*/ int potentiometer::readMux(int channel){ int controlPin[] = {s0, s1, s2, s3}; @@ -108,7 +107,10 @@ float potentiometer::getAngle(){ } -// Calibrates the potentiometer, either the minimum or maximum angle state depending on input +/** + * Calibrates the potentiometer, either the min or max state depending on input. + * @return void +*/ void potentiometer::calibrate(bool state){ if(multipl){ for(int i = 0; i < 2*SAMPLES; i++){ @@ -131,12 +133,16 @@ void potentiometer::calibrate(bool state){ } -// Returns calibrateMax variable +/** + * @returns value of calibrateMax +*/ int potentiometer::getCalibrateMax(){ return calibrateMax; } -// Returns calibrateMin variable +/** + * @returns value of calibrateMin +*/ int potentiometer::getCalibrateMin(){ return calibrateMin; } \ No newline at end of file From a5f17b9d41f15f0bc415cec01ef24b5a709e0d82 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Tue, 5 Apr 2022 16:30:35 +0200 Subject: [PATCH 28/48] added comments and other small fixes --- src/FreeMono12pt7b.h | 4 ++-- src/display.h | 3 +++ src/flexSensor.cpp | 1 + src/main.cpp | 1 + src/potentiometer.cpp | 2 +- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/FreeMono12pt7b.h b/src/FreeMono12pt7b.h index 2fd6b2e..01446cd 100644 --- a/src/FreeMono12pt7b.h +++ b/src/FreeMono12pt7b.h @@ -1,6 +1,6 @@ /* - * THIS FILE - */ + * This is a library for the LCD-display which enables it to output text. +*/ #ifndef FreeMono12pt7b_H #define FreeMono12pt7b_H diff --git a/src/display.h b/src/display.h index 4a206c7..edf2ddc 100644 --- a/src/display.h +++ b/src/display.h @@ -1,3 +1,6 @@ +/* + * This header file is for seting up the LCD-display and creating methods to easily control the display from the main class. + */ #include #include #include "FreeMono12pt7b.h" diff --git a/src/flexSensor.cpp b/src/flexSensor.cpp index bc7eec4..63d9523 100644 --- a/src/flexSensor.cpp +++ b/src/flexSensor.cpp @@ -39,6 +39,7 @@ flexSensor::flexSensor(bool multiplexer, int pin){ min_angle = 0; max_angle = 90; } + /** * Changes multiplexer to read from int channel and then returns the read value. * @return analog reading from multiplexer in input channel. diff --git a/src/main.cpp b/src/main.cpp index 15e7154..e6e0c5f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -93,6 +93,7 @@ void interuptCalibrate(){ static unsigned long last_interuptTime = 0; unsigned long interupt_time = millis(); if((interupt_time - last_interuptTime) > 200){ + Serial.println("PUSH"); calibrateState++; } last_interuptTime = interupt_time; diff --git a/src/potentiometer.cpp b/src/potentiometer.cpp index 023a8ae..aaaeeea 100644 --- a/src/potentiometer.cpp +++ b/src/potentiometer.cpp @@ -1,6 +1,6 @@ /** * This class file is used to create potentiometer objects that handle all reading - * and filtering of each sensor signal.cha + * and filtering of each sensor signal. */ #include From 7bb9186272b42225c7827fddc9cd0d327fa534f8 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Thu, 14 Apr 2022 13:49:00 +0200 Subject: [PATCH 29/48] various small fixes --- src/flexSensor.cpp | 8 ++++++++ src/flexSensor.h | 2 ++ src/main.cpp | 26 ++++++++++++++++++++++---- src/potentiometer.cpp | 1 + 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/flexSensor.cpp b/src/flexSensor.cpp index 63d9523..975c701 100644 --- a/src/flexSensor.cpp +++ b/src/flexSensor.cpp @@ -141,4 +141,12 @@ int flexSensor::getCalibrateClosed(){ */ int flexSensor::getCalibrateOpen(){ return calibrateOpen; +} + +void flexSensor::setCalibrateClosed(int value){ + calibrateClosed = value; +} + +void flexSensor::setCalibrateOpen(int value){ + calibrateOpen = value; } \ No newline at end of file diff --git a/src/flexSensor.h b/src/flexSensor.h index 134f361..654742e 100644 --- a/src/flexSensor.h +++ b/src/flexSensor.h @@ -35,4 +35,6 @@ class flexSensor{ void calibrate(bool state); int getCalibrateOpen(); int getCalibrateClosed(); + void setCalibrateOpen(int value); + void setCalibrateClosed(int value); }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index e6e0c5f..b7f1dd3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,9 +10,13 @@ int sendID = 0; int buttonRun = 0; int state = 0; int calibrateState = 0; +int8_t disp_row_number; + +// test +flexSensor thumbIP = flexSensor(false,27); // Declaring all flexSensor objects -flexSensor thumbIP = flexSensor(0); +//flexSensor thumbIP = flexSensor(0); flexSensor thumbMCP = flexSensor(1); flexSensor f1PIP = flexSensor(2); flexSensor f1MCP = flexSensor(3); @@ -129,6 +133,7 @@ void display_angle(flexSensor sensor){ /*Calibrates all 10 flex sensors for flexion movement. First hold hand open until OK is printed and then have hand closed until OK is printed again */ void calibrateFlexion(){ + disp_clr(); attachInterrupt(16,interuptCalibrate,RISING); Serial.println("Flexion Calibr."); disp_clr(); @@ -140,6 +145,7 @@ void calibrateFlexion(){ while(calibrateState < 1){delay(50);} for(int i = 0; i<10 ; i++){ pinList[i].calibrate(false); + Serial.println(pinList[i].getCalibrateOpen()); } Serial.println("OK"); disp_setTextColor(GREEN); @@ -152,6 +158,7 @@ void calibrateFlexion(){ while(calibrateState < 2){delay(50);} for(int i = 0; i<10 ; i++){ pinList[i].calibrate(true); + Serial.println(pinList[i].getCalibrateClosed()); } Serial.println("OK"); disp_setTextColor(GREEN); @@ -172,6 +179,7 @@ void calibrateFlexion(){ Each finger is calibrated individually with instructions printed on the display */ void calibrateAbduction(){ attachInterrupt(16,interuptCalibrate,RISING); + disp_clr(); for(int i = 0; i < sizeof(potList)/sizeof(potList[i]); i++){ disp_clr(); disp_setTextColor(WHITE); @@ -227,18 +235,28 @@ void setup() { // init_wifi(); // Initiate ESP_NOW initBoard(); // Initiate breakout board disp_initialize(); // Initialise display - attachInterrupt(17, interuptFunc, HIGH); // interupt for start/stop button + //attachInterrupt(17, interuptFunc, HIGH); // interupt for start/stop button calibrateFlexion(); // Calibrate flextion movement of fingers - calibrateAbduction(); // Calibrate abduction and adduction movement of fingers + //calibrateAbduction(); // Calibrate abduction and adduction movement of fingers + + disp_row_number = 0; } void loop() { - /* sendID++; send(sendID, fingerAngles[0], fingerAngles[1], fingerAngles[2], fingerAngles[3], fingerAngles[4], fingerAngles[5], fingerAngles[6], fingerAngles[7], fingerAngles[8], fingerAngles[9]); */ + Serial.print(thumbIP.getValue()); + Serial.print(" :: "); + Serial.println(pinList[0].getAngle()); + disp_println(pinList[0].getAngle()); + disp_row_number ++; + if(disp_row_number >= 9){ + disp_clr(); + disp_row_number = 0; + } } diff --git a/src/potentiometer.cpp b/src/potentiometer.cpp index aaaeeea..76f93a6 100644 --- a/src/potentiometer.cpp +++ b/src/potentiometer.cpp @@ -44,6 +44,7 @@ potentiometer::potentiometer(bool multiplexer, int pin){ /** * Changes multiplexer to read from int channel and then returns the read value. * @return analog reading from multiplexer in input channel. + * this method is taken from http://adam-meyer.com/arduino/CD74HC4067 under MIT-License. */ int potentiometer::readMux(int channel){ int controlPin[] = {s0, s1, s2, s3}; From d2adda8af4d30d1ecad7d3e74c3f24b7e5eede2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Wed, 11 May 2022 18:51:34 +0200 Subject: [PATCH 30/48] Connected all the flexsensors, thumbs not working --- src/config.h | 16 +++++------ src/main.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 81 insertions(+), 16 deletions(-) diff --git a/src/config.h b/src/config.h index 0db6fcb..f152e07 100644 --- a/src/config.h +++ b/src/config.h @@ -5,15 +5,15 @@ #pragma once // Connection for pins on multiplexer -#define SIG_PIN 34 -#define s0 25 -#define s1 26 -#define s2 27 -#define s3 14 +#define SIG_PIN 36 +#define s0 26 +#define s1 27 +#define s2 14 +#define s3 12 // Connection for pins on display -#define DISP_RES 32 -#define DISP_DC 33 +#define DISP_RES 1 +#define DISP_DC 15 #define DISP_CS 5 #define DISP_SCK 18 #define DISP_MOSI 23 @@ -22,4 +22,4 @@ const int SAMPLES = 20; // Pin to the push button that turns the controller on -#define INTERUPT_PIN 16 \ No newline at end of file +#define INTERUPT_PIN 17 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index e6e0c5f..bbcf869 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -113,8 +113,10 @@ void interuptFunc(){ buttonRun = 1; state = 1; } + Serial.println("Button"); } last_interuptTime = interupt_time; + } void display_angle(potentiometer sensor){ @@ -129,7 +131,7 @@ void display_angle(flexSensor sensor){ /*Calibrates all 10 flex sensors for flexion movement. First hold hand open until OK is printed and then have hand closed until OK is printed again */ void calibrateFlexion(){ - attachInterrupt(16,interuptCalibrate,RISING); + attachInterrupt(INTERUPT_PIN,interuptCalibrate,RISING); Serial.println("Flexion Calibr."); disp_clr(); disp_setTextColor(WHITE); @@ -165,17 +167,18 @@ void calibrateFlexion(){ while(calibrateState < 3){delay(50);} calibrateState = 0; disp_clr(); - attachInterrupt(17,interuptFunc,HIGH); + attachInterrupt(INTERUPT_PIN,interuptFunc,HIGH); } /* Calibrates potentiometers for measuring abduction and adduction of fingers. Each finger is calibrated individually with instructions printed on the display */ void calibrateAbduction(){ - attachInterrupt(16,interuptCalibrate,RISING); + attachInterrupt(INTERUPT_PIN,interuptCalibrate,RISING); for(int i = 0; i < sizeof(potList)/sizeof(potList[i]); i++){ disp_clr(); disp_setTextColor(WHITE); disp_println("Abduct. Calibr."); + delay(500); disp_println("----------------"); disp_print("keep F"); disp_print(i+1); @@ -217,7 +220,7 @@ void calibrateAbduction(){ while(calibrateState < 3){delay(50);} calibrateState = 0; disp_clr(); - attachInterrupt(17,interuptFunc,HIGH); + attachInterrupt(INTERUPT_PIN,interuptFunc,HIGH); } void setup() { @@ -227,17 +230,79 @@ void setup() { // init_wifi(); // Initiate ESP_NOW initBoard(); // Initiate breakout board disp_initialize(); // Initialise display - attachInterrupt(17, interuptFunc, HIGH); // interupt for start/stop button - calibrateFlexion(); // Calibrate flextion movement of fingers - calibrateAbduction(); // Calibrate abduction and adduction movement of fingers + pinMode(INTERUPT_PIN,INPUT); + attachInterrupt(INTERUPT_PIN, interuptFunc, RISING); // interupt for start/stop button + //calibrateFlexion(); // Calibrate flextion movement of fingers + //alibrateAbduction(); // Calibrate abduction and adduction movement of fingers } void loop() { + //Serial.print("PIP 1:"); + //Serial.println(readMux(0)); + //Serial.print("MCP 1:"); + //Serial.println(readMux(1)); + //Serial.print("PIP 2:"); + //Serial.println(readMux(2)); + //Serial.print("MCP 3:"); + ///Serial.println(readMux(3)); + //Serial.print("PIP3 :"); + //Serial.println(readMux(4)); + //Serial.print("MCP4 :"); + //Serial.println(readMux(5)); + //Serial.print("PIP4 :"); + //Serial.println(readMux(6)); + //Serial.print("MCP4 :"); + //Serial.println(readMux(7)); + //Serial.print("Tomt :"); + //Serial.println(readMux(8)); + //Serial.print("TOMT :"); + //Serial.println(readMux(9)); + //Serial.print("Tomt :"); + //Serial.println(readMux(10)); + //Serial.print("ev pot :"); + //Serial.println(readMux(11)); + //Serial.print("ev pot :"); + //Serial.println(readMux(12)); + //Serial.print("ev pot :"); + //Serial.println(readMux(13)); + //Serial.print("ev pot :"); + //Serial.println(readMux(14)); + //Serial.print("ev pot :"); + //Serial.println(readMux(15)); + //Serial.print("MCP4 :"); + //Serial.println(readMux(16)); + + delay(100); + //f1PIP.getAngle(); + //Serial.print(readMux(3)); + //Serial.write(13); + //Serial.write(10); /* sendID++; - send(sendID, fingerAngles[0], fingerAngles[1], fingerAngles[2], fingerAngles[3], fingerAngles[4], fingerAngles[5], fingerAngles[6], fingerAngles[7], fingerAngles[8], fingerAngles[9]); + send(sendID, mf_thumbIP.getMedian(), mf_thumbMCP.getMedian(), mf_f1PIP.getMedian(), mf_f1MCP.getMedian(), mf_f2PIP.getMedian(), mf_f2MCP.getMedian(), mf_f3PIP.getMedian(), mf_f3MCP.getMedian(), mf_f4PIP.getMedian(), mf_f4MCP.getMedian()); + //send(sendID, getAngle(pinList[0],0,0),getAngle(pinList[1],1,1),getAngle(pinList[2],2,2),getAngle(pinList[3],3,3),getAngle(pinList[4],4,4),getAngle(pinList[5],5,5),getAngle(pinList[6],6,6),getAngle(pinList[7],7,7),getAngle(pinList[8],8,8),getAngle(pinList[9],9,9)); + /* + Serial.print(mf_thumbIP.getMedian()); + Serial.print(" "); + Serial.print(mf_thumbMCP.getMedian()); + Serial.print(" "); + Serial.print(mf_f1PIP.getMedian()); + Serial.print(" "); + Serial.print(mf_f1MCP.getMedian()); + Serial.print(" "); + Serial.print(mf_f2PIP.getMedian()); + Serial.print(" "); + Serial.print(mf_f2MCP.getMedian()); + Serial.print(" "); + Serial.print(mf_f3PIP.getMedian()); + Serial.print(" "); + Serial.print(mf_f3MCP.getMedian()); + Serial.print(" "); + Serial.print(mf_f4PIP.getMedian()); + Serial.print(" "); + Serial.println(mf_f4MCP.getMedian()); */ } From 31bf25c7bfdc0dac61706c80447143f9d7bd47b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Fri, 13 May 2022 17:10:55 +0200 Subject: [PATCH 31/48] Added serial prints for all fingers and potentiometers, also hardcoded values for pots. fix this later --- src/config.h | 2 +- src/main.cpp | 112 ++++++++++++++++++++++++------------------ src/potentiometer.cpp | 14 ++++++ src/potentiometer.h | 2 + 4 files changed, 81 insertions(+), 49 deletions(-) diff --git a/src/config.h b/src/config.h index f152e07..46fa15e 100644 --- a/src/config.h +++ b/src/config.h @@ -19,7 +19,7 @@ #define DISP_MOSI 23 // Number of samples for the median filter -const int SAMPLES = 20; +const int SAMPLES = 7; // Pin to the push button that turns the controller on #define INTERUPT_PIN 17 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index bbcf869..c6042d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -113,7 +113,7 @@ void interuptFunc(){ buttonRun = 1; state = 1; } - Serial.println("Button"); + //Serial.println("Button"); } last_interuptTime = interupt_time; @@ -167,7 +167,7 @@ void calibrateFlexion(){ while(calibrateState < 3){delay(50);} calibrateState = 0; disp_clr(); - attachInterrupt(INTERUPT_PIN,interuptFunc,HIGH); + detachInterrupt(INTERUPT_PIN); } /* Calibrates potentiometers for measuring abduction and adduction of fingers. @@ -220,7 +220,7 @@ void calibrateAbduction(){ while(calibrateState < 3){delay(50);} calibrateState = 0; disp_clr(); - attachInterrupt(INTERUPT_PIN,interuptFunc,HIGH); + detachInterrupt(INTERUPT_PIN); } void setup() { @@ -231,11 +231,21 @@ void setup() { initBoard(); // Initiate breakout board disp_initialize(); // Initialise display pinMode(INTERUPT_PIN,INPUT); - attachInterrupt(INTERUPT_PIN, interuptFunc, RISING); // interupt for start/stop button - //calibrateFlexion(); // Calibrate flextion movement of fingers - //alibrateAbduction(); // Calibrate abduction and adduction movement of fingers + // interupt for start/stop button + calibrateFlexion(); // Calibrate flextion movement of fingers + //calibrateAbduction(); // Calibrate abduction and adduction movement of fingers + + attachInterrupt(INTERUPT_PIN, interuptFunc, RISING); + + potList[1].setCalibrateMin(50); + potList[1].setCalibrateMax(105); + potList[2].setCalibrateMin(110); + potList[2].setCalibrateMax(240); + potList[3].setCalibrateMin(130); + potList[3].setCalibrateMax(200); } + void loop() { //Serial.print("PIP 1:"); //Serial.println(readMux(0)); @@ -243,67 +253,73 @@ void loop() { //Serial.println(readMux(1)); //Serial.print("PIP 2:"); //Serial.println(readMux(2)); - //Serial.print("MCP 3:"); - ///Serial.println(readMux(3)); + //Serial.print("MCP 2:"); + //Serial.println(readMux(3)); //Serial.print("PIP3 :"); //Serial.println(readMux(4)); - //Serial.print("MCP4 :"); + //Serial.print("MCP3 :"); //Serial.println(readMux(5)); //Serial.print("PIP4 :"); //Serial.println(readMux(6)); //Serial.print("MCP4 :"); //Serial.println(readMux(7)); - //Serial.print("Tomt :"); + //Serial.print("tumme PIP :"); //Serial.println(readMux(8)); - //Serial.print("TOMT :"); + //Serial.print("tumme MCP :"); //Serial.println(readMux(9)); //Serial.print("Tomt :"); //Serial.println(readMux(10)); - //Serial.print("ev pot :"); + //Serial.print("pot 1:"); //Serial.println(readMux(11)); - //Serial.print("ev pot :"); + //Serial.print("pot 2:"); //Serial.println(readMux(12)); - //Serial.print("ev pot :"); + //Serial.print("pot :3"); //Serial.println(readMux(13)); - //Serial.print("ev pot :"); + //Serial.print("pot 4:"); //Serial.println(readMux(14)); - //Serial.print("ev pot :"); - //Serial.println(readMux(15)); - //Serial.print("MCP4 :"); - //Serial.println(readMux(16)); - delay(100); - //f1PIP.getAngle(); + /* + Serial.print("ev pot :"); + Serial.println(readMux(15)); + Serial.print("tomt :"); + Serial.println(readMux(16)); + */ - //Serial.print(readMux(3)); + //Serial.println(readMux(11)); + //Serial.print(potList[1].getAngle()); //Serial.write(13); //Serial.write(10); - /* - sendID++; + + //sendID++; - send(sendID, mf_thumbIP.getMedian(), mf_thumbMCP.getMedian(), mf_f1PIP.getMedian(), mf_f1MCP.getMedian(), mf_f2PIP.getMedian(), mf_f2MCP.getMedian(), mf_f3PIP.getMedian(), mf_f3MCP.getMedian(), mf_f4PIP.getMedian(), mf_f4MCP.getMedian()); + //send(sendID, mf_thumbIP.getMedian(), mf_thumbMCP.getMedian(), mf_f1PIP.getMedian(), mf_f1MCP.getMedian(), mf_f2PIP.getMedian(), mf_f2MCP.getMedian(), mf_f3PIP.getMedian(), mf_f3MCP.getMedian(), mf_f4PIP.getMedian(), mf_f4MCP.getMedian()); //send(sendID, getAngle(pinList[0],0,0),getAngle(pinList[1],1,1),getAngle(pinList[2],2,2),getAngle(pinList[3],3,3),getAngle(pinList[4],4,4),getAngle(pinList[5],5,5),getAngle(pinList[6],6,6),getAngle(pinList[7],7,7),getAngle(pinList[8],8,8),getAngle(pinList[9],9,9)); - /* - Serial.print(mf_thumbIP.getMedian()); - Serial.print(" "); - Serial.print(mf_thumbMCP.getMedian()); - Serial.print(" "); - Serial.print(mf_f1PIP.getMedian()); - Serial.print(" "); - Serial.print(mf_f1MCP.getMedian()); - Serial.print(" "); - Serial.print(mf_f2PIP.getMedian()); - Serial.print(" "); - Serial.print(mf_f2MCP.getMedian()); - Serial.print(" "); - Serial.print(mf_f3PIP.getMedian()); - Serial.print(" "); - Serial.print(mf_f3MCP.getMedian()); - Serial.print(" "); - Serial.print(mf_f4PIP.getMedian()); - Serial.print(" "); - Serial.println(mf_f4MCP.getMedian()); - */ - -} + int currentTime = millis(); + Serial.print(pinList[0].getAngle()); + Serial.print(","); + Serial.print(pinList[1].getAngle()); + Serial.print(","); + Serial.print(pinList[2].getAngle()); + Serial.print(","); + Serial.print(pinList[3].getAngle()); + Serial.print(","); + Serial.print(pinList[4].getAngle()); + Serial.print(","); + Serial.print(pinList[5].getAngle()); + Serial.print(","); + Serial.print(pinList[6].getAngle()); + Serial.print(","); + Serial.print(pinList[7].getAngle()); + Serial.print(","); + Serial.print(pinList[8].getAngle()); + Serial.print(","); + Serial.print(pinList[9].getAngle()); + Serial.print(","); + Serial.print(potList[1].getAngle()); + Serial.print(","); + Serial.print(potList[2].getAngle()); + Serial.print(","); + Serial.println(potList[3].getAngle()); +delay(40); +} \ No newline at end of file diff --git a/src/potentiometer.cpp b/src/potentiometer.cpp index 76f93a6..4f3b14a 100644 --- a/src/potentiometer.cpp +++ b/src/potentiometer.cpp @@ -146,4 +146,18 @@ int potentiometer::getCalibrateMax(){ */ int potentiometer::getCalibrateMin(){ return calibrateMin; +} + +/** + * sets value of calibrateMax +*/ +void potentiometer::setCalibrateMax(int val){ + calibrateMax = val; +} + +/** + * sets value of calibrateMin +*/ +void potentiometer::setCalibrateMin(int val){ + calibrateMin = val; } \ No newline at end of file diff --git a/src/potentiometer.h b/src/potentiometer.h index 923d22e..2ccfe72 100644 --- a/src/potentiometer.h +++ b/src/potentiometer.h @@ -35,4 +35,6 @@ class potentiometer{ void calibrate(bool state); int getCalibrateMin(); int getCalibrateMax(); + void setCalibrateMax(int val); + void setCalibrateMin(int val); }; \ No newline at end of file From aa52f16a25d3d2a6860c1ba5e711f82c974eb453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Fri, 13 May 2022 17:14:32 +0200 Subject: [PATCH 32/48] Added a possible fix for the pot calibration. --- src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index c6042d5..e3b2050 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -172,6 +172,10 @@ void calibrateFlexion(){ /* Calibrates potentiometers for measuring abduction and adduction of fingers. Each finger is calibrated individually with instructions printed on the display */ +/*Change calibration for abduction and adduction potentiometers +By calibrating a "middle value" and theneither add a value +- to that middle value. +or calibrate a motion to one side and then mirror that motion to the otehr side.*/ + void calibrateAbduction(){ attachInterrupt(INTERUPT_PIN,interuptCalibrate,RISING); for(int i = 0; i < sizeof(potList)/sizeof(potList[i]); i++){ From 490d7a4a6c553cd09e33f72b267ca79a0abeeea2 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Tue, 17 May 2022 13:54:29 +0200 Subject: [PATCH 33/48] created calibrateAbduction2() --- src/main.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index e3b2050..ad0d1d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -227,6 +227,34 @@ void calibrateAbduction(){ detachInterrupt(INTERUPT_PIN); } +void calibrateAbduction2(){ + attachInterrupt(INTERUPT_PIN,interuptCalibrate,RISING); + + Serial.println("Put hand in neutral position"); + while(calibrateState < 1){delay(50);} + int pot0_mean = potList[0].getValue(); + int pot1_mean = potList[1].getValue(); + int pot2_mean = potList[2].getValue(); + int pot3_mean = potList[3].getValue(); + Serial.println("DONE"); + delay(100); + + Serial.println("Put hand in abducted position"); + while(calibrateState < 2){delay(50);} + potList[0].calibrate(false); + potList[1].calibrate(false); + potList[2].calibrate(true); + potList[3].calibrate(true); + + potList[0].setCalibrateMax(2*pot0_mean - potList[0].getCalibrateMin()); + potList[0].setCalibrateMax(2*pot0_mean - potList[0].getCalibrateMin()); + potList[0].setCalibrateMin(2*pot0_mean - potList[0].getCalibrateMax()); + potList[0].setCalibrateMin(2*pot0_mean - potList[0].getCalibrateMax()); + Serial.println("Calibration complete"); + calibrateState = 0; + detachInterrupt(INTERUPT_PIN); +} + void setup() { Serial.begin(115200); delay(100); From c8459107af0998afe86f5703d0087a0996e14189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Tue, 17 May 2022 14:25:07 +0200 Subject: [PATCH 34/48] added pots --- src/main.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e3b2050..8aed34c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,16 +22,18 @@ flexSensor f3PIP = flexSensor(6); flexSensor f3MCP = flexSensor(7); flexSensor f4PIP = flexSensor(8); flexSensor f4MCP = flexSensor(9); +flexSensor opposition = flexSensor(10); // Declaring all potentiometer objects -potentiometer f1AD = potentiometer(10); -potentiometer f2AD = potentiometer(11); -potentiometer f3AD = potentiometer(12); -potentiometer f4AD = potentiometer(13); +potentiometer f1AD = potentiometer(11); +potentiometer f2AD = potentiometer(12); +potentiometer f3AD = potentiometer(13); +potentiometer f4AD = potentiometer(14); +potentiometer tAD = potentiometer(15); // Creating list of flexSensor and list of potetiometer objects -flexSensor pinList[] = {thumbIP, thumbMCP, f1PIP, f1MCP, f2PIP, f2MCP, f3PIP, f3MCP, f4PIP, f4MCP}; -potentiometer potList[4] = {f1AD,f2AD,f3AD,f4AD}; +flexSensor pinList[] = {thumbIP, thumbMCP, f1PIP, f1MCP, f2PIP, f2MCP, f3PIP, f3MCP, f4PIP, f4MCP, opposition}; +potentiometer potList[5] = {f1AD,f2AD,f3AD,f4AD,tAD}; const int sizeList = sizeof(pinList)/sizeof(int); // List of angles of all joints in fingers float fingerAngles[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; @@ -236,7 +238,7 @@ void setup() { disp_initialize(); // Initialise display pinMode(INTERUPT_PIN,INPUT); // interupt for start/stop button - calibrateFlexion(); // Calibrate flextion movement of fingers + //calibrateFlexion(); // Calibrate flextion movement of fingers //calibrateAbduction(); // Calibrate abduction and adduction movement of fingers attachInterrupt(INTERUPT_PIN, interuptFunc, RISING); @@ -299,7 +301,7 @@ void loop() { //send(sendID, mf_thumbIP.getMedian(), mf_thumbMCP.getMedian(), mf_f1PIP.getMedian(), mf_f1MCP.getMedian(), mf_f2PIP.getMedian(), mf_f2MCP.getMedian(), mf_f3PIP.getMedian(), mf_f3MCP.getMedian(), mf_f4PIP.getMedian(), mf_f4MCP.getMedian()); //send(sendID, getAngle(pinList[0],0,0),getAngle(pinList[1],1,1),getAngle(pinList[2],2,2),getAngle(pinList[3],3,3),getAngle(pinList[4],4,4),getAngle(pinList[5],5,5),getAngle(pinList[6],6,6),getAngle(pinList[7],7,7),getAngle(pinList[8],8,8),getAngle(pinList[9],9,9)); int currentTime = millis(); - Serial.print(pinList[0].getAngle()); + /*Serial.print(pinList[0].getAngle()); Serial.print(","); Serial.print(pinList[1].getAngle()); Serial.print(","); @@ -323,7 +325,8 @@ void loop() { Serial.print(","); Serial.print(potList[2].getAngle()); Serial.print(","); - Serial.println(potList[3].getAngle()); + Serial.println(potList[3].getAngle());*/ + Serial.println(potList[4].getValue()); delay(40); } \ No newline at end of file From d9eaf009be7b8e0342e207afd8f0b9464b8ad250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Tue, 17 May 2022 14:46:07 +0200 Subject: [PATCH 35/48] Stuff --- src/main.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 86a5bdf..e59a4ab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -266,7 +266,8 @@ void setup() { disp_initialize(); // Initialise display pinMode(INTERUPT_PIN,INPUT); // interupt for start/stop button - //calibrateFlexion(); // Calibrate flextion movement of fingers + calibrateFlexion(); + calibrateAbduction2(); // Calibrate flextion movement of fingers //calibrateAbduction(); // Calibrate abduction and adduction movement of fingers attachInterrupt(INTERUPT_PIN, interuptFunc, RISING); @@ -348,13 +349,16 @@ void loop() { Serial.print(pinList[8].getAngle()); Serial.print(","); Serial.print(pinList[9].getAngle()); + Serial.print(",");*/ + //Serial.print(pinList[10].getAngle()); + Serial.print(","); + Serial.print(potList[0].getAngle()); Serial.print(","); Serial.print(potList[1].getAngle()); Serial.print(","); Serial.print(potList[2].getAngle()); Serial.print(","); - Serial.println(potList[3].getAngle());*/ - Serial.println(potList[4].getValue()); + Serial.println(potList[3].getAngle()); delay(40); } \ No newline at end of file From edac76d4d6d5af9d16776fdcf44dc1a812b0d2d5 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Tue, 17 May 2022 15:39:52 +0200 Subject: [PATCH 36/48] calibreteMean() method --- src/potentiometer.cpp | 13 +++++++++++++ src/potentiometer.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/src/potentiometer.cpp b/src/potentiometer.cpp index 4f3b14a..ae5d4ae 100644 --- a/src/potentiometer.cpp +++ b/src/potentiometer.cpp @@ -21,24 +21,28 @@ potentiometer::potentiometer(int channel, int minimum_angle, int maximum_angle){ m_channel = channel; min_angle = minimum_angle; max_angle = maximum_angle; + calibrateM = 0; } potentiometer::potentiometer(int channel){ multipl = true; m_channel = channel; min_angle = -15; max_angle = 15; + calibrateM = 0; } potentiometer::potentiometer(bool multiplexer, int pin, int minimum_angle, int maximum_angle){ multipl = multiplexer; m_channel = pin; min_angle = minimum_angle; max_angle = maximum_angle; + calibrateM = 0; } potentiometer::potentiometer(bool multiplexer, int pin){ multipl = multiplexer; m_channel = pin; min_angle = -15; max_angle = 15; + calibrateM = 0; } /** @@ -160,4 +164,13 @@ void potentiometer::setCalibrateMax(int val){ */ void potentiometer::setCalibrateMin(int val){ calibrateMin = val; +} + +void potentiometer::calibrateMean(int delta_min, int delta_max){ + for(int i = 0; i < 2*SAMPLES; i++){ + m_f.addSample(readMux(m_channel)); + } + calibrateM = m_f.getMedian(); + calibrateMin = calibrateMax - delta_min; + calibrateMax = calibrateMin - delta_max; } \ No newline at end of file diff --git a/src/potentiometer.h b/src/potentiometer.h index 2ccfe72..77b5e92 100644 --- a/src/potentiometer.h +++ b/src/potentiometer.h @@ -19,6 +19,7 @@ class potentiometer{ int max_angle; int calibrateMin; int calibrateMax; + int calibrateM; bool multipl; // Number of samples are defined in config.h MedianFilter m_f; @@ -37,4 +38,5 @@ class potentiometer{ int getCalibrateMax(); void setCalibrateMax(int val); void setCalibrateMin(int val); + void calibrateMean(); }; \ No newline at end of file From 5974d2701e98743934f109f869a4e490381ed04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Fri, 20 May 2022 09:52:23 +0200 Subject: [PATCH 37/48] Added stuff to talkyboii --- src/main.cpp | 54 ++++++++-------------------------------------------- 1 file changed, 8 insertions(+), 46 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e59a4ab..6441944 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -267,7 +267,7 @@ void setup() { pinMode(INTERUPT_PIN,INPUT); // interupt for start/stop button calibrateFlexion(); - calibrateAbduction2(); // Calibrate flextion movement of fingers + //calibrateAbduction2(); // Calibrate flextion movement of fingers //calibrateAbduction(); // Calibrate abduction and adduction movement of fingers attachInterrupt(INTERUPT_PIN, interuptFunc, RISING); @@ -282,43 +282,7 @@ void setup() { void loop() { - //Serial.print("PIP 1:"); - //Serial.println(readMux(0)); - //Serial.print("MCP 1:"); - //Serial.println(readMux(1)); - //Serial.print("PIP 2:"); - //Serial.println(readMux(2)); - //Serial.print("MCP 2:"); - //Serial.println(readMux(3)); - //Serial.print("PIP3 :"); - //Serial.println(readMux(4)); - //Serial.print("MCP3 :"); - //Serial.println(readMux(5)); - //Serial.print("PIP4 :"); - //Serial.println(readMux(6)); - //Serial.print("MCP4 :"); - //Serial.println(readMux(7)); - //Serial.print("tumme PIP :"); - //Serial.println(readMux(8)); - //Serial.print("tumme MCP :"); - //Serial.println(readMux(9)); - //Serial.print("Tomt :"); - //Serial.println(readMux(10)); - //Serial.print("pot 1:"); - //Serial.println(readMux(11)); - //Serial.print("pot 2:"); - //Serial.println(readMux(12)); - //Serial.print("pot :3"); - //Serial.println(readMux(13)); - //Serial.print("pot 4:"); - //Serial.println(readMux(14)); - - /* - Serial.print("ev pot :"); - Serial.println(readMux(15)); - Serial.print("tomt :"); - Serial.println(readMux(16)); - */ + //Serial.println(readMux(11)); //Serial.print(potList[1].getAngle()); @@ -326,10 +290,8 @@ void loop() { //Serial.write(10); //sendID++; - - //send(sendID, mf_thumbIP.getMedian(), mf_thumbMCP.getMedian(), mf_f1PIP.getMedian(), mf_f1MCP.getMedian(), mf_f2PIP.getMedian(), mf_f2MCP.getMedian(), mf_f3PIP.getMedian(), mf_f3MCP.getMedian(), mf_f4PIP.getMedian(), mf_f4MCP.getMedian()); //send(sendID, getAngle(pinList[0],0,0),getAngle(pinList[1],1,1),getAngle(pinList[2],2,2),getAngle(pinList[3],3,3),getAngle(pinList[4],4,4),getAngle(pinList[5],5,5),getAngle(pinList[6],6,6),getAngle(pinList[7],7,7),getAngle(pinList[8],8,8),getAngle(pinList[9],9,9)); - int currentTime = millis(); + /*Serial.print(pinList[0].getAngle()); Serial.print(","); Serial.print(pinList[1].getAngle()); @@ -352,13 +314,13 @@ void loop() { Serial.print(",");*/ //Serial.print(pinList[10].getAngle()); Serial.print(","); - Serial.print(potList[0].getAngle()); - Serial.print(","); - Serial.print(potList[1].getAngle()); + Serial.print(potList[2].getValue()); Serial.print(","); - Serial.print(potList[2].getAngle()); + // Serial.print(potList[1].getAngle()); + //Serial.print(","); + //Serial.print(potList[2].getAngle()); Serial.print(","); - Serial.println(potList[3].getAngle()); + //Serial.println(potList[3].getAngle()); delay(40); } \ No newline at end of file From 714ea647f8b3e47d0919d268af53bbd2c7d5adc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Fri, 20 May 2022 14:19:34 +0200 Subject: [PATCH 38/48] Working on ESPNOW and add/abu --- src/main.cpp | 42 +++++++++++++++++++++--------------------- src/potentiometer.cpp | 4 ++-- src/potentiometer.h | 2 +- src/talkyBoi.h | 28 +++++++++++++--------------- 4 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6441944..e75cd88 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,10 +33,10 @@ potentiometer tAD = potentiometer(15); // Creating list of flexSensor and list of potetiometer objects flexSensor pinList[] = {thumbIP, thumbMCP, f1PIP, f1MCP, f2PIP, f2MCP, f3PIP, f3MCP, f4PIP, f4MCP, opposition}; -potentiometer potList[5] = {f1AD,f2AD,f3AD,f4AD,tAD}; +potentiometer potList[4] = {f1AD,f2AD,f3AD,f4AD}; const int sizeList = sizeof(pinList)/sizeof(int); // List of angles of all joints in fingers -float fingerAngles[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +float fingerAngles[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // Initiates the multiplexer. void initBoard(){ @@ -142,7 +142,7 @@ void calibrateFlexion(){ Serial.println("HAND OPEN"); disp_print("HAND OPEN"); while(calibrateState < 1){delay(50);} - for(int i = 0; i<10 ; i++){ + for(int i = 0; i<11 ; i++){ pinList[i].calibrate(false); } Serial.println("OK"); @@ -154,7 +154,7 @@ void calibrateFlexion(){ Serial.println("HAND CLOSED"); disp_print("HAND CLOSED"); while(calibrateState < 2){delay(50);} - for(int i = 0; i<10 ; i++){ + for(int i = 0; i<11 ; i++){ pinList[i].calibrate(true); } Serial.println("OK"); @@ -267,30 +267,31 @@ void setup() { pinMode(INTERUPT_PIN,INPUT); // interupt for start/stop button calibrateFlexion(); - //calibrateAbduction2(); // Calibrate flextion movement of fingers + calibrateAbduction2(); // Calibrate flextion movement of fingers //calibrateAbduction(); // Calibrate abduction and adduction movement of fingers attachInterrupt(INTERUPT_PIN, interuptFunc, RISING); - potList[1].setCalibrateMin(50); + /*potList[1].setCalibrateMin(50); potList[1].setCalibrateMax(105); potList[2].setCalibrateMin(110); potList[2].setCalibrateMax(240); potList[3].setCalibrateMin(130); - potList[3].setCalibrateMax(200); + potList[3].setCalibrateMax(200);*/ } void loop() { - - //Serial.println(readMux(11)); //Serial.print(potList[1].getAngle()); //Serial.write(13); //Serial.write(10); - + delay(20); //sendID++; - //send(sendID, getAngle(pinList[0],0,0),getAngle(pinList[1],1,1),getAngle(pinList[2],2,2),getAngle(pinList[3],3,3),getAngle(pinList[4],4,4),getAngle(pinList[5],5,5),getAngle(pinList[6],6,6),getAngle(pinList[7],7,7),getAngle(pinList[8],8,8),getAngle(pinList[9],9,9)); + /*send(sendID, pinList[0].getAngle(),pinList[1].getAngle(),pinList[2].getAngle(),pinList[3].getAngle(), + pinList[4].getAngle(),pinList[5].getAngle(),pinList[6].getAngle(),pinList[7].getAngle(), + pinList[8].getAngle(),pinList[9].getAngle(),pinList[10].getAngle(),potList[0].getAngle(),potList[1].getAngle(), + potList[2].getAngle(),potList[3].getAngle());*/ /*Serial.print(pinList[0].getAngle()); Serial.print(","); @@ -311,16 +312,15 @@ void loop() { Serial.print(pinList[8].getAngle()); Serial.print(","); Serial.print(pinList[9].getAngle()); + Serial.print(","); + Serial.print(pinList[10].getAngle()); Serial.print(",");*/ - //Serial.print(pinList[10].getAngle()); - Serial.print(","); - Serial.print(potList[2].getValue()); + Serial.print(potList[0].getValue()); Serial.print(","); - // Serial.print(potList[1].getAngle()); - //Serial.print(","); - //Serial.print(potList[2].getAngle()); + Serial.print(potList[1].getValue()); Serial.print(","); - //Serial.println(potList[3].getAngle()); - -delay(40); -} \ No newline at end of file + Serial.print(potList[2].getValue()); + Serial.print(","); + Serial.println(potList[3].getValue()); + delay(25); +} diff --git a/src/potentiometer.cpp b/src/potentiometer.cpp index ae5d4ae..db3d492 100644 --- a/src/potentiometer.cpp +++ b/src/potentiometer.cpp @@ -26,8 +26,8 @@ potentiometer::potentiometer(int channel, int minimum_angle, int maximum_angle){ potentiometer::potentiometer(int channel){ multipl = true; m_channel = channel; - min_angle = -15; - max_angle = 15; + min_angle = -20; + max_angle = 20; calibrateM = 0; } potentiometer::potentiometer(bool multiplexer, int pin, int minimum_angle, int maximum_angle){ diff --git a/src/potentiometer.h b/src/potentiometer.h index 77b5e92..96fb679 100644 --- a/src/potentiometer.h +++ b/src/potentiometer.h @@ -38,5 +38,5 @@ class potentiometer{ int getCalibrateMax(); void setCalibrateMax(int val); void setCalibrateMin(int val); - void calibrateMean(); + void calibrateMean(int delta_min, int delta_max); }; \ No newline at end of file diff --git a/src/talkyBoi.h b/src/talkyBoi.h index 9c16f81..ee6909f 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -16,8 +16,8 @@ #include #include "Config.h" -//uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress black tape -uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; //MAC-adress silver tape +uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress black tape +//uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; //MAC-adress silver tape //uint8_t broadcastAdress[] = {0x7C,0x9E,0xBD,0x60,0xD1,0x8C}; //MAC masking tape //uint8_t broadcastAdressModel[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; //MAC white tape @@ -42,6 +42,11 @@ typedef struct struct_message{ float finger2Po; float finger3Po; float finger4Po; + float opposition; + float pot1; + float pot2; + float pot3; + float pot4; }struct_message; struct_message msg_to_send; @@ -50,18 +55,6 @@ struct_message msg_incoming; // Callback when data is sent, triggerd when message is sent void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { Serial.print("\r\nLast Packet Send Status:\t"); - //Serial.write((String)mac_addr)); - Serial.print(mac_addr[0], HEX); - Serial.print(","); - Serial.print(mac_addr[1], HEX); - Serial.print(","); - Serial.print(mac_addr[2], HEX); - Serial.print(","); - Serial.print(mac_addr[3], HEX); - Serial.print(","); - Serial.print(mac_addr[4], HEX); - Serial.print(","); - Serial.println(mac_addr[5], HEX); Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); if(status == ESP_NOW_SEND_FAIL){ error++; @@ -122,7 +115,7 @@ void init_wifi(){ * The rest of the arguments is values in the form of angles(already filterd and proccssed). * Call this function from main when a message over wifi should be sent. */ -void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP){ +void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP,float opposition,float pot1,float pot2,float pot3,float pot4){ uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; msg_to_send.sendID = sendID; msg_to_send.thumbIP = thumbIP; @@ -135,6 +128,11 @@ void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float f msg_to_send.finger3MCP = finger3MCP; msg_to_send.finger4PIP = finger4PIP; msg_to_send.finger4MCP = finger4MCP; + msg_to_send.opposition = opposition; + msg_to_send.pot1 = pot1; + msg_to_send.pot2 = pot2; + msg_to_send.pot3 = pot3; + msg_to_send.pot4 = pot4; esp_err_t result = esp_now_send(broadcastAdress, (uint8_t *) &msg_to_send, sizeof(msg_to_send)); } From 94f31ca6782a9ca789023b0eda0ba965438894d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Fri, 20 May 2022 14:41:11 +0200 Subject: [PATCH 39/48] Stuff again --- src/main.cpp | 2 +- src/talkyBoi.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e75cd88..575b975 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -261,7 +261,7 @@ void setup() { Serial.begin(115200); delay(100); // getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. - // init_wifi(); // Initiate ESP_NOW + init_wifi(); // Initiate ESP_NOW initBoard(); // Initiate breakout board disp_initialize(); // Initialise display pinMode(INTERUPT_PIN,INPUT); diff --git a/src/talkyBoi.h b/src/talkyBoi.h index ee6909f..1451ecb 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -116,7 +116,6 @@ void init_wifi(){ * Call this function from main when a message over wifi should be sent. */ void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP,float opposition,float pot1,float pot2,float pot3,float pot4){ - uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; msg_to_send.sendID = sendID; msg_to_send.thumbIP = thumbIP; msg_to_send.thumbMCP = thumbMCP; From 62384519cb246de9615d7f9aad73535bf1badfa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Mon, 23 May 2022 12:07:49 +0200 Subject: [PATCH 40/48] Added wifi stuff --- src/main.cpp | 15 ++++++++------- src/talkyBoi.h | 20 ++++++++------------ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 575b975..00cf8c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -262,7 +262,8 @@ void setup() { delay(100); // getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. init_wifi(); // Initiate ESP_NOW - initBoard(); // Initiate breakout board + initBoard(); // Initiate breakout board + send(1,1,1,1,1,1,11,1,1,1,1,1,11,1,1,11); disp_initialize(); // Initialise display pinMode(INTERUPT_PIN,INPUT); // interupt for start/stop button @@ -293,7 +294,7 @@ void loop() { pinList[8].getAngle(),pinList[9].getAngle(),pinList[10].getAngle(),potList[0].getAngle(),potList[1].getAngle(), potList[2].getAngle(),potList[3].getAngle());*/ - /*Serial.print(pinList[0].getAngle()); + Serial.print(pinList[0].getAngle()); Serial.print(","); Serial.print(pinList[1].getAngle()); Serial.print(","); @@ -314,13 +315,13 @@ void loop() { Serial.print(pinList[9].getAngle()); Serial.print(","); Serial.print(pinList[10].getAngle()); - Serial.print(",");*/ - Serial.print(potList[0].getValue()); Serial.print(","); - Serial.print(potList[1].getValue()); + Serial.print(potList[0].getAngle()); Serial.print(","); - Serial.print(potList[2].getValue()); + Serial.print(potList[1].getAngle()); Serial.print(","); - Serial.println(potList[3].getValue()); + Serial.print(potList[2].getAngle()); + Serial.print(","); + Serial.println(potList[3].getAngle()); delay(25); } diff --git a/src/talkyBoi.h b/src/talkyBoi.h index 1451ecb..ae59c34 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -39,14 +39,10 @@ typedef struct struct_message{ float finger4MCP; float thumbOpp; float finger1Pot; - float finger2Po; - float finger3Po; - float finger4Po; + float finger2Pot; + float finger3Pot; + float finger4Pot; float opposition; - float pot1; - float pot2; - float pot3; - float pot4; }struct_message; struct_message msg_to_send; @@ -128,11 +124,11 @@ void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float f msg_to_send.finger4PIP = finger4PIP; msg_to_send.finger4MCP = finger4MCP; msg_to_send.opposition = opposition; - msg_to_send.pot1 = pot1; - msg_to_send.pot2 = pot2; - msg_to_send.pot3 = pot3; - msg_to_send.pot4 = pot4; - + msg_to_send.finger1Pot = pot1; + msg_to_send.finger2Pot = pot2; + msg_to_send.finger3Pot = pot3; + msg_to_send.finger4Pot = pot4; + esp_err_t result = esp_now_send(broadcastAdress, (uint8_t *) &msg_to_send, sizeof(msg_to_send)); } /** From 62e4ba5ee28b4877be3dfa465fec28c11c55a5a3 Mon Sep 17 00:00:00 2001 From: LouieJanbro Date: Mon, 23 May 2022 12:09:58 +0200 Subject: [PATCH 41/48] fixade bug med calibration --- src/flexSensor.cpp | 1 + src/main.cpp | 28 ++++++++++++++-------------- src/talkyBoi.h | 1 - 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/flexSensor.cpp b/src/flexSensor.cpp index 975c701..0ef8cb7 100644 --- a/src/flexSensor.cpp +++ b/src/flexSensor.cpp @@ -43,6 +43,7 @@ flexSensor::flexSensor(bool multiplexer, int pin){ /** * Changes multiplexer to read from int channel and then returns the read value. * @return analog reading from multiplexer in input channel. + * this method is taken from http://adam-meyer.com/arduino/CD74HC4067 under MIT-License. */ int flexSensor::readMux(int channel){ int controlPin[] = {s0, s1, s2, s3}; diff --git a/src/main.cpp b/src/main.cpp index e75cd88..e831e2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -249,9 +249,9 @@ void calibrateAbduction2(){ potList[3].calibrate(true); potList[0].setCalibrateMax(2*pot0_mean - potList[0].getCalibrateMin()); - potList[0].setCalibrateMax(2*pot0_mean - potList[0].getCalibrateMin()); - potList[0].setCalibrateMin(2*pot0_mean - potList[0].getCalibrateMax()); - potList[0].setCalibrateMin(2*pot0_mean - potList[0].getCalibrateMax()); + potList[1].setCalibrateMax(2*pot0_mean - potList[1].getCalibrateMin()); + potList[2].setCalibrateMin(2*pot0_mean - potList[2].getCalibrateMax()); + potList[3].setCalibrateMin(2*pot0_mean - potList[3].getCalibrateMax()); Serial.println("Calibration complete"); calibrateState = 0; detachInterrupt(INTERUPT_PIN); @@ -261,7 +261,7 @@ void setup() { Serial.begin(115200); delay(100); // getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. - // init_wifi(); // Initiate ESP_NOW + init_wifi(); // Initiate ESP_NOW initBoard(); // Initiate breakout board disp_initialize(); // Initialise display pinMode(INTERUPT_PIN,INPUT); @@ -288,12 +288,12 @@ void loop() { //Serial.write(10); delay(20); //sendID++; - /*send(sendID, pinList[0].getAngle(),pinList[1].getAngle(),pinList[2].getAngle(),pinList[3].getAngle(), + send(sendID, pinList[0].getAngle(),pinList[1].getAngle(),pinList[2].getAngle(),pinList[3].getAngle(), pinList[4].getAngle(),pinList[5].getAngle(),pinList[6].getAngle(),pinList[7].getAngle(), - pinList[8].getAngle(),pinList[9].getAngle(),pinList[10].getAngle(),potList[0].getAngle(),potList[1].getAngle(), - potList[2].getAngle(),potList[3].getAngle());*/ + pinList[8].getAngle(),pinList[9].getAngle(),pinList[10].getAngle(),potList[0].getAngle(),0, + 0,0); - /*Serial.print(pinList[0].getAngle()); + Serial.print(pinList[0].getAngle()); Serial.print(","); Serial.print(pinList[1].getAngle()); Serial.print(","); @@ -314,13 +314,13 @@ void loop() { Serial.print(pinList[9].getAngle()); Serial.print(","); Serial.print(pinList[10].getAngle()); - Serial.print(",");*/ - Serial.print(potList[0].getValue()); Serial.print(","); - Serial.print(potList[1].getValue()); + Serial.print(potList[0].getAngle()); + Serial.print(","); + Serial.print(0); Serial.print(","); - Serial.print(potList[2].getValue()); + Serial.print(0); Serial.print(","); - Serial.println(potList[3].getValue()); - delay(25); + Serial.println(0); + delay(40); } diff --git a/src/talkyBoi.h b/src/talkyBoi.h index ee6909f..1451ecb 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -116,7 +116,6 @@ void init_wifi(){ * Call this function from main when a message over wifi should be sent. */ void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP,float opposition,float pot1,float pot2,float pot3,float pot4){ - uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; msg_to_send.sendID = sendID; msg_to_send.thumbIP = thumbIP; msg_to_send.thumbMCP = thumbMCP; From 321d33fd31038b7ca6e2926515e0cb0eb3ff05bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Mon, 23 May 2022 12:19:05 +0200 Subject: [PATCH 42/48] Stuff with wifi --- src/main.cpp | 5 +++-- src/talkyBoi.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 00cf8c7..c22f1f1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -262,8 +262,9 @@ void setup() { delay(100); // getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. init_wifi(); // Initiate ESP_NOW + send(1,1,1,1,1,1,11,1,1,1,1,1,11,1,1,11); initBoard(); // Initiate breakout board - send(1,1,1,1,1,1,11,1,1,1,1,1,11,1,1,11); + disp_initialize(); // Initialise display pinMode(INTERUPT_PIN,INPUT); // interupt for start/stop button @@ -324,4 +325,4 @@ void loop() { Serial.print(","); Serial.println(potList[3].getAngle()); delay(25); -} +} \ No newline at end of file diff --git a/src/talkyBoi.h b/src/talkyBoi.h index ae59c34..bf1c91f 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -85,7 +85,7 @@ void getMACAdress(){ * Also inits the ESPNOW protocol with MAC-adresses and peerInfo. */ void init_wifi(){ - WiFi.mode(WIFI_STA); + WiFi.mode(WIFI_STA); if (esp_now_init() != ESP_OK) { Serial.println("Error initializing ESP-NOW"); return; From 5d87a55ab63b23360a4b55bc39bc87e288243af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Wed, 25 May 2022 10:12:03 +0200 Subject: [PATCH 43/48] Testing wifi --- src/main.cpp | 26 ++++++++++---------------- src/talkyBoi.h | 21 +++------------------ 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8c20160..acba270 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -263,16 +263,16 @@ void setup() { // getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. init_wifi(); // Initiate ESP_NOW send(1,1,1,1,1,1,11,1,1,1,1,1,11,1,1,11); - initBoard(); // Initiate breakout board + //initBoard(); // Initiate breakout board - disp_initialize(); // Initialise display - pinMode(INTERUPT_PIN,INPUT); + //disp_initialize(); // Initialise display + //pinMode(INTERUPT_PIN,INPUT); // interupt for start/stop button - calibrateFlexion(); - calibrateAbduction2(); // Calibrate flextion movement of fingers + //calibrateFlexion(); + //calibrateAbduction2(); // Calibrate flextion movement of fingers //calibrateAbduction(); // Calibrate abduction and adduction movement of fingers - attachInterrupt(INTERUPT_PIN, interuptFunc, RISING); + //attachInterrupt(INTERUPT_PIN, interuptFunc, RISING); /*potList[1].setCalibrateMin(50); potList[1].setCalibrateMax(105); @@ -290,11 +290,11 @@ void loop() { //Serial.write(10); delay(20); //sendID++; - send(sendID, pinList[0].getAngle(),pinList[1].getAngle(),pinList[2].getAngle(),pinList[3].getAngle(), + /*send(sendID, pinList[0].getAngle(),pinList[1].getAngle(),pinList[2].getAngle(),pinList[3].getAngle(), pinList[4].getAngle(),pinList[5].getAngle(),pinList[6].getAngle(),pinList[7].getAngle(), pinList[8].getAngle(),pinList[9].getAngle(),pinList[10].getAngle(),potList[0].getAngle(),0, - 0,0); - + 0,0);*/ + /* Serial.print(pinList[0].getAngle()); Serial.print(","); Serial.print(pinList[1].getAngle()); @@ -323,12 +323,6 @@ void loop() { Serial.print(","); Serial.print(0); Serial.print(","); -<<<<<<< HEAD - Serial.println(potList[3].getAngle()); - delay(25); -} -======= - Serial.println(0); + Serial.println(0);*/ delay(40); } ->>>>>>> 175bc933f07c63f63a31fca9da7c0734a2e6a03b diff --git a/src/talkyBoi.h b/src/talkyBoi.h index bf1c91f..9ff212c 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -16,9 +16,9 @@ #include #include "Config.h" -uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress black tape +//uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress black tape //uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; //MAC-adress silver tape -//uint8_t broadcastAdress[] = {0x7C,0x9E,0xBD,0x60,0xD1,0x8C}; //MAC masking tape +uint8_t broadcastAdress[] = {0x7C,0x9E,0xBD,0x60,0xD1,0x8C}; //MAC masking tape //uint8_t broadcastAdressModel[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; //MAC white tape int recID = 0; @@ -89,7 +89,7 @@ void init_wifi(){ if (esp_now_init() != ESP_OK) { Serial.println("Error initializing ESP-NOW"); return; - } + }else{Serial.println("INit not working");} esp_now_register_send_cb(OnDataSent); @@ -130,19 +130,4 @@ void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float f msg_to_send.finger4Pot = pot4; esp_err_t result = esp_now_send(broadcastAdress, (uint8_t *) &msg_to_send, sizeof(msg_to_send)); -} -/** - * This is not used. - */ -void sendToModel(int sendID, float thumbIP, float thumbMCP){ - Serial.println("Send to model : "); - uint8_t broadcastAdress[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; - msg_to_send.sendID = sendID; - esp_err_t result = esp_now_send(broadcastAdress,(uint8_t *) &msg_to_send, sizeof(msg_to_send)); -} -/** - * This is not used. - */ -void recieve() { - } \ No newline at end of file From 7f54e034a71a46510fd5b2715b0df884633009ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Wed, 25 May 2022 10:20:03 +0200 Subject: [PATCH 44/48] Still testing wifi --- src/main.cpp | 2 +- src/talkyBoi.h | 101 ++++++++++++++++++++++--------------------------- 2 files changed, 46 insertions(+), 57 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index acba270..0a09db9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -262,7 +262,7 @@ void setup() { delay(100); // getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. init_wifi(); // Initiate ESP_NOW - send(1,1,1,1,1,1,11,1,1,1,1,1,11,1,1,11); + //send(1,1,1,1,1,1,11,1,1,1,1,1,11,1,1,11); //initBoard(); // Initiate breakout board //disp_initialize(); // Initialise display diff --git a/src/talkyBoi.h b/src/talkyBoi.h index 9ff212c..c73d22a 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -1,25 +1,13 @@ -/** - * This h file contains the funkction callbacks from ESPNOW - * that is used for WIFI communication peer to peer with the mechatronic hand. - * Save values into the struct "msg_to_send" with the "send" function which can be - * calld from the main method. - * to add more values to the struct change the structre of "struct message". - * - * The callback "OnDataSent" can be used to get information about the message status, "success" or "failure" on sent. - * The callback "OnDataRecv" can be used to get information on recieve, this can be used to print the strct that is recievd over WIFI. - * "msg_incoming" is the incoming struct that can be used to print the values(angles) or save the values(angles) as variables. - */ -#pragma once - #include #include #include -#include "Config.h" -//uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress black tape -//uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; //MAC-adress silver tape -uint8_t broadcastAdress[] = {0x7C,0x9E,0xBD,0x60,0xD1,0x8C}; //MAC masking tape -//uint8_t broadcastAdressModel[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; //MAC white tape +//uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress till den svarta/andra gruppen +//uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; //MAC-adress till den silver +//uint8_t broadcastAdress[] = {0x7C,0x9E,0xBD,0x60,0xD1,0x8C}; //MAC till den med maskering +//uint8_t broadcastAdress[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; //MAC till den med vit tejp +uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE4,0x84,0x34}; + int recID = 0; int error = 0; @@ -38,58 +26,57 @@ typedef struct struct_message{ float finger4PIP; float finger4MCP; float thumbOpp; - float finger1Pot; - float finger2Pot; - float finger3Pot; - float finger4Pot; - float opposition; + float test12; + float test13; + float test14; + float test15; }struct_message; struct_message msg_to_send; struct_message msg_incoming; -// Callback when data is sent, triggerd when message is sent +// Callback when data is sent, triggas när något skickas void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { Serial.print("\r\nLast Packet Send Status:\t"); - Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); + /*//Serial.write((String)mac_addr)); + Serial.print(mac_addr[0], HEX); + Serial.print(","); + Serial.print(mac_addr[1], HEX); + Serial.print(","); + Serial.print(mac_addr[2], HEX); + Serial.print(","); + Serial.print(mac_addr[3], HEX); + Serial.print(","); + Serial.print(mac_addr[4], HEX); + Serial.print(","); + Serial.println(mac_addr[5], HEX);*/ + Serial.print(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success: " : "Delivery Fail: "); if(status == ESP_NOW_SEND_FAIL){ error++; }else{ succ++; } + Serial.println(error); } - -/** - * Callback when data is received, triggerd when a message is recievd - */ +// Callback when data is received, triggas när något mottas (används ej) void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { memcpy(&msg_incoming, incomingData, sizeof(msg_incoming)); recID = msg_incoming.sendID; - Serial.print(recID); - Serial.print(","); - Serial.print(recID); - Serial.print(","); Serial.println(recID); } -/** - * Used to print the current ESP's MAC-adress which is used to for peer to peer communication with ESPNOW.' - * This adress is added to the ESP that SENDS data, if you only reciev no MAC-adress is needed - */ + void getMACAdress(){ WiFi.mode(WIFI_MODE_STA); Serial.println(WiFi.macAddress()); } -/** - * Used to print error messages if WIFI is not initializd. - * Also inits the ESPNOW protocol with MAC-adresses and peerInfo. - */ -void init_wifi(){ - WiFi.mode(WIFI_STA); + +void init_wifi (){ + WiFi.mode(WIFI_STA); if (esp_now_init() != ESP_OK) { Serial.println("Error initializing ESP-NOW"); return; - }else{Serial.println("INit not working");} + } esp_now_register_send_cb(OnDataSent); @@ -106,12 +93,8 @@ void init_wifi(){ esp_now_register_recv_cb(OnDataRecv); } -/** - * This function is used to send data over WIFI, takes arguments sendID(incremented value to keep track of the number of sent packages) - * The rest of the arguments is values in the form of angles(already filterd and proccssed). - * Call this function from main when a message over wifi should be sent. - */ -void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP,float opposition,float pot1,float pot2,float pot3,float pot4){ +void send (float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP){ + //uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; msg_to_send.sendID = sendID; msg_to_send.thumbIP = thumbIP; msg_to_send.thumbMCP = thumbMCP; @@ -123,11 +106,17 @@ void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float f msg_to_send.finger3MCP = finger3MCP; msg_to_send.finger4PIP = finger4PIP; msg_to_send.finger4MCP = finger4MCP; - msg_to_send.opposition = opposition; - msg_to_send.finger1Pot = pot1; - msg_to_send.finger2Pot = pot2; - msg_to_send.finger3Pot = pot3; - msg_to_send.finger4Pot = pot4; - + esp_err_t result = esp_now_send(broadcastAdress, (uint8_t *) &msg_to_send, sizeof(msg_to_send)); +} + +void sendToModel(int sendID, float thumbIP, float thumbMCP){ + Serial.println("Send to model : "); + uint8_t broadcastAdress[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; + msg_to_send.sendID = sendID; + esp_err_t result = esp_now_send(broadcastAdress,(uint8_t *) &msg_to_send, sizeof(msg_to_send)); +} + +void recieve () { + } \ No newline at end of file From a8c27ec46b08c663b9ac79b25db55e195b706311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Wed, 25 May 2022 10:41:13 +0200 Subject: [PATCH 45/48] WIFI is fixed! great succ --- src/main.cpp | 18 +++++++++--------- src/talkyBoi.h | 16 +++++++++++----- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0a09db9..4a2e00d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -260,15 +260,15 @@ void calibrateAbduction2(){ void setup() { Serial.begin(115200); delay(100); - // getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. + getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. init_wifi(); // Initiate ESP_NOW //send(1,1,1,1,1,1,11,1,1,1,1,1,11,1,1,11); - //initBoard(); // Initiate breakout board + initBoard(); // Initiate breakout board - //disp_initialize(); // Initialise display - //pinMode(INTERUPT_PIN,INPUT); + disp_initialize(); // Initialise display + pinMode(INTERUPT_PIN,INPUT); // interupt for start/stop button - //calibrateFlexion(); + calibrateFlexion(); //calibrateAbduction2(); // Calibrate flextion movement of fingers //calibrateAbduction(); // Calibrate abduction and adduction movement of fingers @@ -290,11 +290,11 @@ void loop() { //Serial.write(10); delay(20); //sendID++; - /*send(sendID, pinList[0].getAngle(),pinList[1].getAngle(),pinList[2].getAngle(),pinList[3].getAngle(), + send(sendID, pinList[0].getAngle(),pinList[1].getAngle(),pinList[2].getAngle(),pinList[3].getAngle(), pinList[4].getAngle(),pinList[5].getAngle(),pinList[6].getAngle(),pinList[7].getAngle(), pinList[8].getAngle(),pinList[9].getAngle(),pinList[10].getAngle(),potList[0].getAngle(),0, - 0,0);*/ - /* + 0,0); + Serial.print(pinList[0].getAngle()); Serial.print(","); Serial.print(pinList[1].getAngle()); @@ -323,6 +323,6 @@ void loop() { Serial.print(","); Serial.print(0); Serial.print(","); - Serial.println(0);*/ + Serial.println(0); delay(40); } diff --git a/src/talkyBoi.h b/src/talkyBoi.h index c73d22a..6fe8941 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -26,10 +26,11 @@ typedef struct struct_message{ float finger4PIP; float finger4MCP; float thumbOpp; - float test12; - float test13; - float test14; - float test15; + float finger1Pot; + float finger2Pot; + float finger3Pot; + float finger4Pot; + float opposition; }struct_message; struct_message msg_to_send; @@ -93,7 +94,7 @@ void init_wifi (){ esp_now_register_recv_cb(OnDataRecv); } -void send (float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP){ +void send (float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP, float opp, float pot1, float pot2, float pot3, float pot4){ //uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; msg_to_send.sendID = sendID; msg_to_send.thumbIP = thumbIP; @@ -106,6 +107,11 @@ void send (float sendID, float thumbIP, float thumbMCP, float finger1PIP, float msg_to_send.finger3MCP = finger3MCP; msg_to_send.finger4PIP = finger4PIP; msg_to_send.finger4MCP = finger4MCP; + msg_to_send.opposition = opp; + msg_to_send.finger1Pot = pot1; + msg_to_send.finger2Pot = pot2; + msg_to_send.finger3Pot = pot3; + msg_to_send.finger4Pot = pot4; esp_err_t result = esp_now_send(broadcastAdress, (uint8_t *) &msg_to_send, sizeof(msg_to_send)); } From b67267a1fe4cf84d50f5b3d543232ba464037d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Thu, 22 Sep 2022 11:07:58 +0200 Subject: [PATCH 46/48] Stuff --- src/main.cpp | 42 +++++++++++++-------------- src/talkyBoi.h | 79 +++++++++++++++++++++++++++++++++++--------------- 2 files changed, 76 insertions(+), 45 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4a2e00d..1c56185 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,16 +12,16 @@ int state = 0; int calibrateState = 0; // Declaring all flexSensor objects -flexSensor thumbIP = flexSensor(0); -flexSensor thumbMCP = flexSensor(1); -flexSensor f1PIP = flexSensor(2); -flexSensor f1MCP = flexSensor(3); -flexSensor f2PIP = flexSensor(4); -flexSensor f2MCP = flexSensor(5); -flexSensor f3PIP = flexSensor(6); -flexSensor f3MCP = flexSensor(7); -flexSensor f4PIP = flexSensor(8); -flexSensor f4MCP = flexSensor(9); +flexSensor thumbIP = flexSensor(8); +flexSensor thumbMCP = flexSensor(9); +flexSensor f1PIP = flexSensor(0); +flexSensor f1MCP = flexSensor(1); +flexSensor f2PIP = flexSensor(2); +flexSensor f2MCP = flexSensor(3); +flexSensor f3PIP = flexSensor(4); +flexSensor f3MCP = flexSensor(5); +flexSensor f4PIP = flexSensor(6); +flexSensor f4MCP = flexSensor(7); flexSensor opposition = flexSensor(10); // Declaring all potentiometer objects @@ -263,16 +263,16 @@ void setup() { getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. init_wifi(); // Initiate ESP_NOW //send(1,1,1,1,1,1,11,1,1,1,1,1,11,1,1,11); - initBoard(); // Initiate breakout board + //initBoard(); // Initiate breakout board - disp_initialize(); // Initialise display - pinMode(INTERUPT_PIN,INPUT); + //disp_initialize(); // Initialise display + //pinMode(INTERUPT_PIN,INPUT); // interupt for start/stop button - calibrateFlexion(); + //calibrateFlexion(); //calibrateAbduction2(); // Calibrate flextion movement of fingers //calibrateAbduction(); // Calibrate abduction and adduction movement of fingers - //attachInterrupt(INTERUPT_PIN, interuptFunc, RISING); + attachInterrupt(INTERUPT_PIN, interuptFunc, RISING); /*potList[1].setCalibrateMin(50); potList[1].setCalibrateMax(105); @@ -288,13 +288,13 @@ void loop() { //Serial.print(potList[1].getAngle()); //Serial.write(13); //Serial.write(10); - delay(20); + //delay(20); //sendID++; - send(sendID, pinList[0].getAngle(),pinList[1].getAngle(),pinList[2].getAngle(),pinList[3].getAngle(), + /*send(sendID, pinList[0].getAngle(),pinList[1].getAngle(),pinList[2].getAngle(),pinList[3].getAngle(), pinList[4].getAngle(),pinList[5].getAngle(),pinList[6].getAngle(),pinList[7].getAngle(), pinList[8].getAngle(),pinList[9].getAngle(),pinList[10].getAngle(),potList[0].getAngle(),0, - 0,0); - + 0,0);*/ + /* Serial.print(pinList[0].getAngle()); Serial.print(","); Serial.print(pinList[1].getAngle()); @@ -323,6 +323,6 @@ void loop() { Serial.print(","); Serial.print(0); Serial.print(","); - Serial.println(0); - delay(40); + Serial.println(0);*/ + //delay(40); } diff --git a/src/talkyBoi.h b/src/talkyBoi.h index 6fe8941..3343ac4 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -2,11 +2,11 @@ #include #include -//uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress till den svarta/andra gruppen +uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE6,0x79,0x9C}; //MAC-adress till den svarta/andra gruppen //uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; //MAC-adress till den silver //uint8_t broadcastAdress[] = {0x7C,0x9E,0xBD,0x60,0xD1,0x8C}; //MAC till den med maskering //uint8_t broadcastAdress[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4}; //MAC till den med vit tejp -uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE4,0x84,0x34}; +//uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE4,0x84,0x34}; int recID = 0; @@ -59,12 +59,63 @@ void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { } Serial.println(error); } +void send(float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP,float opposition,float pot1,float pot2,float pot3,float pot4){ + msg_to_send.sendID = sendID; + msg_to_send.thumbIP = thumbIP; + msg_to_send.thumbMCP = thumbMCP; + msg_to_send.finger1PIP = finger1PIP; + msg_to_send.finger1MCP = finger1MCP; + msg_to_send.finger2PIP = finger2PIP; + msg_to_send.finger2MCP = finger2MCP; + msg_to_send.finger3PIP = finger3PIP; + msg_to_send.finger3MCP = finger3MCP; + msg_to_send.finger4PIP = finger4PIP; + msg_to_send.finger4MCP = finger4MCP; + msg_to_send.opposition = opposition; + msg_to_send.finger1Pot = pot1; + msg_to_send.finger2Pot = pot2; + msg_to_send.finger3Pot = pot3; + msg_to_send.finger4Pot = pot4; + + esp_err_t result = esp_now_send(broadcastAdress, (uint8_t *) &msg_to_send, sizeof(msg_to_send)); +} // Callback when data is received, triggas när något mottas (används ej) void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { memcpy(&msg_incoming, incomingData, sizeof(msg_incoming)); - recID = msg_incoming.sendID; - Serial.println(recID); + Serial.print(msg_incoming.thumbIP); + Serial.print(","); + Serial.print(msg_incoming.thumbMCP); + Serial.print(","); + Serial.print(msg_incoming.finger1PIP); + Serial.print(","); + Serial.print(msg_incoming.finger1MCP); + Serial.print(","); + Serial.print(msg_incoming.finger2PIP); + Serial.print(","); + Serial.print(msg_incoming.finger2MCP); + Serial.print(","); + Serial.print(msg_incoming.finger3PIP); + Serial.print(","); + Serial.print(msg_incoming.finger3MCP); + Serial.print(","); + Serial.print(msg_incoming.finger4PIP); + Serial.print(","); + Serial.print(msg_incoming.finger4MCP); + Serial.print(","); + Serial.print(msg_incoming.opposition); + Serial.print(","); + Serial.print(msg_incoming.finger1Pot); + Serial.print(","); + Serial.print(0); + Serial.print(","); + Serial.print(0); + Serial.print(","); + Serial.println(0); + send(1, msg_incoming.thumbIP,msg_incoming.thumbMCP,msg_incoming.finger1PIP,msg_incoming.finger1MCP, + msg_incoming.finger2PIP,msg_incoming.finger2MCP,msg_incoming.finger3PIP,msg_incoming.finger3MCP, + msg_incoming.finger4PIP,msg_incoming.finger4MCP,msg_incoming.opposition,msg_incoming.finger1Pot,0, + 0,0); } void getMACAdress(){ @@ -94,27 +145,7 @@ void init_wifi (){ esp_now_register_recv_cb(OnDataRecv); } -void send (float sendID, float thumbIP, float thumbMCP, float finger1PIP, float finger1MCP, float finger2PIP, float finger2MCP, float finger3PIP, float finger3MCP, float finger4PIP, float finger4MCP, float opp, float pot1, float pot2, float pot3, float pot4){ - //uint8_t broadcastAdress[] = {0x94,0xB9,0x7E,0xE5,0x31,0xD8}; - msg_to_send.sendID = sendID; - msg_to_send.thumbIP = thumbIP; - msg_to_send.thumbMCP = thumbMCP; - msg_to_send.finger1PIP = finger1PIP; - msg_to_send.finger1MCP = finger1MCP; - msg_to_send.finger2PIP = finger2PIP; - msg_to_send.finger2MCP = finger2MCP; - msg_to_send.finger3PIP = finger3PIP; - msg_to_send.finger3MCP = finger3MCP; - msg_to_send.finger4PIP = finger4PIP; - msg_to_send.finger4MCP = finger4MCP; - msg_to_send.opposition = opp; - msg_to_send.finger1Pot = pot1; - msg_to_send.finger2Pot = pot2; - msg_to_send.finger3Pot = pot3; - msg_to_send.finger4Pot = pot4; - esp_err_t result = esp_now_send(broadcastAdress, (uint8_t *) &msg_to_send, sizeof(msg_to_send)); -} void sendToModel(int sendID, float thumbIP, float thumbMCP){ Serial.println("Send to model : "); From dcebdc994f650b9707e6dde27f2b32e03d02e1a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Sat, 29 Oct 2022 10:19:18 +0200 Subject: [PATCH 47/48] Cleaning up the code --- src/main.cpp | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1c56185..c26f875 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -261,40 +261,35 @@ void setup() { Serial.begin(115200); delay(100); getMACAdress(); //MAC adress is run for the WIFI to work, the OTHER wearers MAC adress shall be written in this code and vice versa. - init_wifi(); // Initiate ESP_NOW - //send(1,1,1,1,1,1,11,1,1,1,1,1,11,1,1,11); - //initBoard(); // Initiate breakout board + init_wifi(); // Initiate ESP_NOW + initBoard(); // Initiate breakout board - //disp_initialize(); // Initialise display - //pinMode(INTERUPT_PIN,INPUT); + disp_initialize(); // Initialise display + pinMode(INTERUPT_PIN,INPUT); // interupt for start/stop button - //calibrateFlexion(); - //calibrateAbduction2(); // Calibrate flextion movement of fingers - //calibrateAbduction(); // Calibrate abduction and adduction movement of fingers + calibrateFlexion(); + calibrateAbduction2(); // Calibrate flextion movement of fingers + calibrateAbduction(); // Calibrate abduction and adduction movement of fingers attachInterrupt(INTERUPT_PIN, interuptFunc, RISING); - /*potList[1].setCalibrateMin(50); + potList[1].setCalibrateMin(50); potList[1].setCalibrateMax(105); potList[2].setCalibrateMin(110); potList[2].setCalibrateMax(240); potList[3].setCalibrateMin(130); - potList[3].setCalibrateMax(200);*/ + potList[3].setCalibrateMax(200); } void loop() { - //Serial.println(readMux(11)); - //Serial.print(potList[1].getAngle()); - //Serial.write(13); - //Serial.write(10); - //delay(20); - //sendID++; - /*send(sendID, pinList[0].getAngle(),pinList[1].getAngle(),pinList[2].getAngle(),pinList[3].getAngle(), + delay(20); + sendID++; + send(sendID, pinList[0].getAngle(),pinList[1].getAngle(),pinList[2].getAngle(),pinList[3].getAngle(), pinList[4].getAngle(),pinList[5].getAngle(),pinList[6].getAngle(),pinList[7].getAngle(), pinList[8].getAngle(),pinList[9].getAngle(),pinList[10].getAngle(),potList[0].getAngle(),0, - 0,0);*/ - /* + 0,0); + Serial.print(pinList[0].getAngle()); Serial.print(","); Serial.print(pinList[1].getAngle()); @@ -323,6 +318,5 @@ void loop() { Serial.print(","); Serial.print(0); Serial.print(","); - Serial.println(0);*/ - //delay(40); + Serial.println(0); } From 37f39a097d3762b19a1ff8a078f860b131c7a8bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Ax=C3=A9n?= Date: Sat, 29 Oct 2022 10:21:46 +0200 Subject: [PATCH 48/48] Cleaning up the code --- src/talkyBoi.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/talkyBoi.h b/src/talkyBoi.h index 3343ac4..051d222 100644 --- a/src/talkyBoi.h +++ b/src/talkyBoi.h @@ -145,8 +145,6 @@ void init_wifi (){ esp_now_register_recv_cb(OnDataRecv); } - - void sendToModel(int sendID, float thumbIP, float thumbMCP){ Serial.println("Send to model : "); uint8_t broadcastAdress[] = {0X7C,0X9E,0XBD,0X61,0X58,0XF4};