BPI-Bit : MicroPython 개발하기 (PyCharm 사용)

OS/Banana Pi /BPI-Bit 2019.02.07 23:47 Posted by 파란크리스마스

출처

BPI-Bit : MicroPython 개발하기 (PyCharm 사용)

BPI-Bit는 3가지 개발 방법이 있는데, 1번째는 아두이노IDE로 개발, 2번째는 Webduino로 개발, 3번째로는 MicroPython으로 개발이 가능합니다. 

MicroPython의 개발은 펌웨어을 업로드 해야 가능하며, 최신버전의 펌웨어를 업로드 해야 MicroPython 함수를 지원하므로 항상 최신버전으로 펌웨어를 사용하시기 바랍니다.

참고로 MicroPython 펌웨어를 업로드 했을 경우 Webuino사용이 불가능 하므로 Webduino를 다시 사용하려면 Webduino 펌웨어를 업로드 하시면 됩니다.

COM 포트 확인

esptool 설치

C:\BPI-BIT>pip3 install esptool
Collecting esptool
  Downloading https://files.pythonhosted.org/packages/5c/85/5654e7b9019739d3d89af0adf528c9ae57a9a26682e3aa012e1e30f20674/esptool-2.6.tar.gz (80kB)
    100% |████████████████████████████████| 81kB 457kB/s
Collecting pyserial>=3.0 (from esptool)
  Using cached https://files.pythonhosted.org/packages/0d/e4/2a744dd9e3be04a0c0907414e2a01a7c88bb3915cbe3c8cc06e209f59c30/pyserial-3.4-py2.py3-none-any.whl
Collecting pyaes (from esptool)
  Downloading https://files.pythonhosted.org/packages/44/66/2c17bae31c906613795711fc78045c285048168919ace2220daa372c7d72/pyaes-1.6.1.tar.gz
Collecting ecdsa (from esptool)
  Downloading https://files.pythonhosted.org/packages/63/f4/73669d51825516ce8c43b816c0a6b64cd6eb71d08b99820c00792cb42222/ecdsa-0.13-py2.py3-none-any.whl (86kB)
    100% |████████████████████████████████| 92kB 920kB/s
Installing collected packages: pyserial, pyaes, ecdsa, esptool
  Running setup.py install for pyaes ... done
  Running setup.py install for esptool ... done
Successfully installed ecdsa-0.13 esptool-2.6 pyaes-1.6.1 pyserial-3.4
You are using pip version 18.1, however version 19.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

MicroPython 펌웨어 설치

출처

펌웨어 파일(firmware.bin) 다운로드

최신 펌웨어 파일(firmware.bin)을 다운로드 (https://github.com/BPI-STEAM/BPI-BIT-MicroPython/releases)

flash_id 명령어로 가능한 flash 크기와 장치 번호를 확인

D:\BPI-BIT>python.exe -m esptool --port COM27 flash_id
esptool.py v2.6
Serial port COM27
Connecting.......
Detecting chip type... ESP32
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: b4:e6:2d:96:f3:cd
Uploading stub...
Running stub...
Stub running...
Manufacturer: c8
Device: 4016
Detected flash size: 4MB
Hard resetting via RTS pin...

기존 펌웨어 삭제

C:\BPI-BIT>python.exe -m esptool --port COM27 --baud 115200 erase_flash
esptool.py v2.6
Serial port COM27
Connecting......
Detecting chip type... ESP32
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: b4:e6:2d:96:f3:cd
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 4.1s
Hard resetting via RTS pin...

다운받은 펌웨어 파일(firmware.bin)을 BPI-Bit에 업로드

C:\BPI-BIT>python.exe -m esptool --port COM27 --baud 115200 write_flash -z --flash_mode dio --flash_freq 40m 0x1000 firmware.bin
esptool.py v2.6
Serial port COM27
Connecting....
Detecting chip type... ESP32
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: b4:e6:2d:96:f3:cd
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 1294208 bytes to 811935...
Wrote 1294208 bytes (811935 compressed) at 0x00001000 in 74.1 seconds (effective 139.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

PyCharm에서 MicroPython 플러그인 설치

메뉴 [File] - [Settings] 선택

메뉴 [Plugins] 에서 오른쪽 상단의 톱니바퀴 아이콘을 선택하고, 메뉴 [Install Plugin from Disk] 선택

다운받은 플러그인 파일(intellij-micropython-1.1.0.zip)을 선택

버튼 [Restart IDE] 선택

버튼 [Restart] 선택하여 PyCharm 재실행

메뉴 [File] - [Settings] 선택 - 메뉴 [MicroPython] 선택해서 아래와 같이 설정, Device path:는 COM27 설정

[install requirements]선택하여, 플러그인 관련 파일 설치

프로젝트 생성

프로젝트 정보 작성

파이썬 소스 생성

소스 파일명 작성

HelloWorld.py 소스

from display import*
display=Display()
display.scroll("Hello, World!",Yellow)

실행

Run 콘솔창

실행결과

BPI-Bit : 광센서 사용하기

OS/Banana Pi /BPI-Bit 2019.02.06 15:27 Posted by 파란크리스마스

출처

BPI-Bit : 광센서 사용하기

BPI-Bit에는 두개의 버튼위에 각각 광센서가 모둘이 내장 되어 있습니다. 왼쪽 광센서 모듈은 GPIO 36 핀을 사용하고, 오른쪽 광센서 모듈은 GPIO 39 핀을 사용합니다.

GPIO control of BPI:bit

GPIO control of BPI:bit
Light Sensor(L)GPIO 36Analog Input
Light Sensor(R)GPIO 39Analog Input
Botton AGPIO 35Digital Input
Botton BGPIO 27Digital Input
Temperature SensorGPIO 34Analog Input
BuzzerGPIO 25PWM(Digital Output) / Analog Output
RGB_LEDGPIO 4Digital Output
MPU9250_SCLGPIO 22Digital Output
MPU9250_SDAGPIO 21Digital Output
MPU9250_INTGPIO 16Digital Input
R_LED(SPI_SCK)GPIO 18Digital Output

예제 소스

//ADC config
#define LUM0 36 //ADC1_CH0
#define LUM1 39 //ADC1_CH3

void setup() {
  Serial.begin(115200); //Serial Port Config 115200-8-N-1
}

void loop() {
  //LUM0--ADC1_CH0-Pin:IO36
  Serial.print("L_light:");
  Serial.print(analogRead(LUM0));
  Serial.println();
  //LUM1--ADC1_CH3-Pin:IO39
  Serial.print("R_light:");
  Serial.print(analogRead(LUM1));
  Serial.println();
  delay(500);
}

실행 결과

BPI-Bit : 온도 센서 사용하기

OS/Banana Pi /BPI-Bit 2019.02.06 01:18 Posted by 파란크리스마스

출처

BPI-Bit : 온도 센서 사용하기

BPI-Bit에는 온도 센서 모둘이 내장 되어 있습니다. 예제를 통해서 온도 값을 입력 받아보겠습니다.

GPIO control of BPI:bit

GPIO control of BPI:bit
Light Sensor(L)GPIO 36Analog Input
Light Sensor(R)GPIO 39Analog Input
Botton AGPIO 35Digital Input
Botton BGPIO 27Digital Input
Temperature SensorGPIO 34Analog Input
BuzzerGPIO 25PWM(Digital Output) / Analog Output
RGB_LEDGPIO 4Digital Output
MPU9250_SCLGPIO 22Digital Output
MPU9250_SDAGPIO 21Digital Output
MPU9250_INTGPIO 16Digital Input
R_LED(SPI_SCK)GPIO 18Digital Output

예제 소스

// GPIO 핀
#define Temp 34 //ADC2_CH7

// temperature config
const float voltagePower = 3.3;
const float Rs = 5.1; //Sampling Resistance is 5.1K ohm
const int B = 3950;
const double T = 273.15 + 25; //Normal Temperature Parameters
const double R1 = 10; //Normal Temperature Resistance (K ohm)
double Temp_Value = 0;

void setup() {
  Serial.begin(115200); //Serial Port Config 115200-8-N-1
  pinMode(TEMPERATURE_SENSOR, INPUT);//TEMPERATURE_SENSOR(IO34) Input Mode
}

void loop() {
  Temp_Value = analogRead(TEMPERATURE_SENSOR);//Read Analog Value       
  double voltageValue = (Temp_Value / 4095) * 3.3;//
  Serial.print("Current voltage value=");
  Serial.println(voltageValue);
  //Thermistor value
  double Rt = ((voltagePower - voltageValue) * Rs) / voltageValue;
  Serial.print("Current registor value=");
  Serial.println(Rt);
  
  //Temperature value
  Serial.print("Current temperature value=");
  Serial.println(((T * B) / (B + T * log(Rt / R1))) - 273.15);
  Serial.println();
  delay(500);
}

실행 결과

BPI-Bit : 부저 사용하기

OS/Banana Pi /BPI-Bit 2019.02.06 00:23 Posted by 파란크리스마스

출처

BPI-Bit : 부저 사용하기

BPI-Bit에는 사운드 출력을 위한 부저 모듈이 내장 되어 있습니다. 예제를 통해서 간단하게 부저로 사운드를 출력해보겠습니다.

GPIO control of BPI:bit

GPIO control of BPI:bit
Light Sensor(L)GPIO 36Analog Input
Light Sensor(R)GPIO 39Analog Input
Botton AGPIO 35Digital Input
Botton BGPIO 27Digital Input
Temperature SensorGPIO 34Analog Input
BuzzerGPIO 25PWM(Digital Output) / Analog Output
RGB_LEDGPIO 4Digital Output
MPU9250_SCLGPIO 22Digital Output
MPU9250_SDAGPIO 21Digital Output
MPU9250_INTGPIO 16Digital Input
R_LED(SPI_SCK)GPIO 18Digital Output

예제 소스

int adTestFreq = 0;
int BuzzerTestFreq = 0;
int brightness = 0;
int fadeAmount = 5;

//buzzer config
#define Buzzer 25
#define LEDC_CHANNEL_0 0
#define LEDC_TIMER_13_BIT 13
#define LEDC_BASE_FREQ 450
#define bout 3

/*****************************************************************
 * Function      :ledcAnalogWrite                            *
 * Input Parameter :channel / value                           *
 * Output Parameter:None                                      *
 * Features     :Match value to channel and convert to duty   *
 ****************************************************************/
void ledcAnalogWrite(uint8_t channel, uint32_t value)
{
  // calculate duty, 8191 from 2 ^ 13 - 1 (2 ^ LEDC_TIMER_13_BIT - 1)
  //value_MAX = 255
  uint32_t duty = (8191 / 255) * value;
  // write duty to LEDC
  ledcWrite(channel, duty);
}

void setup() {
  Serial.begin(115200); //Serial Port Config 115200-8-N-1
  ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_13_BIT);
  ledcAttachPin(Buzzer, LEDC_CHANNEL_0);
}

void loop() {
  /*****************************
   ***Function:Buzzer Test   ***
   ****************************/
  Serial.println();
  Serial.println("Buzzer Test!!!");
  Serial.println("Buzzer is fading");
  for (BuzzerTestFreq = 0; BuzzerTestFreq < bout; BuzzerTestFreq++)
  {
      for (brightness = 0; brightness < 255; brightness++)
      {
          Serial.print(".");
          // set the brightness on LEDC channel 0
          ledcAnalogWrite(LEDC_CHANNEL_0, brightness);
          // change the brightness for next time through the loop:
          brightness = brightness + fadeAmount;
          // reverse the direction of the fading at the ends of the fade:
          if (brightness <= 0 || brightness >= 255)
          {
              fadeAmount = -fadeAmount;
          }
          // wait for 30 milliseconds to see the dimming effect
          delay(30);
      }
      Serial.println();
      ledcAnalogWrite(LEDC_CHANNEL_0, 0);
  }
  delay(1000);
}

실행 결과

BPI-Bit : AB 버튼 입력 받기

OS/Banana Pi /BPI-Bit 2019.02.05 23:52 Posted by 파란크리스마스

출처

BPI-Bit : AB 버튼 입력 받기

BPI-Bit에는 두개의 버튼이 있습니다. 특이한 점은 버튼이 눌러진 경우 0, 그렇지 않은 경우 1을 반환 하고 있습니다.(저는 반대의 경우라고 생각했지만...)

GPIO control of BPI:bit

GPIO control of BPI:bit
Light Sensor(L)GPIO 36Analog Input
Light Sensor(R)GPIO 39Analog Input
Botton AGPIO 35Digital Input
Botton BGPIO 27Digital Input
Temperature SensorGPIO 34Analog Input
BuzzerGPIO 25PWM(Digital Output) / Analog Output
RGB_LEDGPIO 4Digital Output
MPU9250_SCLGPIO 22Digital Output
MPU9250_SDAGPIO 21Digital Output
MPU9250_INTGPIO 16Digital Input
R_LED(SPI_SCK)GPIO 18Digital Output

예제 소스

//buttom config
#define BottonA 35
#define BottonB 27

void setup() {
  Serial.begin(115200); //Serial Port Config 115200-8-N-1
  pinMode(BottonA, INPUT);//Botton B Pin Mode :Digital Input
  pinMode(BottonB, INPUT);//Botton B Pin Mode :Digital Input
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.printf("BottonA = %d / BottonB = %d \n", digitalRead(BottonA), digitalRead(BottonB));  
  delay(500);
}

실행 결과

BPI-Bit : 전면 LED 사용하기

OS/Banana Pi /BPI-Bit 2019.02.05 22:45 Posted by 파란크리스마스

출처

BPI-Bit : 전면 LED 사용하기

BPI-Bit 전면 LED는 RGB 제어가 가능한 LED로 여러가지 색표현이 가능 모듈로 비슷한 보드인 micro:bit가 단색으로 표현 되는 것보다 개선 되었다고 볼 수 있습니다.

BPI-Bit : 전면 LED 배열

NeoPixel_Bus 라이브러리 추가 (https://github.com/Makuna/NeoPixelBus)

메누 [툴] - [라이브러리 관리] 선택

검색창에 [NeoPixel_Bus]로 검색하고, [설치] 버튼을 선택해서, 라이브러리 설치

예제 실행

메뉴 [파일] - [예제] - [NeoPixelBus by Makuna] - [NeoPixelTest] 선택

BPI-Bit 전면 LED에 맞게 예제 수정

수정전

const uint16_t PixelCount = 4; // this example assumes 4 pixels, making it smaller will cause a failure
const uint8_t PixelPin = 2;  // make sure to set this to the correct pin, ignored for Esp8266

수정후

const uint16_t PixelCount = 25; // this example assumes 4 pixels, making it smaller will cause a failure
const uint8_t PixelPin = 4;  // make sure to set this to the correct pin, ignored for Esp8266

setup 함수에 내용 추가

void setup()
{
    #define LED_POWER      2
    pinMode(LED_POWER, OUTPUT);
    digitalWrite(LED_POWER, HIGH);
  
    Serial.begin(115200);
    while (!Serial); // wait for serial attach

실행 결과

실제로 보면 색상의 변환가 잘 보이지만, 너무 밝아서 사진에는 잘 보이지 않습니다.

예제2

#include <NeoPixelBus.h>

// WS2812 config
const uint16_t PixelCount = 25;
const uint8_t PixelPin = 4;
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);

#define colorSaturation 32

// LED 조명을 정의
#define ledPower 2

// 빨강과 검정색을 정의
RgbColor red(colorSaturation, 0, 0);
RgbColor black(0);

void setup() {
  pinMode(ledPower, OUTPUT);
  digitalWrite(ledPower, HIGH);
  
  // 라이브러리 초기화
  strip.Begin();
  // 发送数据,默认每个点的颜色为0,所以初始的每个点都是不亮的
  strip.Show();
}

void loop() {
  strip.SetPixelColor(0, red);
  strip.Show();
  delay(100);
  strip.SetPixelColor(0, black);
  strip.Show();
  delay(100);
}

예제2 실행

BPI-Bit : Arduino 기본 과정(개발툴 설치)

OS/Banana Pi /BPI-Bit 2019.02.05 22:31 Posted by 파란크리스마스

출처

Arduino 개발도구 설치

arduino ide 다운로드 : https://www.arduino.cc/en/Main/Software

설치 버전이 아닌 포터블(zip파일) 설치 권장

BPI-BIT 보드 추가

BPI-BIT는 esp32 칩을 사용하므로 arduino esp32의 설치 프로그램을 github(https://github.com/espressif/arduino-esp32)에서 다운로드 후 get 프로그램(BPI-BIT 보드 설치 프로그램) 실행

arduino esp32의 설치 프로그램을 github에서 다운로드

D:\Data.BPI-Bit\arduino-1.8.8\hardware>mkdir espressif

D:\Data.BPI-Bit\arduino-1.8.8\hardware>cd espressif

D:\Data.BPI-Bit\arduino-1.8.8\hardware\espressif>git clone https://github.com/espressif/arduino-esp32.git esp32
Cloning into 'esp32'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 11572 (delta 0), reused 4 (delta 0), pack-reused 11567
Receiving objects: 100% (11572/11572), 166.10 MiB | 1.30 MiB/s, done.
Resolving deltas: 100% (6844/6844), done.
Checking out files: 100% (1917/1917), done.

get 프로그램(BPI-BIT 보드 설치 프로그램) 실행

D:\Data.BPI-Bit\arduino-1.8.8\hardware\espressif>cd esp32\tools

D:\Data.BPI-Bit\arduino-1.8.8\hardware\espressif\esp32\tools>get
System: Windows, Info: Windows-10-10.0.17763
Platform: i686-mingw32
Downloading xtensa-esp32-elf-win32-1.22.0-80-g6c4433a-5.2.0.zip
Done
Extracting xtensa-esp32-elf-win32-1.22.0-80-g6c4433a-5.2.0.zip
Downloading esptool-2.6.0-windows.zip
Done
Extracting esptool-2.6.0-windows.zip
Downloading mkspiffs-0.2.3-arduino-esp32-win32.zip
Done
Extracting mkspiffs-0.2.3-arduino-esp32-win32.zip
Renaming mkspiffs-0.2.3-arduino-esp32-win32/ to mkspiffs
Done

BPI-BIT 보드 추가 확인

BPI-Bit : Arduino 개발환경 구축하기

OS/Banana Pi /BPI-Bit 2018.09.21 21:12 Posted by 파란크리스마스

출처

BPI-Bit : Arduino 개발환경 구축하기

BPI-Bit는 몇가지 개발 언어가 있는데 Webduino 말고도 Arduino IDE로 개발할 수 있어서, Arduino IDE 개발환경을 구축하고 간단예제를 실행해보았습니다.

1. Arduino IDE 설치

Arduino IDE (arduino-1.8.7-windows.zip)를 다운로드받고, 설치

2. arduino-esp32 다운로드

Github 저장소(espressif / arduino-esp32)에서 arduino-esp32-master.zip 파일 다운로드

3. arduino-esp32 설치

다운로드 받은 파일 arduino-esp32-master.zip을 [Arduino IDE 설치경로]/hardware/espressif/esp32에 압축 해제

4. get 명령을 관리자 권한으로 실행

[Arduino IDE 설치경로]/hardware/espressif/esp32/tools 디렉토리에서 get 명령을 관리자 권한으로 실행 실행

5. Arduino IDE를 실행하고, 메뉴[툴] > [보드] > [NodeMCU -32S] 선택

예제 작성

//BIT NEW
//BPI - BIT test code
#include <Arduino.h>
#include <NeoPixelBus.h>

#define LEDC_CHANNEL_0 0
#define LEDC_TIMER_13_BIT 13
#define LEDC_BASE_FREQ 4500

const uint16_t PixelCount = 25;
const uint8_t PixelPin = 4;

#define colorSaturation 128
#define delay_ms 500

NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);

RgbColor red(colorSaturation, 0, 0);
RgbColor green(0, colorSaturation, 0);
RgbColor blue(0, 0, colorSaturation);
RgbColor white(colorSaturation);
RgbColor black(0);
RgbColor num1(0.8 * colorSaturation, 0, 0.2 * colorSaturation);
RgbColor num2(0.5 * colorSaturation, 0, 0.5 * colorSaturation);
RgbColor num3(0.25 * colorSaturation, 0, 0.75 * colorSaturation);

HslColor hslRed(red);
HslColor hslGreen(green);
HslColor hslBlue(blue);
HslColor hslWhite(white);
HslColor hslBlack(black);

#define ledPower 2
#define BottomA 35
#define BottomB 27

int brightness = 0;
int fadeAmount = 5;

void ledcAnalogWrite(uint8_t channel, uint32_t value) {
  // calculate duty, 8191 from 2 ^ 13 - 1 (2 ^ LEDC_TIMER_13_BIT - 1)
  //value_MAX = 255
  uint32_t duty = (8191 / 255) * value;
  // write duty to LEDC
  ledcWrite(channel, duty);
}

void setup() {
  Serial.begin(115200); //Serial Port Config 115200-8-N-1
  
  Serial.println();
  Serial.println("Initializing...");
  Serial.flush();
  
  // this resets all the neopixels to an off state
  strip.Begin();
  strip.Show();
  
  pinMode(ledPower,OUTPUT);
  pinMode(BottomA, INPUT);
  pinMode(BottomB, INPUT);
  digitalWrite(ledPower, HIGH);
  
  // strip.SetPixelColor(10, blue);
  // strip.SetPixelColor(11, blue);
  // strip.SetPixelColor(12, blue);
  // strip.SetPixelColor(13, blue);
  // strip.SetPixelColor(14, red);
  // strip.Show();
  
  // delay(1000);
  
  // int i;
  // for (i = 0; i <= PixelCount - 1; i++)
  // {
  //     strip.SetPixelColor(i, black);
  //     strip.Show();
  // }
}

void loop() {
  //signel map
  if (digitalRead(BottomA) == LOW) {
    delay(10);
    if (digitalRead(BottomA) == LOW) {
      strip.SetPixelColor(16, num1);
      strip.SetPixelColor( 7, num2);
      strip.SetPixelColor(18, num3);
      strip.Show();
    } else {
      int i;
      Serial.println("Turn Off");
      for (i = 0; i <= PixelCount - 1; i++) {
        strip.SetPixelColor(i, hslBlack);
        strip.Show();
      }
    }
  }
}

예제 실행

BPI-Bit 소개

OS/Banana Pi /BPI-Bit 2018.07.22 22:12 Posted by 파란크리스마스

출처

BPI-Bit

바나나파이를 만드는 회사에서 BPI-Bit를 출시 했는데, micro:bit 비슷한 개발 보드로,
micro:bit와 비슷한 부분이 많지만, 일부분은 micro:bit보다 개선된 기능이 보입니다.

개선된 기능으로 라디오기능은 빠져 있지만, Wifi가 추가 되어있고, 전면 LED도 RGB LED로 Full Color를 표현할 수 있습니다.

버튼의 간격이 조금 넒어서 micro:bit와 동일한 케이스를 사용할 수 없지만,
GPIO의 핀 배열은 micro:bit 동일하게 배열되어 있어, micro:bit의 확장보드는 동일하게 사용할 수 있을것 같습니다.

개발 언어로 바나나파이에서 만든 WebDuino를 지원하고 있어, AP 모드로 Wifi를 접속해서 공유기를 설정할 수 있고,
JavaScript로 개발된 언어를 내장된 웹서버에 복사해서 웹호출로 실행 해볼 수 있습니다.

Arduino IDE를 지원하고 있어서, Arduino와 동일한 소스를 사용 할 수 있습니다.

 

Interface

이미지 출처 : BPI-Bit - Banana Pi Wiki

Edge interface

BPI-M2+(H2) 운영체제(OS) 설치

OS/Banana Pi /BPI-Bit 2018.07.21 10:24 Posted by 파란크리스마스

출처

OS 이미지 다운로드

2018-05-04-ubuntu-16.04-mate-desktop-v1.1-bpi-m2p-sd-emmc.img.zip

OS 이미지 SD 메모리에 복사

SD 메모리 복사 프로그램인 Etcher를 이용해서 OS 이미지를 복사합니다.

버튼[Select image] 선택하고, 파일 선택 창에서 다운 받은 OS 이미지 선택

OS 이미지를 복사할 SD 메모리 선택하기 위해서 버튼[Select drive] 선택

버튼[Flash!] 선택해서 복사 시작

SD 확장

SD 확장전 용량확인

$ df -l
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root        6993924 4796496   1842152  73% /
devtmpfs          408148       0    408148   0% /dev
tmpfs             510744     380    510364   1% /dev/shm
tmpfs             510744    7500    503244   2% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs             510744       0    510744   0% /sys/fs/cgroup
tmpfs             102152      32    102120   1% /run/user/1000
/dev/mmcblk0p1    261868    6648    255220   3% /media/pi/BPI-BOOT

SD FDisk

pi@bpi-iot-ros-ai:~$ sudo fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x8ef6c070

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1      204800   729087   524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      729088 14940159 14211072  6.8G 83 Linux

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2048-31116287, default 2048): 729088    
Last sector, +sectors or +size{K,M,G,T,P} (729088-31116287, default 31116287): 

Created a new partition 2 of type 'Linux' and of size 14.5 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

pi@bpi-iot-ros-ai:~$ sudo shutdown -r now

SD 확장

$ sudo resize2fs /dev/mmcblk0p2
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 3798400 (4k) blocks long.

SD 확장 확인

$ df -l
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root       14958272 4577560   9706060  33% /
devtmpfs          408148       0    408148   0% /dev
tmpfs             510744     196    510548   1% /dev/shm
tmpfs             510744    7504    503240   2% /run
tmpfs               5120       4      5116   1% /run/lock
tmpfs             510744       0    510744   0% /sys/fs/cgroup
tmpfs             102152      28    102124   1% /run/user/1000
/dev/mmcblk0p1    261868    6648    255220   3% /media/pi/BPI-BOOT

How to burn Linux image to eMMC

출처 : How to burn Linux image to eMMC
bpi-copy command

이미지 복원

이미지 복원이 완료되면 SD 메모리를 제거하고 재부팅

$ sudo dd if=2018-05-04-ubuntu-16.04-mate-desktop-v1.1-bpi-m2p-sd-emmc.img of=/dev/mmcblk1 bs=10MB
765+1 records in
765+1 records out
7650410496 bytes (7.7 GB, 7.1 GiB) copied, 1054.11 s, 7.3 MB/s

eMMC 용량 확인

pi@bpi-iot-ros-ai:~$ uname -a
Linux bpi-iot-ros-ai 3.4.39-BPI-M2P-Kernel #1 SMP PREEMPT Wed May 2 11:02:30 CST 2018 armv7l armv7l armv7l GNU/Linux
pi@bpi-iot-ros-ai:~$ sudo fdisk -l
Disk /dev/mmcblk0: 7.3 GiB, 7818182656 bytes, 15269888 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x8ef6c070

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1      204800   729087   524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      729088 14940159 14211072  6.8G 83 Linux


Disk /dev/mmcblk0boot1: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mmcblk0boot0: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

BPI-M2 Berry - I2C 이용 PCA9685 제어

OS/Banana Pi /BPI-Bit 2018.01.01 13:31 Posted by 파란크리스마스

출처 : Maker Projects: Banana Pi I2C Devices
BPI-M2,use wiringPi I2C to read mpu6050 - Banana Pi BPI-M2 / Linux - banana pi single board computer official forum SinoVoip BPI team
node.js - johntreacy/adafruit-pca9685
adafruit/Adafruit_Python_PCA9685: Python code to use the PCA9685 PWM servo/LED controller with a Raspberry Pi or BeagleBone black.

BPI-M2 Berry GPIO Pin define

출처 : BPI-M2 Ultra GPIO Pin define · banana pi BPI-M2 Ultra/Berry allwinner R40/V40 SBC

GPIO Pin Name Default Function Function2:GPIO Function3
CON1-P01 VCC-3V3
CON1-P02 DCIN
CON1-P03 TWI2-SDA PB21 PWM5
CON1-P04 DCIN
CON1-P05 TWI2-SCK PB20 PWM4
CON1-P06 GND
CON1-P07 PB3 PB3 PWM1
CON1-P08 UART2-TX PI18 SPI1_MOSI
CON1-P09 GND
CON1-P10 UART2-RX PI19 SPI1_MISO
CON1-P11 UART7-TX PI20 PWM2
CON1-P12 UART2-CTS PI17 SPI1_CLK
CON1-P13 UART7-RX PI21 PWM3
CON1-P14 GND
CON1-P15 PH25 PH25 CSI1-FIELD
CON1-P16 UART2-RTS PI16 SPI1_CS0
CON1-P17 VCC-3V3
CON1-P18 PH26 PH26 CSI1-HSYNC
CON1-P19 SPI0_MOSI PC0
CON1-P20 GND
CON1-P21 SPI0_MISO PC1
CON1-P22 PH27 PH27 CSI1-VSYNC
CON1-P23 SPI0_CLK PC2
CON1-P24 SPI0_CS PC23
CON1-P25 GND
CON1-P26 PH24 PH24 CSI1-PCLK
CON1-P27 TWI3-SDA PI1
CON1-P28 TWI3-SCK PI0
CON1-P29 PH0 PH0 CSI1-D0
CON1-P30 GND
CON1-P31 PH1 PH1 CSI1-D1
CON1-P32 PD20 PD20 CSI1-MCLK
CON1-P33 PH2 PH2 CSI1-D2
CON1-P34 GND
CON1-P35 PH3 PH3 CSI1-D3
CON1-P36 UART5-RX PH7 CSI1-D7
CON1-P37 UART4-TX PH4 CSI1-D4
CON1-P38 UART5-TX PH6 CSI1-D6
CON1-P39 GND
CON1-P40 UART4-RX PH5 CSI1-D5

I2C 목록 조회 - i2cdetect -l

$ i2cdetect -l
i2c-0   i2c             twi0                                    I2C adapter
i2c-1   i2c             twi1                                    I2C adapter
i2c-2   i2c             twi2                                    I2C adapter
i2c-4   i2c             twi4                                    I2C adapter

I2C 주소 확인 - i2cdetect -y

$ i2cdetect -y 2
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

gpio readall

 +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |  53 |   8 |   SDA.1 | ALT5 | 0 |  3 || 4  |   |      | 5v      |     |     |
func:sunxi_get_pin_mode pin:53,  bank:1 index:21 phyaddr:0x1c2082c
read reg val: 0x22222233 offset:20  return: 0
read reg val: 0x22222233 offset:20  return: 2
func:sunxi_digitalRead pin:53,bank:1 index:21 phyaddr:0x1c20834
***** read reg val: 0x0,bank:1,index:21,line:850
 |  52 |   9 |   SCL.1 | ALT5 | 0 |  5 || 6  |   |      | 0v      |     |     |
func:sunxi_get_pin_mode pin:52,  bank:1 index:20 phyaddr:0x1c2082c
read reg val: 0x22222233 offset:16  return: 0
read reg val: 0x22222233 offset:16  return: 2
func:sunxi_digitalRead pin:52,bank:1 index:20 phyaddr:0x1c20834
***** read reg val: 0x0,bank:1,index:20,line:850
| 257 |  30 |   SDA.0  | ALT3 | 0 | 27
func:sunxi_get_pin_mode pin:257,  bank:8 index:1 phyaddr:0x1c20920
read reg val: 0x77703377 offset:4  return: 0
read reg val: 0x77703377 offset:4  return: 7
func:sunxi_digitalRead pin:257,bank:8 index:1 phyaddr:0x1c20930
***** read reg val: 0x0,bank:8,index:1,line:850
                                       || 28 | 0 | ALT3 | SCL.0   | 31  | 256 |
func:sunxi_digitalRead pin:256,bank:8 index:0 phyaddr:0x1c20930
***** read reg val: 0x0,bank:8,index:0,line:850
func:sunxi_get_pin_mode pin:256,  bank:8 index:0 phyaddr:0x1c20920
read reg val: 0x77703377 offset:0  return: 0
read reg val: 0x77703377 offset:0  return: 7

BPI-M2 Berry - I2C 이용 PCA9685 제어 소스 - PCA9685Gpio.java

import java.io.IOException;
/**
 * $ sudo java -cp .:pi4j/* PCA9685Gpio
 */
import java.math.BigDecimal;

import com.pi4j.gpio.extension.pca.PCA9685GpioProvider;
import com.pi4j.gpio.extension.pca.PCA9685Pin;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinPwmOutput;
import com.pi4j.io.gpio.BPIM2BerryGpioProvider;
import com.pi4j.io.gpio.Pin;
import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CFactory;
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException;

public class PCA9685Gpio {
	
	public static final int SERVO_DURATION_MIN = 600;
	public static final int SERVO_DURATION_NEUTRAL = 1500;
	public static final int SERVO_DURATION_MAX = 2400;
	
	private static PCA9685Gpio instance = null;
	
	private PCA9685GpioProvider gpioProvider = null;
	
	// sudo java -cp .:pi4j-core.jar:pi4j-gpio-extension.jar PCA9685Gpio
	
	private PCA9685Gpio() throws IOException, UnsupportedBusNumberException {		
		
		//GpioFactory.setDefaultProvider(new BPIM2PGpioProvider());
		//GpioFactory.setDefaultProvider(new NanoPiNEOAirGpioProvider());
		GpioFactory.setDefaultProvider(new BPIM2BerryGpioProvider());
		
		System.out.println("<--Pi4J--> PCA9685 PWM Example ... started.");
		// This would theoretically lead into a resolution of 5 microseconds per
		// step:
		// 4096 Steps (12 Bit)
		// T = 4096 * 0.000005s = 0.02048s
		// f = 1 / T = 48.828125
		BigDecimal frequency = new BigDecimal("48.828");
		// Correction factor: actualFreq / targetFreq
		// e.g. measured actual frequency is: 51.69 Hz
		// Calculate correction factor: 51.65 / 48.828 = 1.0578
		// --> To measure actual frequency set frequency without correction
		// factor(or set to 1)
		BigDecimal frequencyCorrectionFactor = new BigDecimal("1.0578");
		// Create custom PCA9685 GPIO provider
		I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_2);
		gpioProvider = new PCA9685GpioProvider(bus, 0x40, frequency, frequencyCorrectionFactor);
		// Define outputs in use for this example
		GpioPinPwmOutput[] myOutputs = provisionPwmOutputs(gpioProvider);
		// Reset outputs
		gpioProvider.reset();
	}
	
	public static PCA9685Gpio getInstance() throws IOException, UnsupportedBusNumberException {
		if (instance==null) instance = new PCA9685Gpio();
		return instance;
	}
	
	public void setPwm(Pin pin, int duration) {
		gpioProvider.setPwm(pin, duration);
	}
	
	public void shutdown() {
		gpioProvider.shutdown();
	}
	
	private static GpioPinPwmOutput[] provisionPwmOutputs(final PCA9685GpioProvider gpioProvider) {
		GpioController gpio = GpioFactory.getInstance();
		GpioPinPwmOutput myOutputs[] = { 
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_00, "Pulse 00"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_01, "Pulse 01"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_02, "Pulse 02"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_03, "Pulse 03"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_04, "Pulse 04"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_05, "Pulse 05"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_06, "Pulse 06"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_07, "Pulse 07"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_08, "Pulse 08"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_09, "Pulse 09"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_10, "Always ON"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_11, "Always OFF"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_12, "Servo pulse MIN"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_13, "Servo pulse NEUTRAL"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_14, "Servo pulse MAX"),
				gpio.provisionPwmOutputPin(gpioProvider, PCA9685Pin.PWM_15, "not used") };
		return myOutputs;
	}

	public static void main(String[] args) throws Exception {
		
		PCA9685Gpio test = PCA9685Gpio.getInstance();
		
		test.setPwm(PCA9685Pin.PWM_01, SERVO_DURATION_NEUTRAL);
		Thread.sleep(200);
		
		for (int i=SERVO_DURATION_MIN; i<=SERVO_DURATION_MAX; i+=30) {
			test.setPwm(PCA9685Pin.PWM_00, i);
			Thread.sleep(200);
		}
		
		for (int i=SERVO_DURATION_MAX; i>=(int)(SERVO_DURATION_MIN+(SERVO_DURATION_MAX-SERVO_DURATION_MIN)/2); i-=30) {
			test.setPwm(PCA9685Pin.PWM_00, i);
			Thread.sleep(200);
		}
				
		for (int i=SERVO_DURATION_MIN; i<=SERVO_DURATION_MAX; i+=30) {
			test.setPwm(PCA9685Pin.PWM_01, i);
			Thread.sleep(200);
		}
		
		for (int i=SERVO_DURATION_MAX-200; i>=(int)(SERVO_DURATION_MIN+(SERVO_DURATION_MAX-SERVO_DURATION_MIN)/2); i-=30) {
			test.setPwm(PCA9685Pin.PWM_01, i);
			Thread.sleep(200);
		}
		
		test.shutdown();

	}
	
}

