Überprüfung des Xadow Wearable Kit für Intel Edison und Erstellung eines darauf basierenden seltsamen Spiels



, Intel Edison , Arduino, , . , Edison .
, Intel Edison . , . Hirose 70 1 . Xadow Wearable Kit for Intel Edison Seeed, , .


, FCC. , .

, :



  • Xadow — Edison – Intel Edison.
  • Xadow — 3Axis Accelerometer — .
  • Xadow — Edison Programmer – USB.
  • Xadow — Barometer BMP 180 – .
  • Xadow — Edison SD – SD .
  • Battery – .
  • Xadow — Q Touch Sensor – .
  • Digital RGB LED Flexi-Strip — RGB-.
  • Xadow — NFC — NFC .
  • Xadow — Breakout — .
  • Xadow – Buzzer – .
  • Xadow — Vibration Motor – .
  • Xadow — OLED – OLED 128x64.
  • NFC Tags – 3 NFC-.
  • FFC cable package – .
  • Power cable White, Red, Yellow – .



, , . -, .


configure_edison –version

159.

. .
opkg update
opkg upgrade

Arduino IDE. Seeed, .

Intel XDK for IoT ++, .
- , Arduino. - I2C. . , OLED , , - . .
Arduino IDE, . , :
systemctl stop clloader

/sketch, Arduino IDE. Intel Edison (shutdown now), , PWR .

, Edison. . /etc/init.d, automateSketch.sh, :
#!/bin/sh
exec /sketch/sketch.elf /dev/ttyGS0 /dev/ttyGS0

:
chmod +x automateSketch.sh

:
update-rc.d automateSketch.sh defaults



Intel Edison.
Arduino , , Arduino IDE, . www.arduino.cc.

, Xadow-Edison Programmer . USB , , Arduino IDE. Device. Arduino IDE Intel Edison Boards Manager.

Edison ( 30 ) .



Intel Edison Virtual Com Port (COM25) — Arduino IDE.
USB Serial Port (COM29) — , , Putty.


, Intel Edison. . .

FFC – . . , . . . . , , 3 . .



. . 1 . , , , . , 3 . , . .
.



, . , , , .



Arduino


. github.com/Seeed-Studio/Xadow_Edison_Demos .ZIP . , , .

Battery


Li-Ion . 3.7V. 500 mAh.



Xadow — Edison




Edison. Edison. , Edison . Arduino .

. . Edison-Programmer. — . SD .
PWR FW_RCVR. PWR . 9 — , 2 — .

, . . , USB. , . , .

, , Edison. , , .



. — Linux’, WiFi.

Xadow — Edison Programmer




. . Micro USB :
— UART COM .
— Device/Host Arduino IDE. Device Host . Arduino Device.

Xadow — Edison SD




SD . .
SD /dev/mmcblk1
Linux. - , :
mkdir /home/data

:
mount /dev/mmcblk1   /home/data 

Linux , /etc/fstab
/dev/mmcblk1	/home/data	auto	auto 0 0


Xadow – OLED 12864


OLED 128x64 .



seeed.
I2C. 0x3C.

, .

#include <Wire.h>
#include <SeeedOLED.h>

void setup()
 {
  Wire.begin();
  SeeedOled.init();  //initialze SEEED OLED display
  SeeedOled.clearDisplay();          //clear the screen and set start position to top left corner
  SeeedOled.setBrightness(255);
  SeeedOled.setNormalDisplay();      //Set display to normal mode (i.e non-inverse mode)
  SeeedOled.setPageMode();           //Set addressing mode to Page Mode
  SeeedOled.setTextXY(0,0);          //Set the cursor to Xth Page, Yth Column  
  SeeedOled.putString("Xadow and Edison"); //Print the String

  SeeedOled.setTextXY(7,0);          //Set the cursor to Xth Page, Yth Column  
  for(int k = 0; k < 128; k++)
  {
    SeeedOled.sendData(k);
  }
}

void loop() {
}

, .
8 , 16 .

SeeedOLED :

init() – .
sendCommand(unsigned char command)
setBrightness(unsigned char Brightness) –
setHorizontalMode()
setPageMode()
setTextXY(unsigned char Row, unsigned char Column) – . , , , . .
clearDisplay() – .
sendData(unsigned char Data) –
putChar(unsigned char C) – . 32-127
putString(const char *String) –
putNumber(long long_num) —
putFloat(float floatNumber,unsigned char decimal) — float
putFloat(float floatNumber) — float
drawBitmap(unsigned char *bitmaparray,int bytes) – . .
setHorizontalScrollProperties(bool direction,unsigned char startPage, unsigned char endPage, unsigned char scrollSpeed)
activateScroll() –
deactivateScroll() – .
setNormalDisplay() – , . .
setInverseDisplay() – . .

