Author Topic: Data sheet for oak  (Read 7443 times)

Blitzfx

  • Newbie
  • *
  • Posts: 31
Data sheet for oak
« on: March 04, 2016, 10:36:22 pm »
Is there a datasheet somewhere for this?

I'm trying to connect a switch to pin 5 from a joystick with 5V supply and setting pinMode(5, INPUT);

Not sure if it's supposed to take 5V, in which case I've probably fried it then lol

It doesn't seem to work when I press the button and check

int buttonState = digitalRead(5);

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: Data sheet for oak
« Reply #1 on: March 04, 2016, 11:33:04 pm »
The Oak is 3.3V device, it is not 5V tolerant. There is no data sheet, the Wiki will get more of this info in the near future though and has a pin diagram that is correct except for the SPI pins (the labels on the Oak are correct for those): digistump.com/wiki/oak

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: Data sheet for oak
« Reply #2 on: March 04, 2016, 11:42:19 pm »
Erik, so this begs the question on the level shifter as to how to use and not use I/O pins? I've read that the ESP8266 has voltage protection on the GPIO pins but limits max drive current to 12ma. Would love to see some info on how to use and not use the level shifter as not all pins are bidirectional and that many are A=B in the input direction according to how the 74HCT245 is configured. I know you are busy with more pressing matters so adding it to a todo wish list is fine for now.

Blitzfx

  • Newbie
  • *
  • Posts: 31
Re: Data sheet for oak
« Reply #3 on: March 05, 2016, 12:49:38 am »
luckily for me, I checked the joystick and it only uses the 5V across the pot, so the oak reads the voltage levels on the analogue input, 0-1024. If I hook up the joystick to 3.3V, it'll never reach 1024.

The switch that's connected is Normally Open and when pressed, pulls to ground. I guess I should have checked this before.

Anyway, I connect it all up and the analogue read works fine (little bit annoyed there's only one analogue pin). It's connected to VIN (5V) and the GND right next to it.
The button wont work however.

I've found out now that I have to keep calling pinMode(5, INPUT_PULLUP); all the time, ie. in void loop() otherwise it doesn't seem to pull itself up after the switch is depressed.

Is this normal? With the Arduino Uno, you only need to call this once in void setup()
« Last Edit: March 05, 2016, 01:01:01 am by Blitzfx »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Data sheet for oak
« Reply #4 on: March 05, 2016, 03:23:55 am »
Hey Blitzfx

I'll give that a try in the morning and see if I get the same behaviour - hopefully I do! Otherwise it's a symptom of a wilting Oak!!! :D

Best 'datasheet' I know of at the moment is the attached pic I stole from the wiki at at some point. That plus the mantra of 'Oak/ESP8266 is 3v3 only - must not connect to anything but 3v3 parts or will release the magic blue smoke!'  ;)

Edit: And also the addendum from that wiki page re: errors in the image

PWM: Pins 0-9 are PWM. (Pin 10 was incorrectly listed as PWM on original diagram)
SPI: Pins 7, 8 and 9 are now MOSI, MISO and SCK No labeled function for Pin 6.


Pete
« Last Edit: March 05, 2016, 03:31:48 am by pfeerick »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Data sheet for oak
« Reply #5 on: March 05, 2016, 09:12:59 pm »
Blitzfx,

For the button, I've used the below code, and don't have any issues. The LED comes on when I press the button, and goes out when I release it. The publish messages are also pushed to Particle, so you can see that happening in the logs as well. Had the button connected to GND and P5.

Have you got some other code I can try? Maybe it's the combination of the AnalogRead?

Pete

Code: [Select]
boolean btnPressed = false; //button state, and acts as a flag to stop multiple publish messages

void setup()
{
  pinMode(1, OUTPUT);       //onboard LED
  pinMode(5, INPUT_PULLUP); //button

  digitalWrite(1, LOW);     //set LED to known state (OFF)
}

void loop()
{

  if (digitalRead(5) == LOW) //button connected to GND
  {
    digitalWrite(1, HIGH);   //LED on (button pressed)
   
    if (btnPressed == false)
    {
      Particle.publish("Stop it... that tickles!!!");
    }
   
    btnPressed = true;
  }
  else
  {
    digitalWrite(1, LOW);    //LED off (button released)

    if (btnPressed == true)
    {
      Particle.publish("Thank you... that's better!");
    }
   
    btnPressed = false;
  }
}

Blitzfx

  • Newbie
  • *
  • Posts: 31
Re: Data sheet for oak
« Reply #6 on: March 06, 2016, 01:42:37 am »
The code is for the TFT shield.

I'm just messing around, enabling the user to draw on the screen with rainbow colors



Code: [Select]
#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include <SPI.h>
// For the Adafruit shield, these are the default.
#define TFT_DC 1
#define TFT_CS 6

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define SERIAL_OUT Serial

int previous = 0;

int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor
String stringOne;

int digIn = 5;

int buttonState = 1; 
 
int xy=0;

int radius;
int h = tft.height();
int w = tft.width();
int h1 = h/2;
int w1 = w/2;
uint16_t colorHex = 0;

uint16_t value1 = 0;

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(ILI9341_BLACK);
  tft.fillScreen(ILI9341_RED);
  tft.fillScreen(ILI9341_GREEN);
  tft.fillScreen(ILI9341_BLUE);
  tft.fillScreen(ILI9341_BLACK);
  return micros() - start;
}

unsigned long testText() {
  tft.fillScreen(ILI9341_BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_WHITE);  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
  tft.println(1234.56);
  tft.setTextColor(ILI9341_RED);    tft.setTextSize(3);
  tft.println(0xDEADBEEF, HEX);
  tft.println();
  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(5);
  tft.println("Groop");
  tft.setTextSize(2);
  tft.println("I implore thee,");
  tft.setTextSize(1);
  tft.println("my foonting turlingdromes.");
  tft.println("And hooptiously drangle me");
  tft.println("with crinkly bindlewurdles,");
  tft.println("Or I will rend thee");
  tft.println("in the gobberwarts");
  tft.println("with my blurglecruncheon,");
  tft.println("see if I don't!");
  return micros() - start;
}

unsigned long testLines(uint16_t color) {
  unsigned long start, t;
  int           x1, y1, x2, y2,
                w = tft.width(),
                h = tft.height();

  tft.fillScreen(ILI9341_BLACK);
  delay(0);

  x1 = y1 = 0;
  y2    = h - 1;
  start = micros();
  for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  t     = micros() - start; // fillScreen doesn't count against timing

  tft.fillScreen(ILI9341_BLACK);
  delay(0);

  x1    = w - 1;
  y1    = 0;
  y2    = h - 1;
  start = micros();
  for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  tft.fillScreen(ILI9341_BLACK);
  delay(0);

  x1    = 0;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  tft.fillScreen(ILI9341_BLACK);
  delay(0);

  x1    = w - 1;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);

  return micros() - start;
}

unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  unsigned long start;
  int           x, y, w = tft.width(), h = tft.height();

  tft.fillScreen(ILI9341_BLACK);
  start = micros();
  for (y = 0; y < h; y += 5) tft.drawFastHLine(0, y, w, color1);
  for (x = 0; x < w; x += 5) tft.drawFastVLine(x, 0, h, color2);

  return micros() - start;
}

unsigned long testRects(uint16_t color) {
  unsigned long start;
  int           n, i, i2,
                cx = tft.width()  / 2,
                cy = tft.height() / 2;

  tft.fillScreen(ILI9341_BLACK);
  n     = min(tft.width(), tft.height());
  start = micros();
  for (i = 2; i < n; i += 6) {
    i2 = i / 2;
    tft.drawRect(cx - i2, cy - i2, i, i, color);
  }

  return micros() - start;
}

unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  unsigned long start, t = 0;
  int           n, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(ILI9341_BLACK);
  n = min(tft.width(), tft.height());
  for (i = n; i > 0; i -= 6) {
    delay(0);
    i2    = i / 2;
    start = micros();
    tft.fillRect(cx - i2, cy - i2, i, i, color1);
    t    += micros() - start;
    // Outlines are not included in timing results
    tft.drawRect(cx - i2, cy - i2, i, i, color2);
  }

  return t;
}

unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;

  tft.fillScreen(ILI9341_BLACK);
  start = micros();
  for (x = radius; x < w; x += r2) {
    for (y = radius; y < h; y += r2) {
      tft.fillCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int           x, y, r2 = radius * 2,
                      w = tft.width()  + radius,
                      h = tft.height() + radius;

  // Screen is not cleared for this one -- this is
  // intentional and does not affect the reported time.
  start = micros();
  for (x = 0; x < w; x += r2) {
    for (y = 0; y < h; y += r2) {
      tft.drawCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testTriangles() {
  unsigned long start;
  int           n, i, cx = tft.width()  / 2 - 1,
                      cy = tft.height() / 2 - 1;

  tft.fillScreen(ILI9341_BLACK);
  n     = min(cx, cy);
  start = micros();
  for (i = 0; i < n; i += 5) {
    tft.drawTriangle(
      cx    , cy - i, // peak
      cx - i, cy + i, // bottom left
      cx + i, cy + i, // bottom right
      tft.color565(0, 0, i));
  }

  return micros() - start;
}

unsigned long testFilledTriangles() {
  unsigned long start, t = 0;
  int           i, cx = tft.width()  / 2 - 1,
                   cy = tft.height() / 2 - 1;

  tft.fillScreen(ILI9341_BLACK);
  start = micros();
  for (i = min(cx, cy); i > 10; i -= 5) {
    start = micros();
    tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
                     tft.color565(0, i, i));
    t += micros() - start;
    tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
                     tft.color565(i, i, 0));
  }

  return t;
}

unsigned long testRoundRects() {
  unsigned long start;
  int           w, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(ILI9341_BLACK);
  w     = min(tft.width(), tft.height());
  start = micros();
  for (i = 0; i < w; i += 6) {
    i2 = i / 2;
    tft.drawRoundRect(cx - i2, cy - i2, i, i, i / 8, tft.color565(i, 0, 0));
    delay(0);
  }

  return micros() - start;
}

unsigned long testFilledRoundRects() {
  unsigned long start;
  int           i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(ILI9341_BLACK);
  start = micros();
  for (i = min(tft.width(), tft.height()); i > 20; i -= 6) {
    i2 = i / 2;
    tft.fillRoundRect(cx - i2, cy - i2, i, i, i / 8, tft.color565(0, i, 0));
    delay(0);
  }

  return micros() - start;
}


void setup() {
  pinMode(digIn, INPUT_PULLUP);
  pinMode(digIn, INPUT);
 // digitalWrite(digIn, HIGH);
 
  SERIAL_OUT.begin(115200);
  SERIAL_OUT.println("ILI9341 Test!");

  tft.begin();

  // read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  SERIAL_OUT.print("Display Power Mode: 0x"); SERIAL_OUT.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDMADCTL);
  SERIAL_OUT.print("MADCTL Mode: 0x"); SERIAL_OUT.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDPIXFMT);
  SERIAL_OUT.print("Pixel Format: 0x"); SERIAL_OUT.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDIMGFMT);
  SERIAL_OUT.print("Image Format: 0x"); SERIAL_OUT.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDSELFDIAG);
  SERIAL_OUT.print("Self Diagnostic: 0x"); SERIAL_OUT.println(x, HEX);

  SERIAL_OUT.println(F("Benchmark                Time (microseconds)"));

  SERIAL_OUT.print(F("Screen fill              "));
  SERIAL_OUT.println(testFillScreen());
  delay(500);

  SERIAL_OUT.print(F("Text                     "));
  SERIAL_OUT.println(testText());
  delay(3000);

  SERIAL_OUT.print(F("Lines                    "));
  SERIAL_OUT.println(testLines(ILI9341_CYAN));
  delay(500);

  SERIAL_OUT.print(F("Horiz/Vert Lines         "));
  SERIAL_OUT.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
  delay(500);

  SERIAL_OUT.print(F("Rectangles (outline)     "));
  SERIAL_OUT.println(testRects(ILI9341_GREEN));
  delay(500);

  SERIAL_OUT.print(F("Rectangles (filled)      "));
  SERIAL_OUT.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
  delay(500);

  SERIAL_OUT.print(F("Circles (filled)         "));
  SERIAL_OUT.println(testFilledCircles(10, ILI9341_MAGENTA));

  SERIAL_OUT.print(F("Circles (outline)        "));
  SERIAL_OUT.println(testCircles(10, ILI9341_WHITE));
  delay(500);

  SERIAL_OUT.print(F("Triangles (outline)      "));
  SERIAL_OUT.println(testTriangles());
  delay(500);

  SERIAL_OUT.print(F("Triangles (filled)       "));
  SERIAL_OUT.println(testFilledTriangles());
  delay(500);

  SERIAL_OUT.print(F("Rounded rects (outline)  "));
  SERIAL_OUT.println(testRoundRects());
  delay(500);

  SERIAL_OUT.print(F("Rounded rects (filled)   "));
  SERIAL_OUT.println(testFilledRoundRects());
  delay(500);

  SERIAL_OUT.println(F("Done!"));
  tft.fillScreen(ILI9341_BLACK);
}