컴파일

$ javac -cp .:pi4j/* -d . PCA9685Gpio.java

실행

$ sudo java -cp .:pi4j/* PCA9685Gpio

실행 영상


BPI-M2 ZERO - WiringOP 연동 node.js

OS/Banana Pi /BPI-Bit 2017.12.27 01:23 Posted by 파란크리스마스

출처 : github - bluexmas/node-wiring-bpi-zero

BPI-M2 ZERO에서 node.js용 gpio제어 가능한 패키지가 없어서 직접 제작해보았습니다.

node-wiring-bpi-zero 설치

$ cd ~
$ git clone https://github.com/bluexmas/node-wiring-bpi-zero.git
$ npm install node-wiring-bpi-zero

gpio 확인

$ gpio readall
 +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |  12 |   8 |   SDA.1 | ALT5 | 0 |  3 || 4  |   |      | 5v      |     |     |
 |  11 |   9 |   SCL.1 | ALT5 | 0 |  5 || 6  |   |      | 0v      |     |     |
 |   6 |   7 | GPIO. 7 | ALT3 | 0 |  7 || 8  | 0 | ALT4 | TxD     | 15  | 13  |
 |     |     |      0v |      |   |  9 || 10 | 0 | ALT4 | RxD     | 16  | 14  |
 |   1 |   0 | GPIO. 0 | ALT5 | 0 | 11 || 12 | 0 | ALT4 | GPIO. 1 | 1   | 16  |
 |   0 |   2 | GPIO. 2 | ALT5 | 0 | 13 || 14 |   |      | 0v      |     |     |
 |   3 |   3 | GPIO. 3 | ALT5 | 0 | 15 || 16 | 0 | ALT4 | GPIO. 4 | 4   | 15  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | ALT3 | GPIO. 5 | 5   | 68  |
 |  64 |  12 |    MOSI | ALT4 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |  65 |  13 |    MISO | ALT4 | 0 | 21 || 22 | 0 | ALT5 | GPIO. 6 | 6   | 2   |
 |  66 |  14 |    SCLK | ALT4 | 0 | 23 || 24 | 0 | ALT4 | CE0     | 10  | 67  |
 |     |     |      0v |      |   | 25 || 26 | 0 | ALT3 | CE1     | 11  | 71  |
 |  19 |  30 |   SDA.0 | ALT4 | 0 | 27 || 28 | 0 | ALT4 | SCL.0   | 31  | 18  |
 |   7 |  21 | GPIO.21 | ALT3 | 0 | 29 || 30 |   |      | 0v      |     |     |
 |   8 |  22 | GPIO.22 | ALT3 | 0 | 31 || 32 | 0 | ALT3 | GPIO.26 | 26  | 354 |
 |   9 |  23 | GPIO.23 | ALT3 | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  10 |  24 | GPIO.24 | ALT3 | 0 | 35 || 36 | 0 | ALT3 | GPIO.27 | 27  | 356 |
 |  17 |  25 | GPIO.25 | ALT3 | 0 | 37 || 38 | 0 | ALT3 | GPIO.28 | 28  | 21  |
 |     |     |      0v |      |   | 39 || 40 | 0 | ALT3 | GPIO.29 | 29  | 20  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+

blink 소스

var wpi = require('wiring-bpi-zero');

wpi.setup();

var pin = 25;

wpi.pinMode(pin, wpi.OUTPUT);

var value = 1;

setInterval(function() {
  wpi.digitalWrite(pin, value);
  value = +!value;
}, 500);

데모 실행

$ sudo node node-wiring-bpi-zero/examples/blink.js