macsbug

Just another WordPress.com site

Archive for the ‘Processing’ Category

Proximity Sensor of Arduino

leave a comment »

APDL-9960 近接センサーを試す。                                  2015.08.22


SparkFun RGB and Gesture Sensor – APDS-9960 と Arduino を配線し、Proximityセンサーを試す。
データーの表示は、Processing を使用し、オシロスコープのようにグラフ表示。
サンプルプログラムは、全て動きました。
なかなか、良い感度と精度が出ています。センシングする距離は、最大約6センチ位です。


用意するもの:
Arduino UNO と Arduino IDE 。
Library 及び サンプルプログラム:APDS-9960_RGB_and_Gesture_Sensor
プロセシング言語:Processing
SparkFun ジェスチャーセンサ( 3.3V 仕様):価格:スイッチサイエンスで、2053円(送料込み)。



配線:

 Arduino  APDL-9960
  3.3V   VCC
  GND   GND
  A4(4)   SDA
  A5(5)   SCL

 


APDL-9960:仕様:

  • Operational Voltage: 3.3V
  • Ambient Light & RGB Color Sensing
  • Proximity Sensing
  • Gesture Detection
  • Operating Range: 4-8in (10-20cm)
  • I2C Interface (I2C Address: 0x39)

 


Arduino と Processing のスケッチ:

Arduino:


/*********************************************************
Proximity Test
Hardware Connections:The APDS-9960 can only accept 3.3V! 
 Arduino Pin  APDS-9960 Board  Function 
 3.3V         VCC              Power
 GND          GND              Ground
 A4           SDA              I2C Data
 A5           SCL              I2C Clock
*********************************************************/
#include <Wire.h>
#include <SparkFun_APDS9960.h>
SparkFun_APDS9960 apds = SparkFun_APDS9960();
uint8_t proximity_data = 0;

void setup() {
  Serial.begin(115200);
  apds.init();
  apds.setProximityGain(PGAIN_1X);
  apds.enableProximitySensor(false) ;
}

void loop() {
  if ( apds.readProximity(proximity_data)){
    Serial.write('H');             // Header
    Serial.write(proximity_data);  // 0 - 255
  } 
  delay(50);
}


Processing:


import  processing.serial.*;
Serial  serial;
int[]   data;

void setup() {  
  size(700, 240);
  data = new int [width];
  serial = new Serial( this, Serial.list()[0], 115200 );
}

void draw() {
 background(10);
 strokeWeight(2); 
 stroke(0, 255, 0);
 for (int i=0; i<data.length-1; i++) {            // GRAPH DRAW
   line( i, data[i], i+1, data[i+1] );
 } 
} 

void serialEvent(Serial port) {
 if ( port.available() >= 3 ) {
   if ( port.read() == 'H' ) {   
     int recv_data = port.read();                  // DATA READ     
     for (int i=0; i<data.length-1; i++) {        // GRAPH DATA UP
       data[i] = data[i+1];
     }
     data[data.length-1] = recv_data;
   }
 }
}

float convToGraphPoint(int value) {
  return (height - value*height/256);
}


メモ:
Processing は、画像を表示をするのに便利です。
_ 今回は、シリアルデーターをオシロスーコープにするサンプルを参考にしました。
_ 信号は、Arduio : Sensor -> Serial.write(data); -> Processing : port.read(); という流れです。
_ スケッチは、簡単に変更して使え、他の Arduino のセンサーの動作確認にも便利です。
_ Export Application を選択すると Windows, Mac, Linux の単独アプリが作れます。
製品の注意:ebay で販売されている APDL9930 は格安ですが Proximityセンサー機能はありません。
_  参考:じわじわ進む:ArduinoとAPDL9930(9960じゃなくて)


 

Written by macsbug

8月 23, 2015 at 3:10 am

カテゴリー: Arduino, Processing

Indication of FLAG WORD MONITOR demo

leave a comment »

Indication of FLAG WORD MONITOR demo ( x size=1020)

左は、32bitをLED表示。右のグラフは32bitを時間軸で表現したものです。
PAUSEボタンは途中で停止したい場合に押します。

296

Written by macsbug

9月 21, 2014 at 4:10 am

