Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent.strong committed Mar 17, 2024
2 parents fb2d7c2 + 4ea3919 commit c07259c
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 1 deletion.
189 changes: 189 additions & 0 deletions Arduino/Array_Driver.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#include <Adafruit_INA219.h>
#include <Wire.h>

#define ELECT_YELLOW_POS_ENB 22
#define ELECT_YELLOW_POS_POL 23
#define ELECT_YELLOW_NEG_ENB 24
#define ELECT_YELLOW_NEG_POL 25

#define ELECT_GREEN_POS_ENB 27
#define ELECT_GREEN_POS_POL 26
#define ELECT_GREEN_NEG_ENB 28
#define ELECT_GREEN_NEG_POL 29

#define ELECT_BLUE_POS_ENB 31
#define ELECT_BLUE_POS_POL 30
#define ELECT_BLUE_NEG_ENB 32
#define ELECT_BLUE_NEG_POL 33

#define ELECT_PURPLE_POS_ENB 35
#define ELECT_PURPLE_POS_POL 34
#define ELECT_PURPLE_NEG_ENB 38
#define ELECT_PURPLE_NEG_POL 39

#define ELECT_GREY_POS_ENB 41
#define ELECT_GREY_POS_POL 40
#define ELECT_GREY_NEG_ENB 42
#define ELECT_GREY_NEG_POL 43

#define ELECT_WHITE_POS_ENB 45
#define ELECT_WHITE_POS_POL 44
#define ELECT_WHITE_NEG_ENB 46
#define ELECT_WHITE_NEG_POL 47

Adafruit_INA219 ina219Black(0x40); //0x40
Adafruit_INA219 ina219Brown(0x41); //0x41
Adafruit_INA219 ina219Red(0x44); //0x44

String inputString = ""; // a String to hold incoming data
boolean stringComplete = false; // whether the string is complete

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);

if (! ina219Black.begin()) {
Serial.println("Failed to find INA219 black chip");
while (1) { delay(100); digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN)); }
}
if (! ina219Brown.begin()) {
Serial.println("Failed to find INA219 brown chip");
while (1) { delay(100); digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN)); }
}
if (! ina219Red.begin()) {
Serial.println("Failed to find INA219 red chip");
while (1) { delay(100); digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN)); }
}

pinMode(ELECT_YELLOW_NEG_ENB, OUTPUT);
pinMode(ELECT_YELLOW_NEG_POL, OUTPUT);
pinMode(ELECT_YELLOW_POS_ENB, OUTPUT);
pinMode(ELECT_YELLOW_POS_POL, OUTPUT);

pinMode(ELECT_GREEN_NEG_ENB, OUTPUT);
pinMode(ELECT_GREEN_NEG_POL, OUTPUT);
pinMode(ELECT_GREEN_POS_ENB, OUTPUT);
pinMode(ELECT_GREEN_POS_POL, OUTPUT);

pinMode(ELECT_BLUE_NEG_ENB, OUTPUT);
pinMode(ELECT_BLUE_NEG_POL, OUTPUT);
pinMode(ELECT_BLUE_POS_ENB, OUTPUT);
pinMode(ELECT_BLUE_POS_POL, OUTPUT);

pinMode(ELECT_PURPLE_NEG_ENB, OUTPUT);
pinMode(ELECT_PURPLE_NEG_POL, OUTPUT);
pinMode(ELECT_PURPLE_POS_ENB, OUTPUT);
pinMode(ELECT_PURPLE_POS_POL, OUTPUT);

pinMode(ELECT_GREY_NEG_ENB, OUTPUT);
pinMode(ELECT_GREY_NEG_POL, OUTPUT);
pinMode(ELECT_GREY_POS_ENB, OUTPUT);
pinMode(ELECT_GREY_POS_POL, OUTPUT);

pinMode(ELECT_WHITE_NEG_ENB, OUTPUT);
pinMode(ELECT_WHITE_NEG_POL, OUTPUT);
pinMode(ELECT_WHITE_POS_ENB, OUTPUT);
pinMode(ELECT_WHITE_POS_POL, OUTPUT);

RestStim();
digitalWrite(LED_BUILTIN,true);

}

void loop() {
// put your main code here, to run repeatedly:
if (stringComplete) {
Serial.println(getCurrents());
//digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
DriveElectrod(inputString);
// clear the string:
inputString = "";
stringComplete = false;
}

}