Xadow – Buzzer.




11 13. . , 0 1 .

, 1 , .

:

void buzzerInit()
{
    pinMode(11,OUTPUT);
    pinMode(13,OUTPUT);
}

void buzzerOn()
{
    digitalWrite(11,HIGH);
    digitalWrite(13,HIGH); 
}

void buzzerOff()
{
    digitalWrite(11,LOW);
    digitalWrite(13,LOW);
}

void buzzerSignal(int t_ms)
{
    unsigned long cur = millis(); 
    while((millis()-cur) < t_ms )
    {
        buzzerOn();
        delayMicroseconds(150);
        buzzerOff();
        delayMicroseconds(150);
    }
}

void setup()	
{
    buzzerInit();	
    buzzerSignal(1000);
}
 
void loop()	 	
{	
}

, . .
, , Intel XDK for IoT ++. .

Xadow — Vibration Motor.




. .

// Xadow - Vibro
void vibroInit()
{
    pinMode(11,OUTPUT);
    pinMode(10,OUTPUT);
}

void vibroOn()
{
    digitalWrite(11,HIGH);
    digitalWrite(10,HIGH); 
}

void vibroOff()
{
    digitalWrite(11,LOW);
    digitalWrite(10,LOW);
}

void setup()	
{
    vibroInit();	
    vibroOn();
    delay(500);
    vibroOff();
}
 
void loop()	 	
{	
}

, , 1.

Xadow — Q Touch Sensor




. I2C 0x1B.
. . .

, :

#include <Wire.h>
#include "Seeed_QTouch.h"

void setup()
{
    Serial.begin(9600);
    Wire.begin();
}

void loop()
{
    int tn = QTouch.touchNum();
    
    if(tn>=0)
    {
        Serial.print("KEY");
        Serial.print(tn);
        Serial.println(" touched");
    }
    
    delay(10);
}


Xadow – NFC




http://www.seeedstudio.com/wiki/Xadow_-_NFC

NFC . I2C, SPI, UART. 13.56 . . ISO14443 Type A and Type B. P2P . .

NFC , .



NDEF, PN532, PN532_HSU, PN532_I2C, PN532_SPI Seeed.

, NDEF->readTag

, . :
Tag is not NDEF formatted.
NFC Tag - Mifare Classic
UID 6E A5 0B 01

- , . NDEF->FormatTag:

, NDEF->WriteTag.

:
NFC Tag - Mifare Classic
UID 5E B1 FB 01

NDEF Message 1 record, 28 bytes
  NDEF Record
    TNF 0x1 Well Known
    Type Length 0x1 1
    Payload Length 0x18 24
    Type 55  U
    Payload 00 49 6E 74 65 6C 20 45 64 69 73 6F 6E 20 77 69 74 68 20 58 61 64 6F 77  .Intel Edison with Xadow
    Record is 28 bytes


Xadow — 3Axis Accelerometer




. . ±16 g. I2C 0x53. ADXL345. DigitalAccelerometer_ADXL345 .
±2g, ±4g, ±8g, ±16g. .
pdf1.alldatasheet.com/datasheet-pdf/view/254714/AD/ADXL345.html

16- . . int, , , :

void correct(int &a)
{
 if( a > 32767 )
     a = -(65536 - a);  
}

±2g, 256. , . Linux I2C. , , .

Xadow — Barometer BMP 180




. 300-1100 ( -500..+9000 ). I2C 0x77.
, . , I2C , .

Xadow – Breakout




. 3.3V, SCL, SDA, TX0, GND, SCK, MOS1, MOS0, A5. , seeed. Serial, I2C. .

Digital RGB LED Flexi-Strip




5 . RGB WS2812B. .
, , . Xadow-Breakout.





, .

:

#include <Wire.h>
#include "Seeed_ws2812.h"

#define SIG_PIN 12
#define LEN_NUM 5

WS2812 strip = WS2812(LEN_NUM, SIG_PIN);

void setup() {
  strip.begin();
  //Serial.begin(115200);   
}

int pos = 0;