カテゴリー: Processing

MONITOR PROCESSOR FLAG WORD MONITOR demo of Processing

leave a comment »

「32bit デジタル・アナライザー」のデモ版で、Arinc 429 Receiver Board は不要です。       2014.09.21

Processing 言語により、Mac 叉はWindows に表示します。

MONITOR PROCESSOR FLAG WORD MONITOR demo of Processing
Without Monitor Circuit( Arinc 429 Receiver) of Arduino

//---------------------------------------------------------------------------
// A429RX_MON_FLAG_demo_140915
// XXX-XXX RADIO ALT TRANSCEIVER MONITOR Processor Flag Word MONITOR
// ORG ALTITUDE FLAG WORD Copy                          2010.12.21    S.mac
// REV Mode 0,2,3 , PAD check & info                    2010.12.22    S.mac
// REV x display size, demo mode                        2014.09.21    S.mac
// REC DISABLE on=9.8msec/off=25ms,A429 32bit=2.54ms,Serial=2ms
//--------------------------------------------------------------------------
import processing.serial.*;         // serial liblary include
Serial PortA;                       // seria read position
int c=1;                            // Read data count
int d=2;                            // xline width
int x1=350;                         // xline start position       
int xw=1020;                        // 700,1020,
int pwr=0;                          // PAUSE Position
int pcg=0;                          // Pause memo
char [] bit = new char [33];        // A429 SERIAL RECEIVE DATA Buffer
char [] bix = new char [33];        // before 32bit
String [] m = {                     // FLAG WORD 32BIT LIST(0 to 31)
  "PAD (always high)","ALTIMETER STATUS","MATH","COUNTER MODE",
  "PAD (always low)","SELF-TEST","SELF-TEST DELTA","SELF-TEST ERROR",
  "MONITOR","PASS COUNTER","MODE ERROR","UART","SSM",
  "BINALY ALTITUDE COMPARISION","VALID DATA","LIFSPST","INPUT",
  "CURRENT ALTIMETER MODE-(LSB)","CURRENT ALTIMETER MODE-(MSB)",
  "LO IF SIGNAL PRESENCE","HI IF SIGNAL PRESENCE","LIFSPDR","HIFSPDR",
  "PAD","40 FOOT AID","57 FOOT AID","80 FOOT AID","RAM PASS LOW",
  "RAM PASS HIGH","ROM PASS","POWER","PARITY"};
String [] n = {"01","02","03","04","05","06","07","08","09","10","11",
  "12","13","14","15","16","17","18","19","20","21","22","23","24",
  "25","26","27","28","29","30","31","32"};      // bit No 01-32
