Sunday, June 21, 2020

Install Arduino IDE/Seeed SAMD Boards on Raspberry Pi OS, to program Wio Terminal on RPi

Steps to install Arduino IDE on Raspberry Pi 4/Raspberry Pi OS (32-bit), then add Seeed SAMD Boards; to program Seeed Wio Terminal on Raspberry Pi.



Install Arduino IDE (Linux ARM 32 bits) on Raspberry Pi/Raspberry Pi OS


Download Arduino IDE for Linux ARM 32 bits
https://www.arduino.cc/en/Main/Software

Basically follow the official guide to Install the Arduino Software (IDE) on Linux, but install by running ./install.sh with sudo.

$ sudo ./install.sh

After installed, I tested to program Wio Terminal without problem. No extra steps is needed to set serial port permission.


Install Seeed SAMD Boards to Arduino IDE, for Wio Terminal development


Open your Arduino IDE, click on File > Preferences,
and copy below url to Additional Boards Manager URLs:
https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json

Tools > Board > Board Manager,
Search Wio Terminal, install Seeed SAMD Boards.

reference: Get Started with Wio Terminal, more informative details and examples.

My first exercise for Wio terminal, simple detect button press and draw something on display:
#include <SPI.h>
#include <TFT_eSPI.h>

TFT_eSPI tft = TFT_eSPI();

int ptX = 50;
int ptY = 50;

/*  Some basic pre-defined example colours(16-bit) including in the LCD library:
#define TFT_BLACK       0x0000      //   0,   0,   0
#define TFT_NAVY        0x000F      //   0,   0, 128
#define TFT_DARKGREEN   0x03E0      //   0, 128,   0
#define TFT_DARKCYAN    0x03EF      //   0, 128, 128
#define TFT_MAROON      0x7800      // 128,   0,   0
#define TFT_PURPLE      0x780F      // 128,   0, 128
#define TFT_OLIVE       0x7BE0      // 128, 128,   0
#define TFT_LIGHTGREY   0xC618      // 192, 192, 192
#define TFT_DARKGREY    0x7BEF      // 128, 128, 128
#define TFT_BLUE        0x001F      //   0,   0, 255
#define TFT_GREEN       0x07E0      //   0, 255,   0
#define TFT_CYAN        0x07FF      //   0, 255, 255
#define TFT_RED         0xF800      // 255,   0,   0
#define TFT_MAGENTA     0xF81F      /* 255,   0, 255
#define TFT_YELLOW      0xFFE0      /* 255, 255,   0
#define TFT_WHITE       0xFFFF      /* 255, 255, 255
#define TFT_ORANGE      0xFDA0      /* 255, 180,   0
#define TFT_GREENYELLOW 0xB7E0      /* 180, 255,   0
ref: https://wiki.seeedstudio.com/Wio-Terminal-LCD-Basic/
*/

/*  basic graphical functions of the TFT LCD library on Wio Terminal.
    ref: https://wiki.seeedstudio.com/Wio-Terminal-LCD-Graphics/
drawPixel(int32_t x, int32_t y, uint32_t color);
drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color);
drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color); //Horizontal line
drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color); //Verical line
drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color);
fillCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color);
drawEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color);
fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color);
drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color);
fillTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color);
drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, uint32_t color);
fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, uint32_t color);
drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size)
drawString(const String& string, int32_t pptX, int32_t pptY);
fillScreen(uint32_t color);
*/

void updateLoc(String s){
  tft.drawPixel(ptX, ptY, TFT_WHITE);
  const String strLoc = s + " "+ (String)ptX + ":" + (String)ptY + "     ";
  Serial.println(strLoc);
  tft.drawString(strLoc, 100, 100);
}

void setup() {
  Serial.begin(115200);

  pinMode(WIO_KEY_A, INPUT_PULLUP);
  pinMode(WIO_KEY_B, INPUT_PULLUP);
  pinMode(WIO_KEY_C, INPUT_PULLUP);
  pinMode(WIO_5S_UP, INPUT_PULLUP);
  pinMode(WIO_5S_DOWN, INPUT_PULLUP);
  pinMode(WIO_5S_LEFT, INPUT_PULLUP);
  pinMode(WIO_5S_RIGHT, INPUT_PULLUP);
  pinMode(WIO_5S_PRESS, INPUT_PULLUP);

  tft.init();
  tft.setRotation(2);
  tft.fillScreen(TFT_LIGHTGREY);
  tft.fillRect(1, 1, 238, 318, TFT_BLACK);
  tft.fillTriangle(1, 1, 1, 11, 11, 1, TFT_BLUE);
  tft.fillTriangle(238, 318, 238, 308, 228, 318, TFT_RED);
  updateLoc("x");

}

 
void loop() {
  // put your main code here, to run repeatedly:
   if (digitalRead(WIO_5S_UP) == LOW) {
    Serial.println("5 Way Up");
    ptX++;
    updateLoc("^");
   }
   else if (digitalRead(WIO_5S_DOWN) == LOW) {
    Serial.println("5 Way Down");
    ptX--;
    updateLoc("v");
   }
   else if (digitalRead(WIO_5S_LEFT) == LOW) {
    Serial.println("5 Way Left");
    ptY--;
    updateLoc("<");
   }
   else if (digitalRead(WIO_5S_RIGHT) == LOW) {
    Serial.println("5 Way Right");
    ptY++;
    updateLoc(">");
   }
   else if (digitalRead(WIO_5S_PRESS) == LOW) {
    Serial.println("5 Way Press");
    updateLoc("@");
    tft.fillCircle(ptX, ptY, 5, TFT_ORANGE);
   }

   if (digitalRead(WIO_KEY_A) == LOW) {
    Serial.println("A Key pressed");
    ptX+=10;
    updateLoc("A");
    tft.fillCircle(ptX, ptY, 10, TFT_RED);
   }
   else if (digitalRead(WIO_KEY_B) == LOW) {
    Serial.println("B Key pressed");
    updateLoc("B");
    tft.fillCircle(ptX, ptY, 10, TFT_GREEN);
   }
   else if (digitalRead(WIO_KEY_C) == LOW) {
    Serial.println("C Key pressed");
    ptX-=10;
    updateLoc("C");
    tft.fillCircle(ptX, ptY, 10, TFT_BLUE);
   }
   delay(200);
}



to do...

This wiki introduce how to update the latest firmware for the Wireless Core Realtek RTL8720 on Wio Terminal, as well as installing all the dependent libraries for Wio Terminal to enable wireless connectivity.


Related:

No comments: