Showing posts with label Astronomy. Show all posts
Showing posts with label Astronomy. Show all posts

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.

Wednesday, July 2, 2014

The Mathematics of CERN Style Software for a Cloud Chamber

INTRODUCTION
A cloud chamber is an interesting device that allows a user to see charged particles. it consists of supersaturated alcohol and water vapor which is ionized by the charged particle and begins to precipitate. Alcohol is used because its low freezing point allows for us to quickly reach the critical temperature at which ionization will cause precipitation. In this blogpost I will outline the mathematics required for the system, the mathematics for a program to automate detection, and the mathematics of the particles themselves. In an upcoming blogpost I will demonstrate an implementation of the Cloud Chamber and the software.
OVERVIEW

We begin with a brief overview of the particles themselves, as computations from this section will allow for proper design of the chamber, as well as proper mathematics and design of the subsequent program.

    Suppose a particle P was launched at a velocity V towards Earth. It will be attracted to two plates mounted to the outside of the box following the coulomb equation. Also the degree of ionization is a function of the energy and ionization ability of the particle which adjusts the width of the ionized trail, therefore an algorithm can determine a particle type simply by analyzing trail width.

Program NOTATION
Custom Operator: $x$ returns the length of x
Turing Machine: <Machine|Function*|Tape>


Boolean Algebraic Program
The A* function applies the Y filter transform onto c










Saturday, April 19, 2014

Novel Smoothing Algorithm:Morley Pinturia Naturaleza Muerta Smoothing Algorithm(Cluster Bomb Smoothing)

Cells
In the cellular automata the Morley Algorithm allows for a static "object" to occur in the above formation, however that is not the focus of this post. Instead we will be using the above geometry in order to create a basic smoothing algorithm using PImage in Processing. This post continues the Algorithm outlined in the previous post Statistically Viable Time Based Smoothing and Deconvolution Algorithm
PImage img;
int a, b,r,u;
 This sets up the image variable and the 4 vars we will be using.

void setup() {
  size(500, 500);
  img = loadImage("cat.jpg");
  a = 1;
  b = 1;
  r=img.width;
  u=0;
  imageMode(CENTER);
  noStroke();
  background(0);
}
Loading the image and setting up our variables. a & b are for rect sides or in terms of the above image they are the size of the white pieces.

void draw() { 

  float pixel = map(11, 0, width, a, b); //creating pixel variable
  int x = int((img.width)-r); // sets the x pt equal to image width minus the
                              //size of the r val which paints the image

  int y= int(u);//u as the y val due, tis necessary due to language syntax
  color pix = img.get(x, y);//captures pixel color
  fill(pix, 128);//color,alphamask
  rect(x-1, y, pixel, pixel);
  rect(x+1, y, pixel, pixel);
  rect(x, y-1, pixel, pixel);
  rect(x, y+1, pixel, pixel);//these rect lines create our Cells diagram
  r=r-1;//moves painting along the x axis
  println(r);//outputs current pos
Now there must be an if statement in order to move along the y axis once a row is completed:


if(r==1000){
  r=img.width;
   u=u+1;
}
}
And so the symphony all together:


PImage img;
int a, b,r,u;

void setup() {
  size(500, 500);
  img = loadImage("cat.jpg");
  a = 1;
  b = 1;
  r=img.width;
  u=0;
  imageMode(CENTER);
  noStroke();
  background(0);
}

void draw() { 

  float pixel = map(11, 0, width, a, b);
  int x = int((img.width)-r);
  int y= int(u);
  color pix = img.get(x, y);
  fill(pix, 128);
  rect(x-1, y, pixel, pixel);
  rect(x+1, y, pixel, pixel);
  rect(x, y-1, pixel, pixel);
  rect(x, y+1, pixel, pixel);  
  r=r-1;
  println(r);
  
if(r==1000){
  r=img.width;
   u=u+1;
}
}
The Cat's Ear without smoothing


The Cat's Ear with Cluster Smoothing

A place where the smoothing is perhaps most noticeable is in blue background, notice the falloff occurs quickly on the smoothed image but not nearly as quickly on the non-smoothed image. That is because the novel method ensures blending of the regions which guarantees blending and the elimination of noise in the image.

Statistically Viable Time Based Smoothing and Deconvolution Algorithm


Algorithm for image smoothing
PImage img;
int a, b,z,u;

void setup() {
  size(1000, 900);
  img = loadImage("sun.png");
  a = 1;
  b = 1;
  z=img.width;
  u=0;
  imageMode(CENTER);
  noStroke();
  background(255);

}

void draw() { 

  float pixel = map(11, 0, width, a, b);
  int x = int(random(img.width));
  int y = int(random(img.height));
  color pix = img.get(x, y);
  fill(pix, 128);
  rect(x-1, y, pixel, pixel);
  rect(x+1, y, pixel, pixel);
  rect(x, y-1, pixel, pixel);
  rect(x, y+1, pixel, pixel);  
  rect(x, y, pixel, pixel); 

}