//---------------------------------------------------------------------------
void setup(){                                    // Windows : COM*
  //PortA=new Serial(this,"COM4",115200);          // 2msec(32bit)
  PortA=new Serial(this,"/dev/cu.usbserial-A900acDW",115200);// Mac
  size(xw,740);                                  // Graphic area size(x,y)
  noStroke();background(0);                      // BackGround Color=Black
  fill(255); text("XXX-XXX MONITOR Processor Flag Word",100,0,600,48);
  //fill(255); text("*.*.co.,Ltd. / RA Group",480,0,600,48);
  //fill(255); text("by oono 2010",492,20,600,48);                       
  for (int i=0; i<32; i=i+1){fill(255); text(n[i],20,60+20*i,600,48);
        fill(255); text( m[i],100,60+20*i,600,48);}
  for (int i=0; i<640; i=i+20){fill(153,255,0); rect(50,60+i,34,12);}
  fill(255,0,0); rect(50,22,17,12); fill(120,140,255); rect(67,22,17,12);
  fill(255); text("bit       1   0     FLAG WORD",20,19,600,48);  
  noStroke(); fill(120,140,255); rect(x1-d,60,d*2,635);  
  setButton(120,140,255);                        // PAUSE Button color set
}
//---------------------------------------------------------------------------
// ARINC429 SERIAL DATA RECEIVE AND DISPLAY      //
void draw(){                                     //
  if ( pwr==0 ){ noStroke();                     // PAUSE ON/OFF pwr=0(OFF)
   fill(120,140,255);rect(x1+d,60,d*2,635);      //_wave start bar
   stroke(255);                                  //_Line Set
  //if (PortA.available()==34){                    // 32+2Bit(end data)    *****
  //---------------------------------------------// 32bit Reading
    for ( int i=0; i<32; i=i+1 ){                // 32bit = 0 to 31
      //bit[i] = PortA.readChar();}                // SerialRead & Store   *****
      if ( random(10) < 5 ){ bit[i]  = '0';}      //                       *****
      if ( random(10) > 4 ){ bit[i]  = '1';}      //                       *****
    //PortA.clear();                               // Serial Port Clear    *****
    }                                            //                        *****
  //---------------------------------------------//
    if ( bit[0]=='1' && bit[4]=='0'){            // PAD 1 or 2 check
  //---------------------------------------------// 32bit Display
    for ( int i=0; i<32; i=i+1 ){                // 32bit = 0 to 31
      int HI=62+i*20; int LO=70+i*20;            //_LOGIC HI/LO pos
      if (bit[i] != bix[i]){line(x1,LO,x1,HI);}  //_bit changed V-line
      if (bit[i] == '0'){fill(120,140,255);      // bit0 fill color set
       line(x1,LO,x1+d,LO);                      //_bit0 LO Line draw
      }                                          // END bit 0
      else{ println(m[i]);fill(255,0,0);         // bit1 print,fill set
       line(x1,HI,x1+d,HI);                      //_bit1 HI line draw
      }                                          // END bit 1
      rect(50,60+i*20,34,12);                    // flag word bit 0-31
      bix[i]=bit[i];                             //_store bit "0" or "1"
    }                                            // END 32bit Display
  //---------------------------------------------// MODE Display Info
    fill(0,0,0); rect(200,22,50,12);             // disply & Proc window
    if (bit[17]=='0' && bit[18]=='0'){           // CAM L=0,CAM H=0
      println("MODE 0");                         // Processing window PRT
      fill(255);text("MODE 0",200,19,600,48);}   // display Print
    if (bit[17]=='0' && bit[18]=='1'){           // CAM L=0,CAM H=1
      println("MODE 2");                         // Processing window PRT
      fill(255);text("MODE 2",200,19,600,48);}   // display Print
    if (bit[17]=='1' && bit[18]=='1'){           // CAM L=1,CAM H=1
      println("MODE 3");                         // Processing window PRT
      fill(255);text("MODE 3",200,19,600,48);}   // display Print
  //---------------------------------------------//
    x1=x1+d;                                     //_next x1
    if ( x1>xw-10 ){ x1=350;}                    //_x line reset
    println (c);                                 // Count display
    c=c+1;                                       // Read data count up
  //---------------------------------------------//
    }                                            // END PAD check
  //---------------------------------------------//   
  //}                                              // END PortA.available   *****
  }                                              // END PAUSE
  //---------------------------------------------//  
   if(keyPressed) {                              // PAUSE Key ( p or P )
    if(key == 'p' || key == 'P'){ PauseSet();}   // PAUSE ON/OFF Button set
   }                                             //
  //PortA.clear();                               // Serial Port Clear
}                                                // END Void draw
//---------------------------------------------------------------------------
void mousePressed(){                             // Mouse press
  if(mouseX>340 && mouseX<420 && mouseY>35 && mouseY<55){
    PauseSet();}                                 // PAUSE ON/OFF Button set
}                                                //
//---------------------------------------------------------------------------
void setButton(color c1,color c2,color c3){      // PAUSE Button Bar set
  fill(c1,c2,c3); rect(345,35,73,20);            // Bar color set
  fill(255); text("PAUSE",363,50);               // text set
}                                                //
//---------------------------------------------------------------------------
void PauseSet(){                                 // PAUSE ON/OFF set
  if (pwr==0){ pcg=1; setButton(255,0,0);}       // PAUSE ON  Button set
  else {pcg=0; setButton(120,140,255);}          // PAUSE OFF Button set
  pwr = pcg; delay(500); PortA.clear();          // PAUSE memo, chataring
}                                                //
//---------------------------------------------------------------------------

Written by macsbug

9月 21, 2014 at 3:45 am

カテゴリー: Processing

MONITOR PROCESSOR FLAG WORD of Processing