void DriveElectrod(String inputs){
int pongMap[][4] = { {ELECT_PURPLE_NEG_ENB, ELECT_PURPLE_NEG_POL, ELECT_PURPLE_POS_ENB, ELECT_PURPLE_POS_POL},
{ELECT_GREEN_NEG_ENB, ELECT_GREEN_NEG_POL, ELECT_GREEN_POS_ENB, ELECT_GREEN_POS_POL},
{ELECT_WHITE_NEG_ENB, ELECT_WHITE_NEG_POL, ELECT_WHITE_POS_ENB, ELECT_WHITE_POS_POL},
{ELECT_YELLOW_NEG_ENB, ELECT_YELLOW_NEG_POL, ELECT_YELLOW_POS_ENB, ELECT_YELLOW_POS_POL},
{ELECT_GREY_NEG_ENB, ELECT_GREY_NEG_POL, ELECT_GREY_POS_ENB, ELECT_GREY_POS_POL},
{ELECT_BLUE_NEG_ENB, ELECT_BLUE_NEG_POL, ELECT_BLUE_POS_ENB, ELECT_BLUE_POS_POL}};
int lastFind = 0;
for (int i = 0; i<6; i++){
int pos = inputs.indexOf(',', lastFind);
int out = (inputs.substring(lastFind, pos)).toInt();
lastFind = pos+1;
if(out == 0){ //no output
digitalWrite(pongMap[i][0], true);//NEG_ENB
digitalWrite(pongMap[i][1], true);//NEG_POL
digitalWrite(pongMap[i][2], true);//POS_ENB
digitalWrite(pongMap[i][3], true);//POS_POL
}
else if (out == 1){ //positive output
digitalWrite(pongMap[i][0], false);//NEG_ENB
digitalWrite(pongMap[i][1], true);//NEG_POL
digitalWrite(pongMap[i][2], false);//POS_ENB
digitalWrite(pongMap[i][3], false);//POS_POL
}
else if (out == -1){ //negative output
digitalWrite(pongMap[i][0], false);//NEG_ENB
digitalWrite(pongMap[i][1], false);//NEG_POL
digitalWrite(pongMap[i][2], false);//POS_ENB
digitalWrite(pongMap[i][3], true);//POS_POL
}
}
}

void RestStim(){
bool temp = true;
digitalWrite(ELECT_YELLOW_NEG_ENB, temp);
digitalWrite(ELECT_YELLOW_NEG_POL, temp);
digitalWrite(ELECT_YELLOW_POS_ENB, temp);
digitalWrite(ELECT_YELLOW_POS_POL, temp);

digitalWrite(ELECT_GREEN_NEG_ENB, temp);
digitalWrite(ELECT_GREEN_NEG_POL, temp);
digitalWrite(ELECT_GREEN_POS_ENB, temp);
digitalWrite(ELECT_GREEN_POS_POL, temp);

digitalWrite(ELECT_BLUE_NEG_ENB, temp);
digitalWrite(ELECT_BLUE_NEG_POL, temp);
digitalWrite(ELECT_BLUE_POS_ENB, temp);
digitalWrite(ELECT_BLUE_POS_POL, temp);

digitalWrite(ELECT_PURPLE_NEG_ENB, temp);
digitalWrite(ELECT_PURPLE_NEG_POL, temp);
digitalWrite(ELECT_PURPLE_POS_ENB, temp);
digitalWrite(ELECT_PURPLE_POS_POL, temp);

digitalWrite(ELECT_GREY_NEG_ENB, temp);
digitalWrite(ELECT_GREY_NEG_POL, temp);
digitalWrite(ELECT_GREY_POS_ENB, temp);
digitalWrite(ELECT_GREY_POS_POL, temp);

digitalWrite(ELECT_WHITE_NEG_ENB, temp);
digitalWrite(ELECT_WHITE_NEG_POL, temp);
digitalWrite(ELECT_WHITE_POS_ENB, temp);
digitalWrite(ELECT_WHITE_POS_POL, temp);
}

String getCurrents(){// get the values from the current sensor
float currentBlack = ina219Black.getCurrent_mA();
float currentBrown = ina219Brown.getCurrent_mA();
float currentRed = ina219Red.getCurrent_mA();

String temp = String(currentBlack,1) + ',' + String(currentBrown,1) + ',' + String(currentRed,1) + ',' + String(millis());

return temp;
}

void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
if (inChar == '\n') stringComplete = true;
else inputString += inChar;
}
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# EAP_Hydrogels_Exhibit_Emergent_Learning_When_Embodied_in_a_Simulated_Game-Environment
This repository contains all code and data used within the experiments described in the paper “EAP Hydrogels Exhibit Emergent Learning When Embodied in a Simulated Game-Environment”. All data analysis was performed using code written in the Matlab environment, using Matlab packages, and datasets constructed in Matlab. The MEA control software was written in Python. This repository also includes an example video recording of the pong game. This repository is available on Zenodo. This repository is organised into folders according to the languages used and sections of the paper.
This repository contains all code and data used within the experiments described in the paper “EAP Hydrogels Exhibit Emergent Learning When Embodied in a Simulated Game-Environment”. All data analysis was performed using code written in the Matlab environment, using Matlab packages, and datasets constructed in Matlab. The MEA control software was written in Python, with Arduino code used to run the hydrogel interfacing hardware. This repository also includes an example video recording of the pong game. This repository is available on Zenodo. This repository is organised into folders according to the languages used and sections of the paper.

## Example Video
Each run of the pong game generates a screen recording of the simulated pong game. The video "Example Run.mp4" is one of the recordings generated through the experiments undertaken during the research this repository belongs to. For the purposes of storage capacity, the videos speed is quadrupled, and quality is compressed. This video shows the results of a default learning experiment, where the performance gradually improves thought he course of the game to a point.
Expand Down Expand Up @@ -75,6 +75,9 @@ Each run of the pong game generates a screen recording of the simulated pong gam
* "threadedPong.py"
* "Serial_plot2.py" - The serial data plotter used to record initial current values from the sense regions for use as a baseline

## Arduino
* "Array_Driver.ino" - The arduino code that communicates with the python script via serial, and coordinates the relays and sensor communication.

# Matlab Figure Commands list
This is a list of the figures present in the paper and the accompanying Matlab function/commands that render them.

Expand Down

0 comments on commit c07259c

Please sign in to comment.