2018年10月10日

bpi-bit arduino 數位類比pwm

使用bpi-bit 在arduino ide上使用數位角位輸出-P2

參考網址:https://www.cnblogs.com/lulipro/p/8046248.html
void setup() {
  // put your setup code here, to run once:
  pinMode(P2, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(P2, HIGH);
  delay(500);
  digitalWrite(P2, LOW);
  delay(500);
}

要使用pwm來做呼吸燈


int freq = 5000;
int ledChannel = 0;
int resolution = 8;

void setup() {
   ledcSetup(ledChannel, freq, resolution);
  ledcAttachPin(P1, ledChannel);
 }
void loop()
{
  for (int dutyCycle = 0; dutyCycle <= 255; dutyCycle++) {
    ledcWrite(ledChannel, dutyCycle);
    delay(7);
  }

  for (int dutyCycle = 255; dutyCycle >= 0; dutyCycle--) {
    ledcWrite(ledChannel, dutyCycle);
    delay(7);
  }

}

 

P1類比輸入 

把類比感應器接在P1,使用serial monitor秀出。

void setup() {
  // put your setup code here, to run once:
    Serial.begin(115200); //Serial Port Config 115200-8-N-1
    pinMode(P1, INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
      Serial.println();
      Serial.println(analogRead(P1));
      delay(500);;

}

P1數位輸入

把數位感應器接在P1(按鈕),使用serial monitor秀出
void setup() {
  // put your setup code here, to run once:
    Serial.begin(115200); //Serial Port Config 115200-8-N-1
    pinMode(P1, INPUT);//Botton B Pin Mode :Digital Input
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(P1) == LOW)
    {
      delay(100);
   if (digitalRead(P1) == LOW)
    {
      Serial.println();
      Serial.println(LOW);
    }else{
      Serial.println();
      Serial.println(HIGH);
    }
   }
 
}

2018年10月8日

bpi-bit LED 數位亮燈

arduino ide 實作led亮燈

開一個arduino新檔,板子選擇bpi-bit(板子設定方法請參考https://wdpsestea.blogspot.com/2018/10/bpi-bit-arduino-ide.html ,ubuntu使用者參考https://wdpsestea.blogspot.com/2018/09/bpi-bit-arduino-ide.html ) 選擇連擁port(win下是comX,linux下是ttyUSBX),燒錄速度建議降低些。




void setup() {
  // put your setup code here, to run once:

}
前include下列檔案
我們有25個LED和使用PixelPin 4來溝通。

#include <Arduino.h>
#include <NeoPixelBus.h>
#include "WiFi.h"
//WS2812 config
const uint16_t PixelCount = 25;
const uint8_t PixelPin = 4;
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);


#define colorSaturation 32
//定義WS2812 腳位 2
#define ledPower 2
//定義顏色
RgbColor red(colorSaturation, 0, 0);
RgbColor green(0, colorSaturation, 0);
RgbColor blue(0, 0, colorSaturation);
RgbColor white(colorSaturation);
RgbColor black(0);
HslColor hslRed(red);
HslColor hslGreen(green);
HslColor hslBlue(blue);
HslColor hslWhite(white);
HslColor hslBlack(black);


void setup() {
  // put your setup code here, to run once:

}
中加入
  Serial.begin(115200); //Serial Port Config 115200-8-N-1
  while (!Serial); // wait for serial attach

  Serial.println();
  Serial.println("Initializing...");
  Serial.flush();

  // this resets all the neopixels to an off state
  strip.Begin();
  strip.Show();

  pinMode(ledPower,OUTPUT);
  digitalWrite(ledPower, HIGH); //It's very important for the v1.2, if you use the v1.4 ,you can delete it


在void loop() {
  // put your main code here, to run repeatedly:
           
}
中插入下列
            strip.SetPixelColor(0, red);
            strip.Show();
            delay(100);
            strip.SetPixelColor(0, black);
            strip.Show();
            delay(100);
亮燈,strip.SetPixelColor(0, red);0是第幾個燈按照下圖排列,顏色則按RgbColor定義的內容

 要熄滅則用黑色
strip.SetPixelColor(0, black);
間隔時間使用delay(微秒),1秒=1000微秒。
 delay(1000);


2018年10月4日

bpi-bit 使用arduino ide編輯

arduino ide 不認識bpi-bit這板子,arduino ide要如何設定?
參考文章:https://github.com/BPI-STEAM/BPI-BIT-Arduino-IDE/wiki/windows

1.下載arduino ide  個人使用zip檔案:https://www.arduino.cc/en/Main/Software
 選擇適合自己做業系統的zip,下載後解壓縮。

2.bpi-bit是使用esp32晶片,所以要找到arduino esp32的硬體程式,在https://github.com/espressif/arduino-esp32
下載後解壓縮。改目錄名稱為esp32,放到arduino 1.8.7的hardware目錄下建一個espressif目錄下

感謝Yufong提供,在偏好設定中加入https://dl.espressif.com/dl/package_esp32_index.json,就有bpi-bit的板子可以選。



執行esp32/tools/get.exe

執行arduino 1.8.7,這時就有bpi-bit的板子可以選擇了。

加入全彩LED陣列模組
參考文章:http://wiki.banana-pi.org/Lighting_the_RGB_LED
下載程式庫 Librarys:[NeoPixel_Bus] from Makuna:https://github.com/Makuna/NeoPixelBus
 下載完解壓縮,放到arduino ide的libraries目錄中


啟動arduino ide,點選[工具/管理程式庫],在搜尋框中輸入:neopixe,安裝neopixebus by makuna程式庫。

開啟範例:

 找到這兩行(約第16 17行)
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

 (約67行)找到setup()在{下一行加入
#define LED_POWER      2
 pinMode(LED_POWER, OUTPUT);
 digitalWrite(LED_POWER, HIGH);
 
確認你的bpi-bit在哪個com port,就可以燒錄了。燒錄完會看到LED燈亮起。
 
 
gpio 36 39光敏感應
gpio 25 蜂鳴器
gpio 35 按鈕A
gpio 27 按鈕B
gpio 22 I2C_SCL 
gpio 21 I2C_SDA
 https://kknews.cc/news/pprqq5z.html
 https://wiki.banana-pi.org/BPI-Bit_STEAM_%E6%95%99%E8%82%B2%E5%BC%80%E5%8F%91%E6%9D%BF
光敏传感器(L) GPIO 36 Analog Input
光敏传感器(R) GPIO 39 Analog Input
按键 A GPIO 35 Digital Input
按键 B GPIO 27 Digital Input
温度传感器 GPIO 34 Analog Input
蜂鸣器 GPIO 25 PWM(Digital Output) / Analog Output
RGB_LED GPIO 4 Digital Output
九轴传感器MPU9250_SCL GPIO 22 Digital Output
九轴传感器MPU9250_SDA GPIO 21 Digital Output
九轴传感器MPU9250_INT GPIO 16 Digital Input
R_LED(SPI_SCK) GPIO 18 Digital Output


bpi-bit使用webduino編輯器

當bpi-bit接上電腦後,25個全彩LED會顯示出bitxxxx(末4個是數字),使用電腦的wify連上這個AP,例如我的bpi-bit顯示9402這時會出現一個bit9402的AP。
選擇此AP,密碼是12345678。

連上去後在瀏覽器中輸入http://192.168.4.1 ,會看到下圖,此時要輸入可對外連線的SSID和密碼,按下SUBMIT鈕。
接下來會看到板子的ID,很重要,記得複製起來。
 接下來請連上下列網址:https://bit.webduino.io/blockly/?lang=zh-hant

進入編輯頁面,要注意的是在開發板的積木中,要選擇wifi和貼上剛才複製的設備ID(很長那串),再按play鈕,板子才會工作。

如果沒有板子可以選擇摸擬器,ID輸入1234,這時會在預覽視窗中出現程式的結果。



bpi-bit開箱文

拿到了bpi-bit(産品),打開盒子看到如下內容

 它的正面:

它的背面:
wiki上的圖片
簡介:
大小:5公分X5公分 ,重量:10至12公克,cpu:32位元Xtensa LX6雙核處理器,支援Webduino,Arduino,MicroPython以及Scratch X編程,內置20pin 針邊緣連接器,內置照明矩陣,25個可編程全彩LED,兩個光敏光傳感器,兩個可編程按鈕,一個NTC電阻,一個蜂鳴器和一個九軸傳感器(三軸加速三軸陀螺儀和三軸磁羅盤),I / O空間配置如下:
    全彩LED矩陣:GPIO4
    光敏傳感器:GPIO36(模擬A0,左上),GPIO39(模擬A3,右上)
    按鈕開關:GPIO35(Botton A),GPIO27(Botton B)
    溫度傳感器:GPIO34(模擬A6)
    蜂鳴器:GPIO25
    MPU-9250 9軸傳感器:GPIO0,GPIO21(SDA),GPIO22(SCL) 


它的wiki網址:http://wiki.banana-pi.org/BPI-Bit


2018年9月30日

bpi-bit韌體燒錄回weduino版本

如果bpi-bit的韌體版本跑掉了,想回出廠時的版本。依據文件做一次。
https://github.com/BPI-STEAM/BPI-BIT-WebDuino/wiki

參考網址:http://wiki.banana-pi.org/Webduino_firmware_programming

1.下載燒錄軟體
https://www.espressif.com/en/support/download/other-tools

點選esp32
2.解壓縮後,執行ESPFlashDownloadTool_v3.6.4.exe

 3.選擇4列,分别在第二欄填入四個位址x1000、0x8000、0xe000、0x10000,在第一欄選擇相對應檔案:

Filename Address
bootloader_dio_40m.bin 0x1000
partitions.bin 0x8000
boot_app0.bin 0xe000
bit_default.bin 0x10000

四個檔案下載位址:
https://github.com/BPI-STEAM/BPI-BIT-WebDuino
下載後解壓縮,在案在Bin資料夾中

燒錄後,如果出現X符號是沒按按鍵,要先按板子的A鍵不放再按後面的Reset鍵,然後再放掉Reset鍵,聽到蜂鳴器嗶嗶叫時,再放開A鍵。

快速還原方法:
在BPI-BIT-WebDuino-master資料夾中有AutoFlash資料夾,它可以快速還原韌體版本。
先執行AutoErase.exe,清除韌體,再執行AutoFlashWebduinoBin.exe,會自動寫入韌體,寫完後記得要按按鍵A後再按Rest,放掉Rest,聽到嗶嗶聲後放掉A鍵。

2018年9月28日

bpi-bit arduino ide設定

使用bpi bit讓arduino ide認識這塊板子做法:
作業系統ubuntu16.04 18.04
ubuntu使用apt-get  install的版本是2:1.0.5+dfsg2-4

按照
https://github.com/BPI-STEAM/BPI-BIT-Arduino-IDE/wiki#3-debian--ubuntu-os%E5%AE%89%E8%A3%85%E8%AF%B4%E6%98%8E

無法做出來。
我的解決方法(先sudo apt-get install arduino):
sudo usermod -a -G dialout $USER && \
sudo apt-get install git && \
wget https://bootstrap.pypa.io/get-pip.py && \
sudo python get-pip.py && \
sudo pip install pyserial 
 
下載新版的ardino ide
https://www.arduino.cc/en/Main/Software
 我用的是linux amd64 1.8.7版本
https://www.arduino.cc/download_handler.php?f=/arduino-1.8.7-linux64.tar.xz

下載完解壓縮

$tar Jxvf arduino-1.8.7-linux64.tar.xz
$sudo -s
#rm -rf /usr/share/arduino
#mv  arduino-1.8.7 /usr/share/arduino
#cd /usr/share/arduino-1.8.7/hardware/
#sudo mkdir  espressif
#cd espressif
#git clone https://github.com/espressif/arduino-esp32.git esp32
#cd esp32
#git submodule update --init --recursive
#cd tools
#python2 get.py
 
重新啟動arduino ide
在板子中才會有bpi-git可以選擇