with one comment

MONITOR PROCESSOR FLAG WORD of Processing                                               2014.09.21

With Monitor circuit(Arinc 429 Receiver) of Arduino

//---------------------------------------------------------------------------
// A429_MON_FLAG_20101222
// XXX-XXX RADIO ALT TRANSCEIVER MONITOR Processor Flag Word MONITOR
// ORG Altitude Flag Word Copy                     2010.12.20    S.mac
// REV Serial error pass                           2010.12.22    S.mac
// REV x display size                              2014.09.21    S.mac
// REC DISABLE on=9.8msec/off=25ms,A429 32bit=2.54ms,Serial=2ms
//---------------------------------------------------------------------------
import processing.serial.*;         // serial liblary include
Serial PortA;                       // seria read position
int c=1;                            // Read data count
int d=2;                            // xline width
int x1=350;                         // xline start position
int xw=1020;                        // x display size
int pwr=0;                          // PAUSE Position
int pcg=0;                          // Pause memo
char [] bit = new char [33];        // A429 SERIAL RECEIVE DATA Buffer
char [] bix = new char [33];        // before 32bit
String [] m = {                     // FLAG WORD 32BIT LIST(0 to 31)
  "PAD (always high)","ALTIMETER STATUS","MATH","COUNTER MODE",
  "PAD (always low)","SELF-TEST","SELF-TEST DELTA","SELF-TEST ERROR",
  "MONITOR","PASS COUNTER","MODE ERROR","UART","SSM",
  "BINALY ALTITUDE COMPARISION","VALID DATA","LIFSPST","INPUT",
  "CURRENT ALTIMETER MODE-(LSB)","CURRENT ALTIMETER MODE-(MSB)",
  "LO IF SIGNAL PRESENCE","HI IF SIGNAL PRESENCE","LIFSPDR","HIFSPDR",
  "PAD","40 FOOT AID","57 FOOT AID","80 FOOT AID","RAM PASS LOW",
  "RAM PASS HIGH","ROM PASS","POWER","PARITY"};
String [] n = {"01","02","03","04","05","06","07","08","09","10",
               "11","12","13","14","15","16","17","18","19","20",
               "21","22","23","24","25","26","27","28","29","30","31","32"};
//---------------------------------------------------------------------------

void setup(){                                    // Windows : COM*
  //PortA=new Serial(this,"COM4",115200);          // 2msec(32bit)
  PortA=new Serial(this,"/dev/cu.usbserial-A900acDW",115200);// Mac
  size(xw,740);                                  // Graphic area size(x,y)
  noStroke();background(0);                      // BackGround Color=Black
  fill(255); text("XXX-XXX MONITOR Processor Flag Word",100,0,600,48);
  //fill(255); text( "*.*.co.,Ltd. / RA Group",480,0,600,48);
  //fill(255); text( "by oono 2010",492,20,600,48);                       
  for ( int i=0; i<32; i=i+1 ){ fill(255); text( n[i],20,60+20*i,600,48);
        fill(255); text( m[i],100,60+20*i,600,48);}
  for ( int i=0; i<640; i=i+20 ){ fill(153,255,0); rect(50,60+i,34,12);}
  fill(255,0,0); rect(50,20,17,12); fill(120,140,255); rect(67,20,17,12);
  fill(255); text( "bit       1   0     FLAG WORD",20,19,600,48);  
  noStroke();fill(120,140,255);rect(x1-d,60,d*2,635);  
  setButton(120,140,255);                        // PAUSE Button color set
}

