Saturday, May 16, 2015

MuBox Code and Such

The above two scripts link together two of the boards, having a repeater at each fourth pin on the board so that the data is properly spaced. The main computer side has 3 simple python programs, which are really just reiterations of eachother for each serial port. It could all be integrated but, why, really?

import serial
ser=serial.Serial('/dev/ttyAMC0',9600)

while 1:
 ser.readline();
text_file = open("Output.txt", "w")
text_file.write(ser.readline())
text_file.close()
 
The line defining ser is the part that is modfied, along wiht the output *.txt file. In order to find the Serial ports on linux, just pull each arduino out individually, or plug them individually and run the following code at each iteration:

ls /dev/tty*

this will list a lookup of relevant connections:

The missing or newly added board is the Target. Ussually it will be ACM0, ACM1, USB0, or something very similar.

--------------------------------------------------------------------------------------------------------------------------------------

The Boogie Boards

The boards, I used three, two of the Uno(6 Analog pins each) and one Mega(16 Analog pins). These boards can be purchased from a spinoff company in china which prints boards that rely on the Surface Mount Chips of the ATMEGA IC's.

Anyway, each board needs its own code, for now we can just examine the Uno's as the MEGA is simply a more magnificient Uno.:



CODE:


int sensorPin = A0;        
float sensorValue = 0;
int sensorPinB = A1;        
float sensorValueB = 0;
int sensorPinC=A4;
float sensorValueC=0;
int sensorPinD=A5;
float sensorValueD=0;
float dA=0;
void setup() {
 Serial.begin(9600); 
// Serial.println();
}
void loop() {
  sensorValue = analogRead(sensorPin);
  sensorValue=(sensorValue+analogRead(sensorPin));
   sensorValue=(sensorValue+analogRead(sensorPin));
  sensorValue=(sensorValue+analogRead(sensorPin));
    sensorValue=(sensorValue+analogRead(sensorPin));
   sensorValue=(sensorValue+analogRead(sensorPin));
  sensorValue=(sensorValue+analogRead(sensorPin));
  
if(sensorValue!=0.00){
  
  

  if(1==1){
    //Serial.println("A");
    Serial.println((sensorValue/22)-dA);
    // derivatives: float dA=sensorValue/22;
  }
sensorValue=0;
}
//Lets get one going
  sensorValueB = analogRead(sensorPinB);
  sensorValueB=(sensorValueB+analogRead(sensorPinB));
   sensorValueB=(sensorValueB+analogRead(sensorPinB));
  sensorValueB=(sensorValueB+analogRead(sensorPinB));
    sensorValueB=(sensorValueB+analogRead(sensorPinB));
   sensorValueB=(sensorValueB+analogRead(sensorPinB));
  sensorValueB=(sensorValueB+analogRead(sensorPinB));
if(sensorValueB!=0.00){
  
  

  if(1==1){
   // Serial.println("");
    Serial.println((sensorValueB/22));
  }
sensorValueB=0;
}



//CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC



  sensorValueC = analogRead(sensorPinC);
  sensorValueC=(sensorValueC+analogRead(sensorPinC));
   sensorValueC=(sensorValueC+analogRead(sensorPinC));
  sensorValueC=(sensorValueC+analogRead(sensorPinC));
    sensorValueC=(sensorValueC+analogRead(sensorPinC));
   sensorValueC=(sensorValueC+analogRead(sensorPinC));
  sensorValueC=(sensorValueC+analogRead(sensorPinC));
if(sensorValueC!=0.00){
  
  


    //Serial.println("C");
    Serial.println((sensorValueC/22));
  
sensorValueC=0;
}
//Port 4(D)
//Lets get one going
  sensorValueD = analogRead(sensorPinD);
  sensorValueD=(sensorValueD+analogRead(sensorPinD));
   sensorValueD=(sensorValueD+analogRead(sensorPinD));
  sensorValueD=(sensorValueD+analogRead(sensorPinD));
    sensorValueD=(sensorValueD+analogRead(sensorPinD));
   sensorValueD=(sensorValueD+analogRead(sensorPinD));
  sensorValueD=(sensorValueD+analogRead(sensorPinD));
if(sensorValueD!=0.00){
  
  

  if(1==1){
  //  Serial.println("D");
    Serial.println((sensorValueD/22));
  }
sensorValueD=0;
}


}