void loop() {  
  strip.WS2812SetRGB(pos,255,0,0);
  strip.WS2812Send();
  delay(100);
  
  strip.WS2812SetRGB(pos,0,0,0);
  strip.WS2812Send();
  delay(100);

  pos = (pos+1)%LEN_NUM;
}



- . . . . , , 45 . , , . , . , , , , . , , .



:
  • ,
  • OLED ,
  • ,
  • ,
  • ,
  • .

. Breakout, . , . . . . , . .
, .



Linux .
PWR 9 . 3 .

, A B. .



. . You Win! , You Lose!



, .

#include <Wire.h>
#include <Seeed_ws2812.h>
#include <SeeedOLED.h>
#include <Seeed_QTouch.h>
#include <ADXL345.h>

//  
const int stateMenu = 1;
const int stateCount = 3;
const int stateHelp = 4;

// 
const int keyBack = 0;
const int keyA = 1;
const int keyB = 2;

// LED 
const int ledSigPin =  12;
const int numLed = 5;

// 
const int answerLeft = 1;
const int answerRight = 2;
const int answerUp = 3;
const int answerDown = 4;

const int colorGreen = 1;
const int colorRed = 2;

const int numLevels = 6;
const int answerID = 5;

const int angleScale = 100;
const int angleReact = 100;//   * angleScale

int numWins;//  
int numLosts;//  
int gameState;//  

const int numSets = 5;//    

//  
int levels[numLevels][numLed+1] = {  {colorGreen,0,0,0,0,answerLeft},
                             {colorRed,0,0,0,0,answerRight},
                             {0,0,0,0,colorGreen,answerRight},
                             {0,0,0,0,colorRed,answerLeft},
                             {0,0,colorGreen,0,0,answerUp},
                             {0,0,colorRed,0,0,answerRight}};
//  
int rightAnswer;

WS2812 strip = WS2812(numLed, ledSigPin);
ADXL345 adxl; 

//   
int gameLevel;

//  
void initAccel()
{
  adxl.powerOn();

  //set activity/ inactivity thresholds (0-255)
  adxl.setActivityThreshold(75); //62.5mg per increment
  adxl.setInactivityThreshold(75); //62.5mg per increment
  adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?
 
  //look of activity movement on this axes - 1 == on; 0 == off 
  adxl.setActivityX(1);
  adxl.setActivityY(1);
  adxl.setActivityZ(1);
 
  //look of inactivity movement on this axes - 1 == on; 0 == off
  adxl.setInactivityX(1);
  adxl.setInactivityY(1);
  adxl.setInactivityZ(1);
 
  //look of tap movement on this axes - 1 == on; 0 == off
  adxl.setTapDetectionOnX(0);
  adxl.setTapDetectionOnY(0);
  adxl.setTapDetectionOnZ(1);
 
  //set values for what is a tap, and what is a double tap (0-255)
  adxl.setTapThreshold(50); //62.5mg per increment
  adxl.setTapDuration(15); //625us per increment
  adxl.setDoubleTapLatency(80); //1.25ms per increment
  adxl.setDoubleTapWindow(200); //1.25ms per increment
 
  //set values for what is considered freefall (0-255)
  adxl.setFreeFallThreshold(7); //(5 - 9) recommended - 62.5mg per increment
  adxl.setFreeFallDuration(45); //(20 - 70) recommended - 5ms per increment
 
  //setting all interrupts to take place on int pin 1
  //I had issues with int pin 2, was unable to reset it
  adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT,   ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT,   ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT,    ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT,     ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT,   ADXL345_INT1_PIN );
 
  //register interrupt actions - 1 == on; 0 == off  
  adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1);
  adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1);
  adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT,  1);
  adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT,   1);
  adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1);
}

void initGame()
{
  SeeedOled.clearDisplay();
  SeeedOled.setNormalDisplay();
  SeeedOled.setPageMode(); 

  switchToMenu();
}

void setup()
{
    strip.begin();
    SeeedOled.init();
    initAccel();
    initGame();
}

void cleanLED()
{
  for( int led = 0; led < numLed; led++ )
      strip.WS2812SetRGB(led,0,0,0); 
}

void updateLED()
{
  strip.WS2812Send();
}

void drawMenu()
{
  SeeedOled.clearDisplay();
  SeeedOled.setTextXY(0,2);
  SeeedOled.putString("Edison Game");

  SeeedOled.setTextXY(2,1);
  SeeedOled.putString("A - Start");

  SeeedOled.setTextXY(4,1);
  SeeedOled.putString("B - Help"); 
}