//---------------------------------------------------------------------------
// ARINC429 SERIAL DATA RECEIVE AND DATA STORE   //
void draw(){                                     //
  if ( pwr==0 ){ noStroke();                     // PAUSE ON/OFF pwr=0(OFF)
  fill(120,140,255);rect(x1+d,60,d*2,635);       // wave start bar
  stroke(255);                                   // Line Set
  //---------------------------------------------// 32Bit Read start
  if (PortA.available()>33){                     // 32+1Bit(end data)
    for ( int i=0; i<32; i=i+1 ){                // 32bit = 0 to 31
      bit[i] = PortA.readChar();                 // SerialRead & Store
    }                                            //
    PortA.clear();                               // Serial Port Clear
  }                                              // 32Bit Read end
  //---------------------------------------------//    
    if (bit[0]=='0' || bit[4]=='1'){             // PAD1 or 2 NG Pass
  //---------------------------------------------// 32Bit Display  
    for ( int i=0; i<32; i=i+1 ){                // 32bit = 0 to 31   
      int HI=62+i*20; int LO=70+i*20;            // LOGIC Level HI/LO pos
      if (bit[i] != bix[i]){line(x1,LO,x1,HI);}  // bit changed V-line
      if (bit[i] == '0'){fill(120,140,255);      // bit 0 --------------
       line(x1,LO,x1+d,LO);                      // bit 0 level set LO
      }                                          // --------------------
      else{ println(m[i]);fill(255,0,0);         // bit 1 , STATUS print
       line(x1,HI,x1+d,HI);                      // bit 1 level set HI
      }                                          // --------------------
      rect(50,60+i*20,34,12);                    // Draw bit
      bix[i]=bit[i];                             // store bit "0" or "1"
    }                                            // --------------------
  //---------------------------------------------// Draw Line Next
    x1=x1+d;                                     // next x1
    if ( x1 > xw-10 ){ x1=350 ;}                 // x line reset
    println (c);                                 // Counter display
    c=c+1;                                       // Read data count up
   }                                             // PAD NG
  //---------------------------------------------//        
  }                                              // end pause
  //---------------------------------------------//
   if(keyPressed) {                              // PAUSE Key ( p or P )
    if(key == 'p' || key == 'P'){PauseSet();}    // PAUSE ON/OFF Button set
   }                                             //
  //---------------------------------------------//   
}                                                // end void draw

//---------------------------------------------------------------------------
void mousePressed(){                             // Mouse press
  if(mouseX>340 && mouseX<420 && mouseY>35 && mouseY<55){
    PauseSet();}                                 // PAUSE ON/OFF Button set
}                                                //
//---------------------------------------------------------------------------
void setButton(color c1,color c2,color c3){      // PAUSE Button Bar set
  fill(c1,c2,c3); rect(345,35,73,20);            // Bar color set
  fill(255); text("PAUSE",363,50);               // text set
}                                                //
//---------------------------------------------------------------------------
void PauseSet(){                                 // PAUSE ON/OFF set
  if ( pwr==0) { pcg=1; setButton(255,0,0);}     // PAUSE ON  Button set
  else { pcg=0; setButton(120,140,255);}         // PAUSE OFF Button set
  pwr = pcg; delay(500); PortA.clear();          // PAUSE memo, chataring
}                                                //
//---------------------------------------------------------------------------

Written by macsbug

9月 21, 2014 at 3:39 am

カテゴリー: Processing

ALTITUDE PROCESSOR FLAG WORD MONITOR demo for Processeing

leave a comment »

ALTITUDE PROCESSOR FLAG WORD demo for Processeing                                     2014.09.21

Without Monitor Circuit(Arinc 429 Receiver) of Arduino

//---------------------------------------------------------------------------
// A429RX_ALT_FLAG_demo_140915
// XXX-XXX RADIO ALT TRANSCEIVER : Altitude Processor Flag Word Minitor
// ORG SerialEvent                                      2010.10.10    S.mac
// REV Color bar,Hi Speed,SerialEvent->Draw,Vertical    2010.10.11-13 S.mac
// REV Waveform display,PAUSE Button & Key              2010.10.18    S.mac
// REV x display size  set, Demo mode                   2014.09.21    S.mac
// INFO PortA.available()>=34
// REC DISABLE on=9.8msec/off=25ms,A429 32bit=2.54ms,Serial=2ms
//---------------------------------------------------------------------------
import processing.serial.*;         // serial liblary include
Serial PortA;                       // seria read position
int c=1;                            // Read data count
int d=2;                            // xline width
int x1=350;                         // xline start position
int xw=1020;                        // x width 700,1020,
int pwr=0;                          // PAUSE Position
int pcg=0;                          // Pause memo
char [] bit = new char [33];        // A429 SERIAL RECEIVE DATA Buffer
char [] bix = new char [33];        // before 32bit
String [] m = {                     // FLAG WORD 32BIT LIST(0 to 31)
  "PAD (always high)","ALTIMETER STATUS","MONITOR STATUS","COUNTER MODES",
  "PAD (always low)","INPUT (Discreate:Arinc,AID,ANT,flag)",
  "UART","BINARY ALTITUDE COMPARISION","SELF-TEST","SELF-TEST DELTA",
  "SELF-TEST ERROR","LIFSPDR","HIFSPDR","LIFSPST","LO IF SIGNAL PRESENCE",
  "HI IF SIGNAL PRESENCE","40 FOOT AID","57 FOOT AID","80 FOOT AID",
  "RAM TEST (RAM CHECKS OK)","ROM TEST (ROM CHECKS OK)","SDI-(LSB)",
  "SDI-(MSB)","FRONT PANEL SELF-TEST","MATH","VALID DATA",
  "CURRENT ALTIMETER MODE-(LSB)","CURRENT ALTIMETER MODE-(MSB)",
  "BAND SWITCHES-(LSB)","BAND SWITCHES","BAND SWITCHES-(MSB)","PARITY"};
