2018年11月10日

bpi-bit buzzer music

參考網址:https://www.esp32.com/viewtopic.php?t=5140#p22226


 #define Buzzer 25   //GPIO 25
#define TIME 250       // 時間
#define LEDC_CHANNEL 0     
#define LEDC_TIMER_BIT 13
#define LEDC_BASE_FREQ 5000
int music_star[] = {1,1,5,5,6,6,5,0,4,4,3,3,2,2,1,0,5,5,4,4,3,3,2,0,5,5,4,4,3,3,2,0,1,1,5,5,6,6,5,0,4,4,3,3,2,2,1,0 };
int music_happy[] = {5,5,6,5,1,0,7,0,5,5,6,5,2,0,1,0,5,5,5,0,3,0,2,0,1,0,7,4,4,3,1,2,0,1 };

void setup(){
  ledcSetup(LEDC_CHANNEL, LEDC_BASE_FREQ, LEDC_TIMER_BIT);
  ledcAttachPin(Buzzer, LEDC_CHANNEL);
}
double to_num(int m_n){
// 0 NULL 0.0001
// 1 LG 419.333
// 2 A 472.333
// 7 B 531
// 1 C 590
// 2 D 629.333
// 3 E 708
// 4 F 786.6667
// 5 G 839.111
// 6 HA 944
double r_n = 0.00;
  switch ( m_n) {
    case 1:   
      r_n = 590;
      break;
    case 2:   
      r_n = 629.333;
      break;
    case 3:   
      r_n = 708;
      break;
    case 4:   
      r_n = 786.667;
      break;
    case 5:   
      r_n = 839.111;
      break;
    case 6:   
      r_n = 944;
      break;
    case 7:   
      r_n = 1044;
      break;
    default:
      r_n = 0;
      break;
  }
   return r_n ;
}

void loop(){
  for (int i=0;i<sizeof(music_happy);i++)
  {
    //double aa=to_num(music_star[i]);
    ledcWriteTone(LEDC_CHANNEL, to_num(music_happy[i]));
        delay(TIME);

    }
delay(1000);
}

2018年11月1日

micropython 連bpi-bit

apt-get install picocom
 pip3 install esptool

github
 https://github.com/BPI-STEAM/BPI-BIT-MicroPython


燒入micropython韌體
檔案下載
https://github.com/BPI-STEAM/BPI-BIT-MicroPython/releases/tag/beta 

python3  AutoErase.py
python3 AutoFlash.py

連上bpi-bit
picocom /dev/ttyUSB0 -b 115200

關掉wifi指令
wifi.close();

2018年10月27日

cura升級到3.5

記一下好了。
sudo add-apt-repository ppa:thopiekar/cura
sudo apt-get update
sudo apt install cura 
或是
sudo apt dist-upgrade
 
必要時
sudo apt -f install 

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);
    }
   }
 
}