SELF_HW: week 0

 "Software" - Saturday

- Continued on implementing EHCI. Coded a wrong implementation of the ASYNC list. Need to debug.


https://github.com/Speedstor/aldrinOS/commit/96b16cc6136d518586de2d3e7e4c0cb0106ea47e

TODO:: What I think went wrong / What could be some points that I did wrong


 "Hardware" - Sunday

Using MPU6050 gyroscope and 1602A LCD display, display the mpu6050 data using symbols. The code was trash because I had some trouble with reading the documentation: https://www.openhacks.com/uploadsproductos/eone-1602a1.pdf 


#include "I2Cdev.h"
#include "MPU6050.h"

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    #include "Wire.h"
#endif

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;
//MPU6050 accelgyro(0x69); // <-- use for AD0 high

int16_t ax, ay, az;
int16_t gx, gy, gz;


#define LED_PIN 13

#define D0 8
#define D1 9
#define D2 2
#define D3 3
#define D4 4
#define D5 5
#define D6 6
#define D7 7

#define RS 22
#define RW 24
#define EN  26


void setup() {
    // join I2C bus (I2Cdev library doesn't do this automatically)
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif

    Serial.begin(38400);

    // initialize device
    Serial.println("Initializing...");
    accelgyro.initialize();
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
    accelgyro.setXAccelOffset(0);
    accelgyro.setYAccelOffset(0);
    accelgyro.setZAccelOffset(0);
    accelgyro.setXGyroOffset(0);
    accelgyro.setYGyroOffset(0);
    accelgyro.setZGyroOffset(0);

    pinMode(D0, OUTPUT);
    pinMode(D1, OUTPUT);
    pinMode(D2, OUTPUT);
    pinMode(D3, OUTPUT);
    pinMode(D4, OUTPUT);
    pinMode(D5, OUTPUT);
    pinMode(D6, OUTPUT);
    pinMode(D7, OUTPUT);
    pinMode(RS, OUTPUT);
    pinMode(RW, OUTPUT);
    pinMode(EN, OUTPUT);

    delay(500);
    
    setDisplayMode();
    delay(50);
    setShiftMode();
    delay(50);
}


const char accel_symbol[3][3] = {{'<', '^', '>'}, {'<', '.', '>'}, {'<', 'v', '>'}};
//const char* accel_symbol[3][3] = {{"⇖", "⇑", "⇗"}, {"⇐", "•", "⇒"}, {"⇙", "⇓", "⇘"}};
const char* accel_symbol_spaced[3][3] = {{"⇖", " ⇑ ", "  ⇗"}, {"⇐  ", " • ", "  ⇒"}, {"⇙  ", " ⇓ ", "  ⇘"}};

int dataPins[8] = {D0, D1, D2, D3, D4, D5, D6, D7};

int x = 1;
int y = 1;
void loop() {
    // read raw accel/gyro measurements from device
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    ax += 5184;
    ay += 2800;
    az += 510;
    gx += 190;
    gy -= 200;
    gz -= 15;

    x = 1;
    y = 1;
    /*
    if (gz > 500)
      x = 0;
    else if (gz < -300)
      x = 2;
      
    if (gy > 250)
      y = 2;
    else if (gy < -250)
      y = 0;
      */

      
    if (ay > 2000)
      x = 0;
    else if (ay < -2000)
      x = 2;
      
    if (ax > 2050)
      y = 0;
    else if (ax < -2050)
      y = 2;

    //Serial.println(accel_symbol[y][x]);
    clearBuffer();
    delay(50);
    //clearDisplay();
    //delay(50);

    sendCharacter(accel_symbol[y][x]);
    //sendCharacter('a');
    delay(50);
    //while(true)
    delay(500);
}

void sendCharacter(char c) {
  digitalWrite(RW, LOW);
  digitalWrite(RS, HIGH);

  for(int i = 0; i < 8; i++){
      digitalWrite(dataPins[i], c & 0x01);
      c >>= 1;
  }
  
  digitalWrite(EN, LOW);
  delayMicroseconds(1);
  digitalWrite(EN, HIGH);
  delayMicroseconds(1);
  digitalWrite(EN, LOW);
  delayMicroseconds(1);
}

void clearBuffer() {
  digitalWrite(RW, LOW);
  digitalWrite(RS, LOW);
  
  digitalWrite(EN, LOW);

  digitalWrite(D0, LOW);
  digitalWrite(D1, LOW); 
  digitalWrite(D2, LOW); 
  digitalWrite(D3, LOW); 
  digitalWrite(D4, LOW);
  digitalWrite(D5, LOW);
  digitalWrite(D6, LOW);
  digitalWrite(D7, HIGH);
  
  
  digitalWrite(EN, LOW);
  delayMicroseconds(1);
  digitalWrite(EN, HIGH);
  delayMicroseconds(1);
  digitalWrite(EN, LOW);
  delayMicroseconds(1);
}


void setShiftMode() {
  digitalWrite(RW, LOW);
  digitalWrite(RS, LOW);
  
  digitalWrite(EN, LOW);

  digitalWrite(D0, LOW); // x
  digitalWrite(D1, LOW); // x
  digitalWrite(D2, HIGH); // Font size, HIGH: Right
  digitalWrite(D3, LOW); // cursor/dispaly, high: display
  digitalWrite(D4, HIGH); // signify sending shift flags
  digitalWrite(D5, LOW); 
  digitalWrite(D6, LOW);
  digitalWrite(D7, LOW);
  
  
  digitalWrite(EN, LOW);
  delayMicroseconds(1);
  digitalWrite(EN, HIGH);
  delayMicroseconds(1);
  digitalWrite(EN, LOW);
  delayMicroseconds(1);
}

void setDisplayMode() {
  digitalWrite(RW, LOW);
  digitalWrite(RS, LOW);
  
  digitalWrite(EN, LOW);

  digitalWrite(D0, LOW); //  cursor position on
  digitalWrite(D1, LOW); // cursor on
  digitalWrite(D2, HIGH); // entire display on
  digitalWrite(D3, HIGH);  // signify sending display flags
  digitalWrite(D4, LOW);
  digitalWrite(D5, LOW);
  digitalWrite(D6, LOW);
  digitalWrite(D7, LOW);
  
  
  digitalWrite(EN, LOW);
  delayMicroseconds(1);
  digitalWrite(EN, HIGH);
  delayMicroseconds(1);
  digitalWrite(EN, LOW);
  delayMicroseconds(1);
}

void clearDisplay() {
  digitalWrite(RW, LOW);
  digitalWrite(RS, LOW);
  
  digitalWrite(EN, LOW);
  
  digitalWrite(D0, HIGH);
  digitalWrite(D1, LOW);
  digitalWrite(D2, LOW);
  digitalWrite(D3, LOW);
  digitalWrite(D4, LOW);
  digitalWrite(D5, LOW);
  digitalWrite(D6, LOW);
  digitalWrite(D7, LOW);
  
  digitalWrite(EN, LOW);
  delayMicroseconds(1);
  digitalWrite(EN, HIGH);
  delayMicroseconds(1);
  digitalWrite(EN, LOW);
  delayMicroseconds(1);
}

Comments