String [] n = {"01","02","03","04","05","06","07","08","09","10",
               "11","12","13","14","15","16","17","18","19","20",
               "21","22","23","24","25","26","27","28","29","30","31","32"};
//---------------------------------------------------------------------------
void setup(){                                    // Windows : COM*
  PortA=new Serial(this,"/dev/cu.usbserial-A900acDW",115200);// 2msec(32bit)
  size(xw,740);                                  // Graphic area size(x,y)
  noStroke();background(0);                      // BackGround Color=Black
  fill(255); text( "XXX-XXX ALTITUDE PROCESSOR FLAG WORD",100,0,600,48);
  //fill(255); text( "*.*.*.co.,Ltd. / RA Group",480,0,600,48);
  //fill(255); text( "by oono 2010",492,20,600,48);                       
  for ( int i=0; i<32; i=i+1 ){ fill(255); text( n[i],20,60+20*i,600,48);
        fill(255); text( m[i],100,60+20*i,600,48);}
  for ( int i=0; i<640; i=i+20 ){ fill(153,255,0); rect(50,60+i,34,12);}
  fill(255,0,0); rect(50,20,17,12); fill(120,140,255); rect(67,20,17,12);
  fill(255); text( "bit    1   0     FLAG WORD",20,19,600,48);  
  noStroke();fill(120,140,255);rect(x1-d,60,d*2,635);  
  setButton(120,140,255);                        // PAUSE Button color set
}
//---------------------------------------------------------------------------
// ARINC429 SERIAL DATA RECEIVE AND DATA STORE   //
void draw(){                                     //
  if ( pwr==0 ){ noStroke();                     // PAUSE ON/OFF pwr=0(OFF)
  fill(120,140,255);rect(x1+d,60,d*2,635);       // wave start bar
  stroke(255); 
                                                 // Line Set
  //if (PortA.available()>=34){                    // 32+2Bit(end data)   *****
    for ( int i=0; i<32; i=i+1 ){                // 32bit = 0 to 31
     // bit[i] = PortA.readChar();                 // SerialRead & Store  *****
     if ( random(10) < 5 ){ bit[i]  = '0';}      //                       *****
     if ( random(10) > 4 ){ bit[i]  = '1';}      //                       *****
   
      int HI=62+i*20; int LO=70+i*20;            // LOGIC Level HI/LO pos
      if (bit[i] != bix[i]){line(x1,LO,x1,HI);}  // bit changed V-line
      if (bit[i] == '0'){fill(120,140,255);      // bit 0 --------------
       line(x1,LO,x1+d,LO);                      // bit 0 level set LO
      }else{ println(m[i]);fill(255,0,0);        // bit 1 , STATUS print
       line(x1,HI,x1+d,HI);                      // bit 1 level set HI
      }                                          // --------------------
      rect(50,60+i*20,34,12);                    // Draw bit
      bix[i]=bit[i];                             // store bit "0" or "1"
    }                                            // --------------------
    x1=x1+d;                                     // next x1
    if ( x1 > xw-10 ){ x1=350;}                  // x line reset
    PortA.clear();                               // Serial Port Clear
    println (c);                                 // Nomen display
    c=c+1;                                       // Read data count up
  //}                                              //                    *****
  }                                              // --------------------
   if(keyPressed) {                              // PAUSE Key ( p or P )
    if(key == 'p' || key == 'P'){ PauseSet();}   // PAUSE ON/OFF Button set
   }                                             //
  PortA.clear();                                 // Serial Port Clear
}                                                //
//---------------------------------------------------------------------------
void mousePressed(){                             // Mouse press
  if(mouseX>340 && mouseX<420 && mouseY>35 && mouseY<55){
    PauseSet();}                                 // PAUSE ON/OFF Button set
}                                                //
//---------------------------------------------------------------------------
void setButton(color c1,color c2,color c3){      // PAUSE Button Bar set
  fill(c1,c2,c3); rect(345,35,73,20);            // Bar color set
  fill(255); text("PAUSE",363,50);               // text set
}                                                //
//---------------------------------------------------------------------------
void PauseSet(){                                 // PAUSE ON/OFF set
  if ( pwr==0) { pcg=1; setButton(255,0,0);}     // PAUSE ON  Button set
  else { pcg=0; setButton(120,140,255);}         // PAUSE OFF Button set
  pwr = pcg; delay(500); PortA.clear();          // PAUSE memo, chataring
}                                                //
//---------------------------------------------------------------------------