void loop(void) {
  /*
  for(uint8_t rotation=0; rotation<4; rotation++) {
    tft.setRotation(rotation);
    testText();
    delay(1000);
  }
  */
  //pinMode(digIn, INPUT_PULLUP);
 
  buttonState = digitalRead(digIn);

  if (buttonState == 0)
  {
    if (previous == 1)
    {
      if (xy == 0)
      {
        xy = 1;
      }
      else
      {
        xy = 0;
      }
      previous = 0;
    }
  }
  else
  {
    previous =1;
  }
 
   
  radius = 10;
  sensorValue = analogRead(sensorPin);

if (xy == 0)
{
  if (sensorValue < 750)
  {
    h1 = h1-2;
    if (sensorValue <100)
    {
      h1 = h1-3;
    }
  }
  if (sensorValue > 770)
  {
    h1 = h1+2;
    if(sensorValue >900)
    {
      h1 = h1+3;
    }
  }
}
if (xy == 1)
{
  if (sensorValue < 750)
  {
    w1 = w1-2;
    if(sensorValue <100)
    {
      w1 = w1 -3;
    }
  }
  if (sensorValue > 770)
  {
    w1 = w1+2;
    if (sensorValue >900)
    {
      w1 = w1 +3;
    }
  }
}

colorHex = colorHex + 1;
//if (colorHex > 65536)
if (colorHex > 131072)
{
  colorHex = 0;
}

//  tft.fillCircle(h1, w1, radius, ILI9341_WHITE);
tft.fillCircle(h1, w1, radius, colorHex);
  tft.fillCircle(h1, w1, 2, ILI9341_BLACK);
 
  value1 = sensorValue * 64;
  //stringOne =  String(value1, HEX);
  stringOne =  String(colorHex, HEX);
  // prints "2d", which is the hexadecimal version of decimal 45:
  //Serial.println(stringOne);


  //tft.fillScreen(ILI9341_BLACK);
  tft.fillRect(0,0,w,45,ILI9341_BLACK);
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_WHITE);
  //tft.setTextColor(value1);
//  tft.fillRect(tft.width()/2, tft.height()/2, tft.width(), tft.height(), value1);


  tft.setTextSize(3);
  //tft.println(sensorValue);
  //tft.println(value1);
  //tft.println(stringOne);
  if (xy ==1)
  {
    tft.print("Y vertical"); 
  }
  else
  {
    tft.print("X horizon");
  }
  tft.print(" ");
  tft.println(buttonState);
 
  tft.print(stringOne);
  tft.print(" | ");
  tft.print(colorHex);
 
  delay(50);
}

Well whatever's going on in the example code, I found if you also put the pull-up call at the end of the setup function, it'll work fine as well.

Probably not relevant but the thing works by moving the joy stick left and right, and that moves the cursor left and right. Since there's no Y-axis (second analogue input pin), I can just press the button and switch x-axis => y-axis movement.
« Last Edit: March 06, 2016, 01:49:32 am by Blitzfx »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Data sheet for oak
« Reply #7 on: March 06, 2016, 02:07:34 am »
Nice! I won't try it yet as I haven't bothered assembling the TFT shield yet, but my first thoughts, which seem to be reinforced by you comment about adding pulllups to the end of the example code setup, are that in the setup function, the second pinMode command shouldn't be there - as it effectively cancels the first one, as according to the Arduino reference docs "the INPUT mode explicitly disables the internal pullups."!!!! So i'd just comment out the comment out pinMode INPUT line, and it should be fine. That section of code looks like old legacy pre -Arduino 1.0 code , where you had to do a DigitalWrite(pin,HIGH) and then pinMode(pin, INPUT) to enable pullups.