So basically, we reduce the data count and the variance we get as shown in the histogram at top by sampling multiple data points, or the:
  sensorValueD = analogRead(sensorPinD);
  sensorValueD=(sensorValueD+analogRead(sensorPinD));
   sensorValueD=(sensorValueD+analogRead(sensorPinD));
  sensorValueD=(sensorValueD+analogRead(sensorPinD));
    sensorValueD=(sensorValueD+analogRead(sensorPinD));
   sensorValueD=(sensorValueD+analogRead(sensorPinD));
  sensorValueD=(sensorValueD+analogRead(sensorPinD));
 
of the code,acting as a variance limiting filter, by moving towareds the mean of 6 data points. Some need scaling to reduce size issues of the float string:
 Serial.println((sensorValueB/22));
and for some others we have to filter for 0 values, as the hardware is not as great as the software(the American method over Russian for sensors is good here because the parts are too expensive):

if(sensorValue!=0.00){
But I suppose we are all really just interested in the Graphing. Okay that is next, and connecting to the internet server(and creating it for that matter) will be the topic of another post.

---------------------------------------------------------Graph it------------------------------------------------------------


int a=1; 
 import processing.serial.*;
 
 Serial myPort;        // The serial port
 int xPos = 1;         // graph pos(x)
 
 void setup () {

 size(600, 600);        
 

 println(Serial.list());
 // ACM1 here
 myPort = new Serial(this, Serial.list()[0], 9600);

 myPort.bufferUntil('\n');

 background(255);
 }
 void draw () {

 }
 
 void serialEvent (Serial myPort) {
 // get the data
 String inString = myPort.readStringUntil('\n');
 
 if (inString != null) {

 inString = trim(inString);

 float inByte = float(inString); 
 inByte = map(inByte, 0, 1023, 0, height);
 

 stroke(127,34,255);
 line(xPos, height, xPos, height - inByte);
 
 // start a new picture
 if (xPos >= width) {
  //save(a+".png");
 a=a+1;
 xPos = 0;
 background(0); 

 } 
 else {
 // move
 xPos=xPos+2;
 
 }
 }
 } 
 
 
Yeah, well that will do it. McCormack Out.

μBox wiring with dry ice

Nothing left for me to do but dance. Will be having live stream of data eventually and remote hookup for other builds once I publish the build instructions and software. And unlike most other live data stream projects on the internet the data is useful unlike coffee temperature...

Ice from local dairy farm, available at fisheries and some welding companies as well.

Saturday, May 2, 2015

Neural Synchronizer Application



Meant to follow the idea that the waves can be synced (right and left hemispheres of the brain) through stimuli, using audio and visual. Going to add a physical piece for the palms with a high speed solenoid. I used VB because of the libs for audio(.Beep())
Vis with Processing:
void setup() {
  size(600,600);
}
void draw(){
  noCursor();
background(random(0,255));

}
The rest is using VB:
Auditory:
1
2
3
4
5
6
Public Class Form2

    Private Sub audodd_Click(sender As Object, e As EventArgs) Handles audodd.Click
        Console.Beep(250, 900000000)
    End Sub
End Class
The auditory is emmitting at 250Hz and the 900000000 is for timing.

Visual:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Public Class Form1
    Dim I As Integer

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Sync_Click(sender As Object, e As EventArgs) Handles Sync.Click
        vis.Visible = True
        Dim SecondForm As New Form2
        SecondForm.Show()
        visual.Enabled = True
        visualone.Enabled = True



    End Sub

    Private Sub visual_Tick(sender As Object, e As EventArgs) Handles visual.Tick
        vis.Visible = True


    End Sub

    Private Sub visualone_Tick(sender As Object, e As EventArgs) Handles visualone.Tick
        vis.Visible = False
    End Sub
End Class