2018年10月12日

bpi-bit led function

要讓led亮燈程式碼
#include <NeoPixelBus.h>
const uint16_t PixelCount = 25;
const uint8_t PixelPin = 4;
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);


#define colorSaturation 128
#define ledPower 2

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200); //Serial Port Config 115200-8-N-1
  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(20, RgbColor (0, 255, 0));
  strip.Show();
  delay(100);
  strip.SetPixelColor(20, RgbColor (0, 0, 0));
  strip.Show();
  delay(100);

}


把led燈滅用副程式來做:在void setup(){}前加入
 void led_black(){
  int i =0 ;
  for ( i =0;i <25;i++){
    strip.SetPixelColor(i, RgbColor (0, 0, 0));
    }
    strip.Show();
}
再把
  strip.SetPixelColor(20, RgbColor (0, 0, 0));
  strip.Show();
兩行改成呼叫副程式一行,以後只要一個副程式即可以把led燈熄滅。
   led_black();




qtqr crash


https://launchpad.net/ubuntu/cosmic/amd64/python-qt4/4.12.1+dfsg-2
下載    deb

wget http://launchpadlibrarian.net/344235582/python-qt4_4.12.1+dfsg-2_amd64.deb

安裝
sudo dpkg -i  python-qt4_4.12.1+dfsg-2_amd64.deb

如果出現相依性錯誤
  dpkg: 因相依問題,無法設定 python-qt4:
 python-qt4 相依於 libqt4-designer (>= 4:4.8.0-1~).
 python-qt4 相依於 libqt4-help (>= 4:4.8.0-1~)﹔然而:
  套件 libqt4-help 未安裝。
 python-qt4 相依於 libqt4-scripttools (>= 4:4.8.0-1~)﹔然而:
  套件 libqt4-scripttools 未安裝。
 python-qt4 相依於 libqt4-svg (>= 4:4.8.0-1~)﹔然而:
  套件 libqt4-svg 未安裝。
 python-qt4 相依於 libqt4-test (>= 4:4.8.0-1~)﹔然而:
  套件 libqt4-test 未安裝。
 python-qt4 相依於 libqtassistantclient4 (>= 4.6.3)﹔然而:
  套件 libqtassistantclient4 未安裝。

dpkg: error processing package python-qt4 (--install):
 相依問題 - 保留未設定
處理時發生錯誤:
 python-qt4


 sudo apt-get -f install
安裝好後再做一次
sudo dpkg -i  python-qt4_4.12.1+dfsg-2_amd64.deb

 wget http://free.nchc.org.tw/parrot/pool/main/q/qr-tools/qr-tools_1.4~bzr23.orig.tar.gz

tar zxvf qr-tools_1.4~bzr23.orig.tar.gz

cd qr-tools-1.4~bzr23

sudo chmod +x qtqr.py

sudo cp qtqr.py /usb/bin/qtqr

40 個 Laravel 開發便捷技巧

保太貼的,有時間要研讀一下
免費電子書: 40 個 Laravel 開發便捷技巧

https://laraveldaily.com/free-e-book-40-laravel-quick-tips-and-counting/

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