Pete

Code: [Select]
void setup() {
  pinMode(digIn, INPUT_PULLUP);
  pinMode(digIn, INPUT); //comment this line out, as it disables pullups
 // digitalWrite(digIn, HIGH);

Blitzfx

  • Newbie
  • *
  • Posts: 31
Re: Data sheet for oak
« Reply #8 on: March 06, 2016, 04:13:01 am »
Oh, you're 100% right lol. Well that fixed it.

Also if you ever find out how the library translates hex into RGB [0-255]/[0-255]/[0-255], let me know because i'm just passing decimal unsigned int into the function and just guessing lol
Looks like it's 8-bit resolution however.

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Data sheet for oak
« Reply #9 on: March 06, 2016, 05:24:13 pm »
No problem ;)

Well, I blame you for me not studying at the moment, and having an Oak running the LCD demo (yes, have it wired up now!).  :o ;D

For the colour, you can use any of the pre-defined colours below (ILI9341_BLACK, ILI9341_PURPLE, etc). To set your own colour, you can use the colour565 function to generate the "16-bit packed colour" code.

Like so:

Code: [Select]
uint16_t colourVar = 0;
colourVar = tft.color565(255,255,255); //R, G, B (0 - 255 for each colour channel)
tft.setTextColor(colourVar);  tft.setTextSize(1);
tft.println("Hello World!");

Code: [Select]
// Color definitions
#define ILI9341_BLACK       0x0000      /*   0,   0,   0 */
#define ILI9341_NAVY        0x000F      /*   0,   0, 128 */
#define ILI9341_DARKGREEN   0x03E0      /*   0, 128,   0 */
#define ILI9341_DARKCYAN    0x03EF      /*   0, 128, 128 */
#define ILI9341_MAROON      0x7800      /* 128,   0,   0 */
#define ILI9341_PURPLE      0x780F      /* 128,   0, 128 */
#define ILI9341_OLIVE       0x7BE0      /* 128, 128,   0 */
#define ILI9341_LIGHTGREY   0xC618      /* 192, 192, 192 */
#define ILI9341_DARKGREY    0x7BEF      /* 128, 128, 128 */
#define ILI9341_BLUE        0x001F      /*   0,   0, 255 */
#define ILI9341_GREEN       0x07E0      /*   0, 255,   0 */
#define ILI9341_LIGHTBLUE   0x061F      /*   0, 192, 255 */
#define ILI9341_CYAN        0x07FF      /*   0, 255, 255 */
#define ILI9341_RED         0xF800      /* 255,   0,   0 */
#define ILI9341_MAGENTA     0xF81F      /* 255,   0, 255 */
#define ILI9341_YELLOW      0xFFE0      /* 255, 255,   0 */
#define ILI9341_WHITE       0xFFFF      /* 255, 255, 255 */
#define ILI9341_ORANGE      0xFD20      /* 255, 165,   0 */
#define ILI9341_GREENYELLOW 0xAFE5      /* 173, 255,  47 */
#define ILI9341_PINK        0xF81F
« Last Edit: March 06, 2016, 05:26:11 pm by pfeerick »

Blitzfx

  • Newbie
  • *
  • Posts: 31
Re: Data sheet for oak
« Reply #10 on: March 06, 2016, 10:57:22 pm »
Code: [Select]
// Pass 8-bit (each) R,G,B, get back 16-bit packed color
uint16_t Adafruit_ILI9341::color565(uint8_t r, uint8_t g, uint8_t b) {
  return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}

lol i didnt realise this existed. Forgotten how the logical bitshifting and comparisons do though. Doesn't really matter now anymore if there's a function for it

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Data sheet for oak
« Reply #11 on: March 07, 2016, 12:44:25 am »
Yup, that's the one! I just went... if they're defining it as a four digit hex number, where is it being used or decoded... and spotted that function hiding there... and yeah... enough said on the logical bitshifting & or'ing... I'll stick with the function! lol