Written by macsbug

9月 21, 2014 at 3:26 am

カテゴリー: Processing

ALTITUDE PROCESSOR FLAG WORD MONITOR for Processing

leave a comment »

ALTITUDE PROCESSOR FLAG WORD MONITOR for Processing                                    2014.09.21

With Monitor circuit(Arinc 429 Receiver)of Arduino

//---------------------------------------------------------------------------
// A429RX_ALT_FLAG_140910
// XXX-XXX RADIO ALT TRANSCEIVER : Altitude Processor Flag Word Minitor
// ORG SerialEvent                                      2010.10.10    S.mac
// REV Color bar,Hi Speed,SerialEvent->Draw,Vertical    2010.10.11-13 S.mac
// REV Waveform display,PAUSE Button & Key              2010.10.18    S.mac
// REV x display size  set                              2014.09.21    S.mac
// INFO PortA.available()>=34
// REC DISABLE on=9.8msec/off=25ms,A429 32bit=2.54ms,Serial=2ms
//---------------------------------------------------------------------------
import processing.serial.*;         // serial liblary include
Serial PortA;                       // seria read position
int c=1;                            // Read data count
int d=2;                            // xline width
int xw=700;                         // x display size
int x1=350;                         // xline start position
int pwr=0;                          // PAUSE Position
int pcg=0;                          // Pause memo
char [] bit = new char [33];        // A429 SERIAL RECEIVE DATA Buffer
char [] bix = new char [33];        // before 32bit
String [] m = {                     // FLAG WORD 32BIT LIST(0 to 31)
  "PAD (always high)","ALTIMETER STATUS","MONITOR STATUS","COUNTER MODES",
  "PAD (always low)","INPUT (Discreate:Arinc,AID,ANT,flag)",
  "UART","BINARY ALTITUDE COMPARISION","SELF-TEST","SELF-TEST DELTA",
  "SELF-TEST ERROR","LIFSPDR","HIFSPDR","LIFSPST","LO IF SIGNAL PRESENCE",
  "HI IF SIGNAL PRESENCE","40 FOOT AID","57 FOOT AID","80 FOOT AID",
  "RAM TEST (RAM CHECKS OK)","ROM TEST (ROM CHECKS OK)","SDI-(LSB)",
  "SDI-(MSB)","FRONT PANEL SELF-TEST","MATH","VALID DATA",
  "CURRENT ALTIMETER MODE-(LSB)","CURRENT ALTIMETER MODE-(MSB)",
  "BAND SWITCHES-(LSB)","BAND SWITCHES","BAND SWITCHES-(MSB)","PARITY"};
String [] n = {"01","02","03","04","05","06","07","08","09","10",
               "11","12","13","14","15","16","17","18","19","20",
               "21","22","23","24","25","26","27","28","29","30","31","32"};