void drawHelp()
{
  SeeedOled.clearDisplay();
  
  char *messages[] = {    "Center green -",
    "tilt forward." ,
    "Center red -" ,
    "tilt backward.", 
    "Green edge -" ,
    "tilt same side." ,
    "Red edge - tilt",
    "other side."
 };

   for( int k = 0; k < 8; k++ )
   {
      SeeedOled.setTextXY(k,0);
      SeeedOled.putString(messages[k]);
   }
}

void makeNewLevel()
{
    gameLevel = rand() % numLevels;
    rightAnswer = levels[gameLevel][answerID];
}

void showGameStart()
{
  SeeedOled.clearDisplay();
  SeeedOled.setTextXY(0,0);
  SeeedOled.putString("Press Start");
}

int getKeys()
{
    int tn = QTouch.touchNum();
    return tn;   
}

int haveTime = 20;

void showGameLevel()
{
  for( int k = 0; k < numLed; k++ )
  {
     int color = levels[gameLevel][k];
     switch(color)
     {
         case colorRed  : strip.WS2812SetRGB(k,255,0,0); break;
         case colorGreen: strip.WS2812SetRGB(k,0,255,0); break;
         default        : strip.WS2812SetRGB(k,0,0,0);
     }
  }

  updateLED();
}

void switchToSets()
{
  numWins = 0;
  numLosts = 0;
  switchToPlay();
}

//------------------------------------

void switchToPlay()
{
  cleanLED();
  updateLED();

  SeeedOled.clearDisplay();
  SeeedOled.setTextXY(3,3);
  SeeedOled.putString("Get ready!");

  int waitTime = 2000 + (rand()%4)*500;

  delay(waitTime);

  makeNewLevel();
  
  SeeedOled.setTextXY(3,3);
  SeeedOled.putString("          ");

  haveTime = 100;
  gameState = stateCount;
}

void doPlay()
{
  if( haveTime >= 0 )
  {
    SeeedOled.setTextXY(3,1);
    char str[100];
    sprintf(str,"-- TILT NOW --");
    SeeedOled.putString(str);

    SeeedOled.setTextXY(5,6);
    sprintf(str,"%d  ",haveTime);
    SeeedOled.putString(str);

    showGameLevel();
    
    int answerID = getAnswerID();

    haveTime--;
    
    if( answerID !=0 || haveTime < 0)
    {
      char *message;
      if( answerID != rightAnswer || haveTime < 0)
      {
        numLosts++;
        message = "You lose!";
      }
      else
      {
        numWins++;
        message = "You win!";
      }

      cleanLED();
      updateLED();

      SeeedOled.clearDisplay();
      SeeedOled.setTextXY(3,4);
      SeeedOled.putString(message);

      delay(1000);

      if( numWins + numLosts == numSets )
      {
        switchToMenu();
      }
      else
      {
        switchToPlay();
      }
    }
  }
}

//-----------------------

void switchToHelp()
{
    drawHelp();
    gameState = stateHelp;

    cleanLED();
    updateLED();
}

void doHelp()
{
  cleanLED();
  updateLED();
  
  int key = getKeys();
  
  if( key == keyBack )
      switchToMenu();  
}

//-----------------------
void switchToMenu()
{
  drawMenu();
  gameState = stateMenu;

  cleanLED();
  updateLED();
}

void doMenu()
{
  int key = getKeys();
  
  if( key == keyA )
      switchToSets();  

    if( key == keyB )
      switchToHelp();  
}
//-----------------------

void correct(int &a)
{
 if( a > 32767 )
     a = -(65536 - a);  
}

int  getAnswerID()
{
  int x,y,z;  
  adxl.readXYZ(&x, &y, &z);

  correct(x);
  correct(y);
  correct(z);

  int v1 = angleReact;
  if( z != 0 )
      v1 = y*angleScale/z;

  if( v1 > angleReact )
    return answerRight;

  if( v1 < -angleReact )
    return answerLeft;

  int v2 = angleReact;

  if( z != 0 )
      v2 = x*angleScale/z;

  if( v2 > angleReact )
    return answerUp;

  if( v2 < -angleReact )
    return answerDown;

    return 0;
}

void gameStep()
{
  switch(gameState)
  {
    case stateCount: doPlay();break;
    case stateMenu:  doMenu();break;
    case stateHelp:  doHelp();break;
  }
}

void loop()
{
    gameStep();
    delay(10);
}

Source: https://habr.com/ru/post/de386271/


All Articles