//---------------------------------------------------------------------------
void setup(){                                    // Windows : COM*
  PortA=new Serial(this,"/dev/cu.usbserial-A900acDW",115200);// 2msec(32bit)
  size(xw,740);  // x size                       // Graphic area size(x,y)
  noStroke();background(0);                      // BackGround Color=Black
  fill(255); text( "XXX-XXX ALTITUDE PROCESSOR FLAG WORD",100,0,600,48);
  //fill(255); text( "*.*.*.co.,Ltd. / RA Group",480,0,600,48);
  //fill(255); text( "by oono 2010",492,20,600,48);                       
  for ( int i=0; i<32; i=i+1 ){ fill(255); text( n[i],20,60+20*i,600,48);
        fill(255); text( m[i],100,60+20*i,600,48);}
  for ( int i=0; i<640; i=i+20 ){ fill(153,255,0); rect(50,60+i,34,12);}
  fill(255,0,0); rect(50,20,17,12); fill(120,140,255); rect(67,20,17,12);
  fill(255); text( "bit    1   0     FLAG WORD",20,19,600,48);  
  noStroke();fill(120,140,255);rect(x1-d,60,d*2,635);  
  setButton(120,140,255);                        // PAUSE Button color set
}
//---------------------------------------------------------------------------
// ARINC429 SERIAL DATA RECEIVE AND DATA STORE   //
void draw(){                                     //
  if ( pwr==0 ){ noStroke();                     // PAUSE ON/OFF pwr=0(OFF)
  fill(120,140,255);rect(x1+d,60,d*2,635);       // wave start bar
  stroke(255); 
                                                 // Line Set
  if (PortA.available()>=34){                    // 32+2Bit(end data)
    for ( int i=0; i<32; i=i+1 ){                // 32bit = 0 to 31
      bit[i] = PortA.readChar();                 // SerialRead & Store
      int HI=62+i*20; int LO=70+i*20;            // LOGIC Level HI/LO pos
      if (bit[i] != bix[i]){line(x1,LO,x1,HI);}  // bit changed V-line
      if (bit[i] == '0'){fill(120,140,255);      // bit 0 --------------
       line(x1,LO,x1+d,LO);                      // bit 0 level set LO
      }else{ println(m[i]);fill(255,0,0);        // bit 1 , STATUS print
       line(x1,HI,x1+d,HI);                      // bit 1 level set HI
      }                                          // --------------------
      rect(50,60+i*20,34,12);                    // Draw bit
      bix[i]=bit[i];                             // store bit "0" or "1"
    }                                            // --------------------
    x1=x1+d;                                     // next x1
    if ( x1 > xw-10 ){ x1=350;}                  // x line reset
    PortA.clear();                               // Serial Port Clear
    println (c);                                 // Nomen display
    c=c+1;                                       // Read data count up
  }                                              //
  }                                              // --------------------
   if(keyPressed) {                              // PAUSE Key ( p or P )
    if(key == 'p' || key == 'P'){ PauseSet();}   // PAUSE ON/OFF Button set
   }                                             //
  PortA.clear();                                 // Serial Port Clear
}                                                //
//---------------------------------------------------------------------------
void mousePressed(){                             // Mouse press
  if(mouseX>340 && mouseX<420 && mouseY>35 && mouseY<55){
    PauseSet();}                                 // PAUSE ON/OFF Button set
}                                                //
//---------------------------------------------------------------------------
void setButton(color c1,color c2,color c3){      // PAUSE Button Bar set
  fill(c1,c2,c3); rect(345,35,73,20);            // Bar color set
  fill(255); text("PAUSE",363,50);               // text set
}                                                //
//---------------------------------------------------------------------------
void PauseSet(){                                 // PAUSE ON/OFF set
  if ( pwr==0) { pcg=1; setButton(255,0,0);}     // PAUSE ON  Button set
  else { pcg=0; setButton(120,140,255);}         // PAUSE OFF Button set
  pwr = pcg; delay(500); PortA.clear();          // PAUSE memo, chataring
}                                                //
//---------------------------------------------------------------------------

Written by macsbug

9月 21, 2014 at 3:17 am

カテゴリー: Processing